Skip to content

Instantly share code, notes, and snippets.

@peteromano
Created September 30, 2013 19:22
Show Gist options
  • Save peteromano/6768763 to your computer and use it in GitHub Desktop.
Save peteromano/6768763 to your computer and use it in GitHub Desktop.
Adds target attribute binding as 'linkToNewTab' helper
// 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