annotate core/modules/quickedit/js/views/ContextualLinkView.es6.js @ 4:a9cd425dd02b

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