annotate core/modules/quickedit/js/views/ContextualLinkView.es6.js @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 129ea1e6d783
children
rev   line source
Chris@0 1 /**
Chris@0 2 * @file
Chris@0 3 * A Backbone View that provides a dynamic contextual link.
Chris@0 4 */
Chris@0 5
Chris@17 6 (function($, Backbone, Drupal) {
Chris@17 7 Drupal.quickedit.ContextualLinkView = Backbone.View.extend(
Chris@17 8 /** @lends Drupal.quickedit.ContextualLinkView# */ {
Chris@17 9 /**
Chris@17 10 * Define all events to listen to.
Chris@17 11 *
Chris@17 12 * @return {object}
Chris@17 13 * A map of events.
Chris@17 14 */
Chris@17 15 events() {
Chris@17 16 // Prevents delay and simulated mouse events.
Chris@17 17 function touchEndToClick(event) {
Chris@17 18 event.preventDefault();
Chris@17 19 event.target.click();
Chris@17 20 }
Chris@0 21
Chris@17 22 return {
Chris@17 23 'click a': function(event) {
Chris@17 24 event.preventDefault();
Chris@17 25 this.model.set('state', 'launching');
Chris@17 26 },
Chris@17 27 'touchEnd a': touchEndToClick,
Chris@17 28 };
Chris@17 29 },
Chris@0 30
Chris@17 31 /**
Chris@17 32 * Create a new contextual link view.
Chris@17 33 *
Chris@17 34 * @constructs
Chris@17 35 *
Chris@17 36 * @augments Backbone.View
Chris@17 37 *
Chris@17 38 * @param {object} options
Chris@17 39 * An object with the following keys:
Chris@17 40 * @param {Drupal.quickedit.EntityModel} options.model
Chris@17 41 * The associated entity's model.
Chris@17 42 * @param {Drupal.quickedit.AppModel} options.appModel
Chris@17 43 * The application state model.
Chris@17 44 * @param {object} options.strings
Chris@17 45 * The strings for the "Quick edit" link.
Chris@17 46 */
Chris@17 47 initialize(options) {
Chris@17 48 // Insert the text of the quick edit toggle.
Chris@17 49 this.$el.find('a').text(options.strings.quickEdit);
Chris@17 50 // Initial render.
Chris@17 51 this.render();
Chris@17 52 // Re-render whenever this entity's isActive attribute changes.
Chris@17 53 this.listenTo(this.model, 'change:isActive', this.render);
Chris@17 54 },
Chris@17 55
Chris@17 56 /**
Chris@17 57 * Render function for the contextual link view.
Chris@17 58 *
Chris@17 59 * @param {Drupal.quickedit.EntityModel} entityModel
Chris@17 60 * The associated `EntityModel`.
Chris@17 61 * @param {bool} isActive
Chris@17 62 * Whether the in-place editor is active or not.
Chris@17 63 *
Chris@17 64 * @return {Drupal.quickedit.ContextualLinkView}
Chris@17 65 * The `ContextualLinkView` in question.
Chris@17 66 */
Chris@17 67 render(entityModel, isActive) {
Chris@17 68 this.$el.find('a').attr('aria-pressed', isActive);
Chris@17 69
Chris@17 70 // Hides the contextual links if an in-place editor is active.
Chris@17 71 this.$el.closest('.contextual').toggle(!isActive);
Chris@17 72
Chris@17 73 return this;
Chris@17 74 },
Chris@0 75 },
Chris@17 76 );
Chris@17 77 })(jQuery, Backbone, Drupal);