Chris@0: /** Chris@0: * @file Chris@0: * A Backbone View that provides a dynamic contextual link. Chris@0: */ Chris@0: Chris@17: (function($, Backbone, Drupal) { Chris@17: Drupal.quickedit.ContextualLinkView = Backbone.View.extend( Chris@17: /** @lends Drupal.quickedit.ContextualLinkView# */ { Chris@17: /** Chris@17: * Define all events to listen to. Chris@17: * Chris@17: * @return {object} Chris@17: * A map of events. Chris@17: */ Chris@17: events() { Chris@17: // Prevents delay and simulated mouse events. Chris@17: function touchEndToClick(event) { Chris@17: event.preventDefault(); Chris@17: event.target.click(); Chris@17: } Chris@0: Chris@17: return { Chris@17: 'click a': function(event) { Chris@17: event.preventDefault(); Chris@17: this.model.set('state', 'launching'); Chris@17: }, Chris@17: 'touchEnd a': touchEndToClick, Chris@17: }; Chris@17: }, Chris@0: Chris@17: /** Chris@17: * Create a new contextual link view. Chris@17: * Chris@17: * @constructs Chris@17: * Chris@17: * @augments Backbone.View Chris@17: * Chris@17: * @param {object} options Chris@17: * An object with the following keys: Chris@17: * @param {Drupal.quickedit.EntityModel} options.model Chris@17: * The associated entity's model. Chris@17: * @param {Drupal.quickedit.AppModel} options.appModel Chris@17: * The application state model. Chris@17: * @param {object} options.strings Chris@17: * The strings for the "Quick edit" link. Chris@17: */ Chris@17: initialize(options) { Chris@17: // Insert the text of the quick edit toggle. Chris@17: this.$el.find('a').text(options.strings.quickEdit); Chris@17: // Initial render. Chris@17: this.render(); Chris@17: // Re-render whenever this entity's isActive attribute changes. Chris@17: this.listenTo(this.model, 'change:isActive', this.render); Chris@17: }, Chris@17: Chris@17: /** Chris@17: * Render function for the contextual link view. Chris@17: * Chris@17: * @param {Drupal.quickedit.EntityModel} entityModel Chris@17: * The associated `EntityModel`. Chris@17: * @param {bool} isActive Chris@17: * Whether the in-place editor is active or not. Chris@17: * Chris@17: * @return {Drupal.quickedit.ContextualLinkView} Chris@17: * The `ContextualLinkView` in question. Chris@17: */ Chris@17: render(entityModel, isActive) { Chris@17: this.$el.find('a').attr('aria-pressed', isActive); Chris@17: Chris@17: // Hides the contextual links if an in-place editor is active. Chris@17: this.$el.closest('.contextual').toggle(!isActive); Chris@17: Chris@17: return this; Chris@17: }, Chris@0: }, Chris@17: ); Chris@17: })(jQuery, Backbone, Drupal);