3 * A Backbone View that provides a dynamic contextual link.
6 (function ($, Backbone, Drupal) {
7 Drupal.quickedit.ContextualLinkView = Backbone.View.extend(/** @lends Drupal.quickedit.ContextualLinkView# */{
10 * Define all events to listen to.
16 // Prevents delay and simulated mouse events.
17 function touchEndToClick(event) {
18 event.preventDefault();
23 'click a': function (event) {
24 event.preventDefault();
25 this.model.set('state', 'launching');
27 'touchEnd a': touchEndToClick,
32 * Create a new contextual link view.
36 * @augments Backbone.View
38 * @param {object} options
39 * An object with the following keys:
40 * @param {Drupal.quickedit.EntityModel} options.model
41 * The associated entity's model.
42 * @param {Drupal.quickedit.AppModel} options.appModel
43 * The application state model.
44 * @param {object} options.strings
45 * The strings for the "Quick edit" link.
48 // Insert the text of the quick edit toggle.
49 this.$el.find('a').text(options.strings.quickEdit);
52 // Re-render whenever this entity's isActive attribute changes.
53 this.listenTo(this.model, 'change:isActive', this.render);
57 * Render function for the contextual link view.
59 * @param {Drupal.quickedit.EntityModel} entityModel
60 * The associated `EntityModel`.
61 * @param {bool} isActive
62 * Whether the in-place editor is active or not.
64 * @return {Drupal.quickedit.ContextualLinkView}
65 * The `ContextualLinkView` in question.
67 render(entityModel, isActive) {
68 this.$el.find('a').attr('aria-pressed', isActive);
70 // Hides the contextual links if an in-place editor is active.
71 this.$el.closest('.contextual').toggle(!isActive);
77 }(jQuery, Backbone, Drupal));