Created
September 30, 2013 19:22
-
-
Save peteromano/6768763 to your computer and use it in GitHub Desktop.
Adds target attribute binding as 'linkToNewTab' helper
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Extend Ember.LinkView to support target attribute binding | |
var NewTabLinkView = Ember.LinkView.extend({ | |
// Bind target attribute to view | |
//attributeBindings: Ember.LinkView.prototype.attributeBindings.concat('target'), | |
attributeBindings: ['href', 'title', 'target'], | |
// Set target attribute to '_blank' by default | |
target: '_blank', | |
// Since we are navigating to a new browser instance (bypassing router), we can | |
// just let browser do its default thing | |
_invoke: function() { | |
return true; | |
} | |
}); | |
/** | |
* Copy and modify linkTo helper behavior to use NewTabLinkView | |
* | |
* @TODO Do not use copied/repetitive code taken from Ember source | |
*/ | |
Ember.Handlebars.registerHelper('linkToNewTab', function(name) { | |
var options = [].slice.call(arguments, -1)[0]; | |
var params = [].slice.call(arguments, 1, -1); | |
var hash = options.hash; | |
hash.namedRoute = name; | |
hash.currentWhen = hash.currentWhen || name; | |
hash.disabledBinding = hash.disabledWhen; | |
hash.parameters = { | |
context: this, | |
options: options, | |
params: params | |
}; | |
return Ember.Handlebars.helpers.view.call(this, NewTabLinkView, options); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment