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