3 * A Backbone View that provides a dynamic contextual link.
6 (function ($, Backbone, Drupal) {
10 Drupal.quickedit.ContextualLinkView = Backbone.View.extend(/** @lends Drupal.quickedit.ContextualLinkView# */{
13 * Define all events to listen to.
19 // Prevents delay and simulated mouse events.
20 function touchEndToClick(event) {
21 event.preventDefault();
26 'click a': function (event) {
27 event.preventDefault();
28 this.model.set('state', 'launching');
30 'touchEnd a': touchEndToClick
35 * Create a new contextual link view.
39 * @augments Backbone.View
41 * @param {object} options
42 * An object with the following keys:
43 * @param {Drupal.quickedit.EntityModel} options.model
44 * The associated entity's model.
45 * @param {Drupal.quickedit.AppModel} options.appModel
46 * The application state model.
47 * @param {object} options.strings
48 * The strings for the "Quick edit" link.
50 initialize: function (options) {
51 // Insert the text of the quick edit toggle.
52 this.$el.find('a').text(options.strings.quickEdit);
55 // Re-render whenever this entity's isActive attribute changes.
56 this.listenTo(this.model, 'change:isActive', this.render);
60 * Render function for the contextual link view.
62 * @param {Drupal.quickedit.EntityModel} entityModel
63 * The associated `EntityModel`.
64 * @param {bool} isActive
65 * Whether the in-place editor is active or not.
67 * @return {Drupal.quickedit.ContextualLinkView}
68 * The `ContextualLinkView` in question.
70 render: function (entityModel, isActive) {
71 this.$el.find('a').attr('aria-pressed', isActive);
73 // Hides the contextual links if an in-place editor is active.
74 this.$el.closest('.contextual').toggle(!isActive);
81 })(jQuery, Backbone, Drupal);