diff options
author | Lauri Eskola <lauriii@1078742.no-reply.drupal.org> | 2018-08-09 18:49:18 +0300 |
---|---|---|
committer | Lauri Eskola <lauriii@1078742.no-reply.drupal.org> | 2018-08-09 18:49:18 +0300 |
commit | e742590eedd0f8bfe0f4f21710df3ddfe0524521 (patch) | |
tree | 6ca0c5c851f63186f0cb1ca52a28ee899dd3aa14 /core/modules/contextual/js | |
parent | c6e6709878839e0639d73d7c1e4420a8008e8a33 (diff) | |
download | drupal-e742590eedd0f8bfe0f4f21710df3ddfe0524521.tar.gz drupal-e742590eedd0f8bfe0f4f21710df3ddfe0524521.zip |
Issue #2981652 by ApacheEx, corbacho, drpal, dawehner, xjm, alexpott, lauriii: Format core JavaScript using recently add Prettier
Diffstat (limited to 'core/modules/contextual/js')
-rw-r--r-- | core/modules/contextual/js/contextual.es6.js | 69 | ||||
-rw-r--r-- | core/modules/contextual/js/contextual.js | 4 | ||||
-rw-r--r-- | core/modules/contextual/js/contextual.toolbar.es6.js | 34 | ||||
-rw-r--r-- | core/modules/contextual/js/models/StateModel.es6.js | 189 | ||||
-rw-r--r-- | core/modules/contextual/js/toolbar/models/StateModel.es6.js | 193 | ||||
-rw-r--r-- | core/modules/contextual/js/toolbar/views/AuralView.es6.js | 192 | ||||
-rw-r--r-- | core/modules/contextual/js/toolbar/views/VisualView.es6.js | 139 | ||||
-rw-r--r-- | core/modules/contextual/js/views/AuralView.es6.js | 94 | ||||
-rw-r--r-- | core/modules/contextual/js/views/KeyboardView.es6.js | 92 | ||||
-rw-r--r-- | core/modules/contextual/js/views/RegionView.es6.js | 95 | ||||
-rw-r--r-- | core/modules/contextual/js/views/VisualView.es6.js | 145 |
11 files changed, 658 insertions, 588 deletions
diff --git a/core/modules/contextual/js/contextual.es6.js b/core/modules/contextual/js/contextual.es6.js index d3e5973440f..46a57085dfa 100644 --- a/core/modules/contextual/js/contextual.es6.js +++ b/core/modules/contextual/js/contextual.es6.js @@ -3,7 +3,7 @@ * Attaches behaviors for the Contextual module. */ -(function ($, Drupal, drupalSettings, _, Backbone, JSON, storage) { +(function($, Drupal, drupalSettings, _, Backbone, JSON, storage) { const options = $.extend( drupalSettings.contextual, // Merge strings on top of drupalSettings so that they are not mutable. @@ -17,15 +17,19 @@ // Clear the cached contextual links whenever the current user's set of // permissions changes. - const cachedPermissionsHash = storage.getItem('Drupal.contextual.permissionsHash'); + const cachedPermissionsHash = storage.getItem( + 'Drupal.contextual.permissionsHash', + ); const permissionsHash = drupalSettings.user.permissionsHash; if (cachedPermissionsHash !== permissionsHash) { if (typeof permissionsHash === 'string') { - _.chain(storage).keys().each((key) => { - if (key.substring(0, 18) === 'Drupal.contextual.') { - storage.removeItem(key); - } - }); + _.chain(storage) + .keys() + .each(key => { + if (key.substring(0, 18) === 'Drupal.contextual.') { + storage.removeItem(key); + } + }); } storage.setItem('Drupal.contextual.permissionsHash', permissionsHash); } @@ -42,7 +46,8 @@ function adjustIfNestedAndOverlapping($contextual) { const $contextuals = $contextual // @todo confirm that .closest() is not sufficient - .parents('.contextual-region').eq(-1) + .parents('.contextual-region') + .eq(-1) .find('.contextual'); // Early-return when there's no nesting. @@ -93,16 +98,22 @@ .prepend(Drupal.theme('contextualTrigger')); // Set the destination parameter on each of the contextual links. - const destination = `destination=${Drupal.encodePath(drupalSettings.path.currentPath)}`; - $contextual.find('.contextual-links a').each(function () { + const destination = `destination=${Drupal.encodePath( + drupalSettings.path.currentPath, + )}`; + $contextual.find('.contextual-links a').each(function() { const url = this.getAttribute('href'); - const glue = (url.indexOf('?') === -1) ? '?' : '&'; + const glue = url.indexOf('?') === -1 ? '?' : '&'; this.setAttribute('href', url + glue + destination); }); // Create a model and the appropriate views. const model = new contextual.StateModel({ - title: $region.find('h2').eq(0).text().trim(), + title: $region + .find('h2') + .eq(0) + .text() + .trim(), }); const viewOptions = $.extend({ el: $contextual, model }, options); contextual.views.push({ @@ -147,19 +158,21 @@ const $context = $(context); // Find all contextual links placeholders, if any. - let $placeholders = $context.find('[data-contextual-id]').once('contextual-render'); + let $placeholders = $context + .find('[data-contextual-id]') + .once('contextual-render'); if ($placeholders.length === 0) { return; } // Collect the IDs for all contextual links placeholders. const ids = []; - $placeholders.each(function () { + $placeholders.each(function() { ids.push($(this).attr('data-contextual-id')); }); // Update all contextual links placeholders whose HTML is cached. - const uncachedIDs = _.filter(ids, (contextualID) => { + const uncachedIDs = _.filter(ids, contextualID => { const html = storage.getItem(`Drupal.contextual.${contextualID}`); if (html && html.length) { // Initialize after the current execution cycle, to make the AJAX @@ -168,7 +181,10 @@ // the chance to set up an event listener on the Backbone collection // Drupal.contextual.collection. window.setTimeout(() => { - initContextual($context.find(`[data-contextual-id="${contextualID}"]`), html); + initContextual( + $context.find(`[data-contextual-id="${contextualID}"]`), + html, + ); }); return false; } @@ -196,7 +212,9 @@ // possible for multiple identical placeholders exist on the // page (probably because the same content appears more than // once). - $placeholders = $context.find(`[data-contextual-id="${contextualID}"]`); + $placeholders = $context.find( + `[data-contextual-id="${contextualID}"]`, + ); // Initialize the contextual links. for (let i = 0; i < $placeholders.length; i++) { @@ -216,7 +234,6 @@ * @namespace */ Drupal.contextual = { - /** * The {@link Drupal.contextual.View} instances associated with each list * element of contextual links. @@ -239,7 +256,9 @@ * * @type {Backbone.Collection} */ - Drupal.contextual.collection = new Backbone.Collection([], { model: Drupal.contextual.StateModel }); + Drupal.contextual.collection = new Backbone.Collection([], { + model: Drupal.contextual.StateModel, + }); /** * A trigger is an interactive element often bound to a click handler. @@ -247,7 +266,7 @@ * @return {string} * A string representing a DOM fragment. */ - Drupal.theme.contextualTrigger = function () { + Drupal.theme.contextualTrigger = function() { return '<button class="trigger visually-hidden focusable" type="button"></button>'; }; @@ -264,4 +283,12 @@ $(document).on('drupalContextualLinkAdded', (event, data) => { Drupal.ajax.bindAjaxLinks(data.$el[0]); }); -}(jQuery, Drupal, drupalSettings, _, Backbone, window.JSON, window.sessionStorage)); +})( + jQuery, + Drupal, + drupalSettings, + _, + Backbone, + window.JSON, + window.sessionStorage, +); diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js index 7e6d000d407..049233b4e13 100644 --- a/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -139,7 +139,9 @@ regionViews: [] }; - Drupal.contextual.collection = new Backbone.Collection([], { model: Drupal.contextual.StateModel }); + Drupal.contextual.collection = new Backbone.Collection([], { + model: Drupal.contextual.StateModel + }); Drupal.theme.contextualTrigger = function () { return '<button class="trigger visually-hidden focusable" type="button"></button>'; diff --git a/core/modules/contextual/js/contextual.toolbar.es6.js b/core/modules/contextual/js/contextual.toolbar.es6.js index 9538288d6c1..953f76496c9 100644 --- a/core/modules/contextual/js/contextual.toolbar.es6.js +++ b/core/modules/contextual/js/contextual.toolbar.es6.js @@ -3,10 +3,14 @@ * Attaches behaviors for the Contextual module's edit toolbar tab. */ -(function ($, Drupal, Backbone) { +(function($, Drupal, Backbone) { const strings = { - tabbingReleased: Drupal.t('Tabbing is no longer constrained by the Contextual module.'), - tabbingConstrained: Drupal.t('Tabbing is constrained to a set of @contextualsCount and the edit mode toggle.'), + tabbingReleased: Drupal.t( + 'Tabbing is no longer constrained by the Contextual module.', + ), + tabbingConstrained: Drupal.t( + 'Tabbing is constrained to a set of @contextualsCount and the edit mode toggle.', + ), pressEsc: Drupal.t('Press the esc key to exit.'), }; @@ -22,14 +26,19 @@ } const contextualToolbar = Drupal.contextualToolbar; - contextualToolbar.model = new contextualToolbar.StateModel({ - // Checks whether localStorage indicates we should start in edit mode - // rather than view mode. - // @see Drupal.contextualToolbar.VisualView.persist - isViewing: localStorage.getItem('Drupal.contextualToolbar.isViewing') !== 'false', - }, { - contextualCollection: Drupal.contextual.collection, - }); + contextualToolbar.model = new contextualToolbar.StateModel( + { + // Checks whether localStorage indicates we should start in edit mode + // rather than view mode. + // @see Drupal.contextualToolbar.VisualView.persist + isViewing: + localStorage.getItem('Drupal.contextualToolbar.isViewing') !== + 'false', + }, + { + contextualCollection: Drupal.contextual.collection, + }, + ); const viewOptions = { el: $('.toolbar .toolbar-bar .contextual-toolbar-tab'), @@ -62,7 +71,6 @@ * @namespace */ Drupal.contextualToolbar = { - /** * The {@link Drupal.contextualToolbar.StateModel} instance. * @@ -70,4 +78,4 @@ */ model: null, }; -}(jQuery, Drupal, Backbone)); +})(jQuery, Drupal, Backbone); diff --git a/core/modules/contextual/js/models/StateModel.es6.js b/core/modules/contextual/js/models/StateModel.es6.js index 2eab4a63522..bb142a9aa98 100644 --- a/core/modules/contextual/js/models/StateModel.es6.js +++ b/core/modules/contextual/js/models/StateModel.es6.js @@ -3,7 +3,7 @@ * A Backbone Model for the state of a contextual link's trigger, list & region. */ -(function (Drupal, Backbone) { +(function(Drupal, Backbone) { /** * Models the state of a contextual link's trigger, list & region. * @@ -11,118 +11,117 @@ * * @augments Backbone.Model */ - Drupal.contextual.StateModel = Backbone.Model.extend(/** @lends Drupal.contextual.StateModel# */{ - - /** - * @type {object} - * - * @prop {string} title - * @prop {bool} regionIsHovered - * @prop {bool} hasFocus - * @prop {bool} isOpen - * @prop {bool} isLocked - */ - defaults: /** @lends Drupal.contextual.StateModel# */{ - + Drupal.contextual.StateModel = Backbone.Model.extend( + /** @lends Drupal.contextual.StateModel# */ { /** - * The title of the entity to which these contextual links apply. + * @type {object} * - * @type {string} + * @prop {string} title + * @prop {bool} regionIsHovered + * @prop {bool} hasFocus + * @prop {bool} isOpen + * @prop {bool} isLocked */ - title: '', + defaults: /** @lends Drupal.contextual.StateModel# */ { + /** + * The title of the entity to which these contextual links apply. + * + * @type {string} + */ + title: '', + + /** + * Represents if the contextual region is being hovered. + * + * @type {bool} + */ + regionIsHovered: false, + + /** + * Represents if the contextual trigger or options have focus. + * + * @type {bool} + */ + hasFocus: false, + + /** + * Represents if the contextual options for an entity are available to + * be selected (i.e. whether the list of options is visible). + * + * @type {bool} + */ + isOpen: false, + + /** + * When the model is locked, the trigger remains active. + * + * @type {bool} + */ + isLocked: false, + }, /** - * Represents if the contextual region is being hovered. + * Opens or closes the contextual link. + * + * If it is opened, then also give focus. * - * @type {bool} + * @return {Drupal.contextual.StateModel} + * The current contextual state model. */ - regionIsHovered: false, + toggleOpen() { + const newIsOpen = !this.get('isOpen'); + this.set('isOpen', newIsOpen); + if (newIsOpen) { + this.focus(); + } + return this; + }, /** - * Represents if the contextual trigger or options have focus. + * Closes this contextual link. * - * @type {bool} + * Does not call blur() because we want to allow a contextual link to have + * focus, yet be closed for example when hovering. + * + * @return {Drupal.contextual.StateModel} + * The current contextual state model. */ - hasFocus: false, + close() { + this.set('isOpen', false); + return this; + }, /** - * Represents if the contextual options for an entity are available to - * be selected (i.e. whether the list of options is visible). + * Gives focus to this contextual link. + * + * Also closes + removes focus from every other contextual link. * - * @type {bool} + * @return {Drupal.contextual.StateModel} + * The current contextual state model. */ - isOpen: false, + focus() { + this.set('hasFocus', true); + const cid = this.cid; + this.collection.each(model => { + if (model.cid !== cid) { + model.close().blur(); + } + }); + return this; + }, /** - * When the model is locked, the trigger remains active. + * Removes focus from this contextual link, unless it is open. * - * @type {bool} + * @return {Drupal.contextual.StateModel} + * The current contextual state model. */ - isLocked: false, - }, - - /** - * Opens or closes the contextual link. - * - * If it is opened, then also give focus. - * - * @return {Drupal.contextual.StateModel} - * The current contextual state model. - */ - toggleOpen() { - const newIsOpen = !this.get('isOpen'); - this.set('isOpen', newIsOpen); - if (newIsOpen) { - this.focus(); - } - return this; - }, - - /** - * Closes this contextual link. - * - * Does not call blur() because we want to allow a contextual link to have - * focus, yet be closed for example when hovering. - * - * @return {Drupal.contextual.StateModel} - * The current contextual state model. - */ - close() { - this.set('isOpen', false); - return this; - }, - - /** - * Gives focus to this contextual link. - * - * Also closes + removes focus from every other contextual link. - * - * @return {Drupal.contextual.StateModel} - * The current contextual state model. - */ - focus() { - this.set('hasFocus', true); - const cid = this.cid; - this.collection.each((model) => { - if (model.cid !== cid) { - model.close().blur(); + blur() { + if (!this.get('isOpen')) { + this.set('hasFocus', false); } - }); - return this; - }, - - /** - * Removes focus from this contextual link, unless it is open. - * - * @return {Drupal.contextual.StateModel} - * The current contextual state model. - */ - blur() { - if (!this.get('isOpen')) { - this.set('hasFocus', false); - } - return this; + return this; + }, }, - - }); -}(Drupal, Backbone)); + ); +})(Drupal, Backbone); diff --git a/core/modules/contextual/js/toolbar/models/StateModel.es6.js b/core/modules/contextual/js/toolbar/models/StateModel.es6.js index 0a1b1614687..73781534ce0 100644 --- a/core/modules/contextual/js/toolbar/models/StateModel.es6.js +++ b/core/modules/contextual/js/toolbar/models/StateModel.es6.js @@ -3,113 +3,120 @@ * A Backbone Model for the state of Contextual module's edit toolbar tab. */ -(function (Drupal, Backbone) { - Drupal.contextualToolbar.StateModel = Backbone.Model.extend(/** @lends Drupal.contextualToolbar.StateModel# */{ - - /** - * @type {object} - * - * @prop {bool} isViewing - * @prop {bool} isVisible - * @prop {number} contextualCount - * @prop {Drupal~TabbingContext} tabbingContext - */ - defaults: /** @lends Drupal.contextualToolbar.StateModel# */{ - +(function(Drupal, Backbone) { + Drupal.contextualToolbar.StateModel = Backbone.Model.extend( + /** @lends Drupal.contextualToolbar.StateModel# */ { /** - * Indicates whether the toggle is currently in "view" or "edit" mode. + * @type {object} * - * @type {bool} + * @prop {bool} isViewing + * @prop {bool} isVisible + * @prop {number} contextualCount + * @prop {Drupal~TabbingContext} tabbingContext */ - isViewing: true, + defaults: /** @lends Drupal.contextualToolbar.StateModel# */ { + /** + * Indicates whether the toggle is currently in "view" or "edit" mode. + * + * @type {bool} + */ + isViewing: true, + + /** + * Indicates whether the toggle should be visible or hidden. Automatically + * calculated, depends on contextualCount. + * + * @type {bool} + */ + isVisible: false, + + /** + * Tracks how many contextual links exist on the page. + * + * @type {number} + */ + contextualCount: 0, + + /** + * A TabbingContext object as returned by {@link Drupal~TabbingManager}: + * the set of tabbable elements when edit mode is enabled. + * + * @type {?Drupal~TabbingContext} + */ + tabbingContext: null, + }, /** - * Indicates whether the toggle should be visible or hidden. Automatically - * calculated, depends on contextualCount. + * Models the state of the edit mode toggle. + * + * @constructs * - * @type {bool} + * @augments Backbone.Model + * + * @param {object} attrs + * Attributes for the backbone model. + * @param {object} options + * An object with the following option: + * @param {Backbone.collection} options.contextualCollection + * The collection of {@link Drupal.contextual.StateModel} models that + * represent the contextual links on the page. */ - isVisible: false, + initialize(attrs, options) { + // Respond to new/removed contextual links. + this.listenTo( + options.contextualCollection, + 'reset remove add', + this.countContextualLinks, + ); + this.listenTo( + options.contextualCollection, + 'add', + this.lockNewContextualLinks, + ); + + // Automatically determine visibility. + this.listenTo(this, 'change:contextualCount', this.updateVisibility); + + // Whenever edit mode is toggled, lock all contextual links. + this.listenTo(this, 'change:isViewing', (model, isViewing) => { + options.contextualCollection.each(contextualModel => { + contextualModel.set('isLocked', !isViewing); + }); + }); + }, /** - * Tracks how many contextual links exist on the page. + * Tracks the number of contextual link models in the collection. * - * @type {number} + * @param {Drupal.contextual.StateModel} contextualModel + * The contextual links model that was added or removed. + * @param {Backbone.Collection} contextualCollection + * The collection of contextual link models. */ - contextualCount: 0, + countContextualLinks(contextualModel, contextualCollection) { + this.set('contextualCount', contextualCollection.length); + }, /** - * A TabbingContext object as returned by {@link Drupal~TabbingManager}: - * the set of tabbable elements when edit mode is enabled. + * Lock newly added contextual links if edit mode is enabled. * - * @type {?Drupal~TabbingContext} + * @param {Drupal.contextual.StateModel} contextualModel + * The contextual links model that was added. + * @param {Backbone.Collection} [contextualCollection] + * The collection of contextual link models. */ - tabbingContext: null, - }, - - /** - * Models the state of the edit mode toggle. - * - * @constructs - * - * @augments Backbone.Model - * - * @param {object} attrs - * Attributes for the backbone model. - * @param {object} options - * An object with the following option: - * @param {Backbone.collection} options.contextualCollection - * The collection of {@link Drupal.contextual.StateModel} models that - * represent the contextual links on the page. - */ - initialize(attrs, options) { - // Respond to new/removed contextual links. - this.listenTo(options.contextualCollection, 'reset remove add', this.countContextualLinks); - this.listenTo(options.contextualCollection, 'add', this.lockNewContextualLinks); + lockNewContextualLinks(contextualModel, contextualCollection) { + if (!this.get('isViewing')) { + contextualModel.set('isLocked', true); + } + }, - // Automatically determine visibility. - this.listenTo(this, 'change:contextualCount', this.updateVisibility); - - // Whenever edit mode is toggled, lock all contextual links. - this.listenTo(this, 'change:isViewing', (model, isViewing) => { - options.contextualCollection.each((contextualModel) => { - contextualModel.set('isLocked', !isViewing); - }); - }); - }, - - /** - * Tracks the number of contextual link models in the collection. - * - * @param {Drupal.contextual.StateModel} contextualModel - * The contextual links model that was added or removed. - * @param {Backbone.Collection} contextualCollection - * The collection of contextual link models. - */ - countContextualLinks(contextualModel, contextualCollection) { - this.set('contextualCount', contextualCollection.length); - }, - - /** - * Lock newly added contextual links if edit mode is enabled. - * - * @param {Drupal.contextual.StateModel} contextualModel - * The contextual links model that was added. - * @param {Backbone.Collection} [contextualCollection] - * The collection of contextual link models. - */ - lockNewContextualLinks(contextualModel, contextualCollection) { - if (!this.get('isViewing')) { - contextualModel.set('isLocked', true); - } - }, - - /** - * Automatically updates visibility of the view/edit mode toggle. - */ - updateVisibility() { - this.set('isVisible', this.get('contextualCount') > 0); + /** + * Automatically updates visibility of the view/edit mode toggle. + */ + updateVisibility() { + this.set('isVisible', this.get('contextualCount') > 0); + }, }, - - }); -}(Drupal, Backbone)); + ); +})(Drupal, Backbone); diff --git a/core/modules/contextual/js/toolbar/views/AuralView.es6.js b/core/modules/contextual/js/toolbar/views/AuralView.es6.js index 757c8868d17..3d343354e19 100644 --- a/core/modules/contextual/js/toolbar/views/AuralView.es6.js +++ b/core/modules/contextual/js/toolbar/views/AuralView.es6.js @@ -3,102 +3,116 @@ * A Backbone View that provides the aural view of the edit mode toggle. */ -(function ($, Drupal, Backbone, _) { - Drupal.contextualToolbar.AuralView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.AuralView# */{ +(function($, Drupal, Backbone, _) { + Drupal.contextualToolbar.AuralView = Backbone.View.extend( + /** @lends Drupal.contextualToolbar.AuralView# */ { + /** + * Tracks whether the tabbing constraint announcement has been read once. + * + * @type {bool} + */ + announcedOnce: false, - /** - * Tracks whether the tabbing constraint announcement has been read once. - * - * @type {bool} - */ - announcedOnce: false, + /** + * Renders the aural view of the edit mode toggle (screen reader support). + * + * @constructs + * + * @augments Backbone.View + * + * @param {object} options + * Options for the view. + */ + initialize(options) { + this.options = options; - /** - * Renders the aural view of the edit mode toggle (screen reader support). - * - * @constructs - * - * @augments Backbone.View - * - * @param {object} options - * Options for the view. - */ - initialize(options) { - this.options = options; + this.listenTo(this.model, 'change', this.render); + this.listenTo(this.model, 'change:isViewing', this.manageTabbing); - this.listenTo(this.model, 'change', this.render); - this.listenTo(this.model, 'change:isViewing', this.manageTabbing); + $(document).on('keyup', _.bind(this.onKeypress, this)); + this.manageTabbing(); + }, - $(document).on('keyup', _.bind(this.onKeypress, this)); - this.manageTabbing(); - }, - - /** - * @inheritdoc - * - * @return {Drupal.contextualToolbar.AuralView} - * The current contextual toolbar aural view. - */ - render() { - // Render the state. - this.$el.find('button').attr('aria-pressed', !this.model.get('isViewing')); + /** + * @inheritdoc + * + * @return {Drupal.contextualToolbar.AuralView} + * The current contextual toolbar aural view. + */ + render() { + // Render the state. + this.$el + .find('button') + .attr('aria-pressed', !this.model.get('isViewing')); - return this; - }, + return this; + }, - /** - * Limits tabbing to the contextual links and edit mode toolbar tab. - */ - manageTabbing() { - let tabbingContext = this.model.get('tabbingContext'); - // Always release an existing tabbing context. - if (tabbingContext) { - // Only announce release when the context was active. - if (tabbingContext.active) { - Drupal.announce(this.options.strings.tabbingReleased); + /** + * Limits tabbing to the contextual links and edit mode toolbar tab. + */ + manageTabbing() { + let tabbingContext = this.model.get('tabbingContext'); + // Always release an existing tabbing context. + if (tabbingContext) { + // Only announce release when the context was active. + if (tabbingContext.active) { + Drupal.announce(this.options.strings.tabbingReleased); + } + tabbingContext.release(); } - tabbingContext.release(); - } - // Create a new tabbing context when edit mode is enabled. - if (!this.model.get('isViewing')) { - tabbingContext = Drupal.tabbingManager.constrain($('.contextual-toolbar-tab, .contextual')); - this.model.set('tabbingContext', tabbingContext); - this.announceTabbingConstraint(); - this.announcedOnce = true; - } - }, + // Create a new tabbing context when edit mode is enabled. + if (!this.model.get('isViewing')) { + tabbingContext = Drupal.tabbingManager.constrain( + $('.contextual-toolbar-tab, .contextual'), + ); + this.model.set('tabbingContext', tabbingContext); + this.announceTabbingConstraint(); + this.announcedOnce = true; + } + }, - /** - * Announces the current tabbing constraint. - */ - announceTabbingConstraint() { - const strings = this.options.strings; - Drupal.announce(Drupal.formatString(strings.tabbingConstrained, { - '@contextualsCount': Drupal.formatPlural(Drupal.contextual.collection.length, '@count contextual link', '@count contextual links'), - })); - Drupal.announce(strings.pressEsc); - }, + /** + * Announces the current tabbing constraint. + */ + announceTabbingConstraint() { + const strings = this.options.strings; + Drupal.announce( + Drupal.formatString(strings.tabbingConstrained, { + '@contextualsCount': Drupal.formatPlural( + Drupal.contextual.collection.length, + '@count contextual link', + '@count contextual links', + ), + }), + ); + Drupal.announce(strings.pressEsc); + }, - /** - * Responds to esc and tab key press events. - * - * @param {jQuery.Event} event - * The keypress event. - */ - onKeypress(event) { - // The first tab key press is tracked so that an annoucement about tabbing - // constraints can be raised if edit mode is enabled when the page is - // loaded. - if (!this.announcedOnce && event.keyCode === 9 && !this.model.get('isViewing')) { - this.announceTabbingConstraint(); - // Set announce to true so that this conditional block won't run again. - this.announcedOnce = true; - } - // Respond to the ESC key. Exit out of edit mode. - if (event.keyCode === 27) { - this.model.set('isViewing', true); - } + /** + * Responds to esc and tab key press events. + * + * @param {jQuery.Event} event + * The keypress event. + */ + onKeypress(event) { + // The first tab key press is tracked so that an annoucement about tabbing + // constraints can be raised if edit mode is enabled when the page is + // loaded. + if ( + !this.announcedOnce && + event.keyCode === 9 && + !this.model.get('isViewing') + ) { + this.announceTabbingConstraint(); + // Set announce to true so that this conditional block won't run again. + this.announcedOnce = true; + } + // Respond to the ESC key. Exit out of edit mode. + if (event.keyCode === 27) { + this.model.set('isViewing', true); + } + }, }, - - }); -}(jQuery, Drupal, Backbone, _)); + ); +})(jQuery, Drupal, Backbone, _); diff --git a/core/modules/contextual/js/toolbar/views/VisualView.es6.js b/core/modules/contextual/js/toolbar/views/VisualView.es6.js index 56bae27859f..d168d5414ca 100644 --- a/core/modules/contextual/js/toolbar/views/VisualView.es6.js +++ b/core/modules/contextual/js/toolbar/views/VisualView.es6.js @@ -3,78 +3,79 @@ * A Backbone View that provides the visual view of the edit mode toggle. */ -(function (Drupal, Backbone) { - Drupal.contextualToolbar.VisualView = Backbone.View.extend(/** @lends Drupal.contextualToolbar.VisualView# */{ +(function(Drupal, Backbone) { + Drupal.contextualToolbar.VisualView = Backbone.View.extend( + /** @lends Drupal.contextualToolbar.VisualView# */ { + /** + * Events for the Backbone view. + * + * @return {object} + * A mapping of events to be used in the view. + */ + events() { + // Prevents delay and simulated mouse events. + const touchEndToClick = function(event) { + event.preventDefault(); + event.target.click(); + }; - /** - * Events for the Backbone view. - * - * @return {object} - * A mapping of events to be used in the view. - */ - events() { - // Prevents delay and simulated mouse events. - const touchEndToClick = function (event) { - event.preventDefault(); - event.target.click(); - }; + return { + click() { + this.model.set('isViewing', !this.model.get('isViewing')); + }, + touchend: touchEndToClick, + }; + }, - return { - click() { - this.model.set('isViewing', !this.model.get('isViewing')); - }, - touchend: touchEndToClick, - }; - }, + /** + * Renders the visual view of the edit mode toggle. + * + * Listens to mouse & touch and handles edit mode toggle interactions. + * + * @constructs + * + * @augments Backbone.View + */ + initialize() { + this.listenTo(this.model, 'change', this.render); + this.listenTo(this.model, 'change:isViewing', this.persist); + }, - /** - * Renders the visual view of the edit mode toggle. - * - * Listens to mouse & touch and handles edit mode toggle interactions. - * - * @constructs - * - * @augments Backbone.View - */ - initialize() { - this.listenTo(this.model, 'change', this.render); - this.listenTo(this.model, 'change:isViewing', this.persist); - }, + /** + * @inheritdoc + * + * @return {Drupal.contextualToolbar.VisualView} + * The current contextual toolbar visual view. + */ + render() { + // Render the visibility. + this.$el.toggleClass('hidden', !this.model.get('isVisible')); + // Render the state. + this.$el + .find('button') + .toggleClass('is-active', !this.model.get('isViewing')); - /** - * @inheritdoc - * - * @return {Drupal.contextualToolbar.VisualView} - * The current contextual toolbar visual view. - */ - render() { - // Render the visibility. - this.$el.toggleClass('hidden', !this.model.get('isVisible')); - // Render the state. - this.$el.find('button').toggleClass('is-active', !this.model.get('isViewing')); + return this; + }, - return this; + /** + * Model change handler; persists the isViewing value to localStorage. + * + * `isViewing === true` is the default, so only stores in localStorage when + * it's not the default value (i.e. false). + * + * @param {Drupal.contextualToolbar.StateModel} model + * A {@link Drupal.contextualToolbar.StateModel} model. + * @param {bool} isViewing + * The value of the isViewing attribute in the model. + */ + persist(model, isViewing) { + if (!isViewing) { + localStorage.setItem('Drupal.contextualToolbar.isViewing', 'false'); + } else { + localStorage.removeItem('Drupal.contextualToolbar.isViewing'); + } + }, }, - - /** - * Model change handler; persists the isViewing value to localStorage. - * - * `isViewing === true` is the default, so only stores in localStorage when - * it's not the default value (i.e. false). - * - * @param {Drupal.contextualToolbar.StateModel} model - * A {@link Drupal.contextualToolbar.StateModel} model. - * @param {bool} isViewing - * The value of the isViewing attribute in the model. - */ - persist(model, isViewing) { - if (!isViewing) { - localStorage.setItem('Drupal.contextualToolbar.isViewing', 'false'); - } - else { - localStorage.removeItem('Drupal.contextualToolbar.isViewing'); - } - }, - - }); -}(Drupal, Backbone)); + ); +})(Drupal, Backbone); diff --git a/core/modules/contextual/js/views/AuralView.es6.js b/core/modules/contextual/js/views/AuralView.es6.js index 0141b04ba10..27574239ea6 100644 --- a/core/modules/contextual/js/views/AuralView.es6.js +++ b/core/modules/contextual/js/views/AuralView.es6.js @@ -3,49 +3,53 @@ * A Backbone View that provides the aural view of a contextual link. */ -(function (Drupal, Backbone) { - Drupal.contextual.AuralView = Backbone.View.extend(/** @lends Drupal.contextual.AuralView# */{ - - /** - * Renders the aural view of a contextual link (i.e. screen reader support). - * - * @constructs - * - * @augments Backbone.View - * - * @param {object} options - * Options for the view. - */ - initialize(options) { - this.options = options; - - this.listenTo(this.model, 'change', this.render); - - // Use aria-role form so that the number of items in the list is spoken. - this.$el.attr('role', 'form'); - - // Initial render. - this.render(); +(function(Drupal, Backbone) { + Drupal.contextual.AuralView = Backbone.View.extend( + /** @lends Drupal.contextual.AuralView# */ { + /** + * Renders the aural view of a contextual link (i.e. screen reader support). + * + * @constructs + * + * @augments Backbone.View + * + * @param {object} options + * Options for the view. + */ + initialize(options) { + this.options = options; + + this.listenTo(this.model, 'change', this.render); + + // Use aria-role form so that the number of items in the list is spoken. + this.$el.attr('role', 'form'); + + // Initial render. + this.render(); + }, + + /** + * @inheritdoc + */ + render() { + const isOpen = this.model.get('isOpen'); + + // Set the hidden property of the links. + this.$el.find('.contextual-links').prop('hidden', !isOpen); + + // Update the view of the trigger. + this.$el + .find('.trigger') + .text( + Drupal.t('@action @title configuration options', { + '@action': !isOpen + ? this.options.strings.open + : this.options.strings.close, + '@title': this.model.get('title'), + }), + ) + .attr('aria-pressed', isOpen); + }, }, - - /** - * @inheritdoc - */ - render() { - const isOpen = this.model.get('isOpen'); - - // Set the hidden property of the links. - this.$el.find('.contextual-links') - .prop('hidden', !isOpen); - - // Update the view of the trigger. - this.$el.find('.trigger') - .text(Drupal.t('@action @title configuration options', { - '@action': (!isOpen) ? this.options.strings.open : this.options.strings.close, - '@title': this.model.get('title'), - })) - .attr('aria-pressed', isOpen); - }, - - }); -}(Drupal, Backbone)); + ); +})(Drupal, Backbone); diff --git a/core/modules/contextual/js/views/KeyboardView.es6.js b/core/modules/contextual/js/views/KeyboardView.es6.js index 908b2495931..4c13f08e31c 100644 --- a/core/modules/contextual/js/views/KeyboardView.es6.js +++ b/core/modules/contextual/js/views/KeyboardView.es6.js @@ -3,56 +3,56 @@ * A Backbone View that provides keyboard interaction for a contextual link. */ -(function (Drupal, Backbone) { - Drupal.contextual.KeyboardView = Backbone.View.extend(/** @lends Drupal.contextual.KeyboardView# */{ - - /** - * @type {object} - */ - events: { - 'focus .trigger': 'focus', - 'focus .contextual-links a': 'focus', - 'blur .trigger': function () { - this.model.blur(); - }, - 'blur .contextual-links a': function () { - // Set up a timeout to allow a user to tab between the trigger and the - // contextual links without the menu dismissing. - const that = this; - this.timer = window.setTimeout(() => { - that.model.close().blur(); - }, 150); +(function(Drupal, Backbone) { + Drupal.contextual.KeyboardView = Backbone.View.extend( + /** @lends Drupal.contextual.KeyboardView# */ { + /** + * @type {object} + */ + events: { + 'focus .trigger': 'focus', + 'focus .contextual-links a': 'focus', + 'blur .trigger': function() { + this.model.blur(); + }, + 'blur .contextual-links a': function() { + // Set up a timeout to allow a user to tab between the trigger and the + // contextual links without the menu dismissing. + const that = this; + this.timer = window.setTimeout(() => { + that.model.close().blur(); + }, 150); + }, }, - }, - /** - * Provides keyboard interaction for a contextual link. - * - * @constructs - * - * @augments Backbone.View - */ - initialize() { /** - * The timer is used to create a delay before dismissing the contextual - * links on blur. This is only necessary when keyboard users tab into - * contextual links without edit mode (i.e. without TabbingManager). - * That means that if we decide to disable tabbing of contextual links - * without edit mode, all this timer logic can go away. + * Provides keyboard interaction for a contextual link. + * + * @constructs * - * @type {NaN|number} + * @augments Backbone.View */ - this.timer = NaN; - }, + initialize() { + /** + * The timer is used to create a delay before dismissing the contextual + * links on blur. This is only necessary when keyboard users tab into + * contextual links without edit mode (i.e. without TabbingManager). + * That means that if we decide to disable tabbing of contextual links + * without edit mode, all this timer logic can go away. + * + * @type {NaN|number} + */ + this.timer = NaN; + }, - /** - * Sets focus on the model; Clears the timer that dismisses the links. - */ - focus() { - // Clear the timeout that might have been set by blurring a link. - window.clearTimeout(this.timer); - this.model.focus(); + /** + * Sets focus on the model; Clears the timer that dismisses the links. + */ + focus() { + // Clear the timeout that might have been set by blurring a link. + window.clearTimeout(this.timer); + this.model.focus(); + }, }, - - }); -}(Drupal, Backbone)); + ); +})(Drupal, Backbone); diff --git a/core/modules/contextual/js/views/RegionView.es6.js b/core/modules/contextual/js/views/RegionView.es6.js index c1d3e8fe379..57048a77d68 100644 --- a/core/modules/contextual/js/views/RegionView.es6.js +++ b/core/modules/contextual/js/views/RegionView.es6.js @@ -3,53 +3,56 @@ * A Backbone View that renders the visual view of a contextual region element. */ -(function (Drupal, Backbone, Modernizr) { - Drupal.contextual.RegionView = Backbone.View.extend(/** @lends Drupal.contextual.RegionView# */{ +(function(Drupal, Backbone, Modernizr) { + Drupal.contextual.RegionView = Backbone.View.extend( + /** @lends Drupal.contextual.RegionView# */ { + /** + * Events for the Backbone view. + * + * @return {object} + * A mapping of events to be used in the view. + */ + events() { + let mapping = { + mouseenter() { + this.model.set('regionIsHovered', true); + }, + mouseleave() { + this.model + .close() + .blur() + .set('regionIsHovered', false); + }, + }; + // We don't want mouse hover events on touch. + if (Modernizr.touchevents) { + mapping = {}; + } + return mapping; + }, - /** - * Events for the Backbone view. - * - * @return {object} - * A mapping of events to be used in the view. - */ - events() { - let mapping = { - mouseenter() { - this.model.set('regionIsHovered', true); - }, - mouseleave() { - this.model.close().blur().set('regionIsHovered', false); - }, - }; - // We don't want mouse hover events on touch. - if (Modernizr.touchevents) { - mapping = {}; - } - return mapping; - }, - - /** - * Renders the visual view of a contextual region element. - * - * @constructs - * - * @augments Backbone.View - */ - initialize() { - this.listenTo(this.model, 'change:hasFocus', this.render); - }, + /** + * Renders the visual view of a contextual region element. + * + * @constructs + * + * @augments Backbone.View + */ + initialize() { + this.listenTo(this.model, 'change:hasFocus', this.render); + }, - /** - * @inheritdoc - * - * @return {Drupal.contextual.RegionView} - * The current contextual region view. - */ - render() { - this.$el.toggleClass('focus', this.model.get('hasFocus')); + /** + * @inheritdoc + * + * @return {Drupal.contextual.RegionView} + * The current contextual region view. + */ + render() { + this.$el.toggleClass('focus', this.model.get('hasFocus')); - return this; + return this; + }, }, - - }); -}(Drupal, Backbone, Modernizr)); + ); +})(Drupal, Backbone, Modernizr); diff --git a/core/modules/contextual/js/views/VisualView.es6.js b/core/modules/contextual/js/views/VisualView.es6.js index 385fa7deca3..57f68cacc37 100644 --- a/core/modules/contextual/js/views/VisualView.es6.js +++ b/core/modules/contextual/js/views/VisualView.es6.js @@ -3,80 +3,85 @@ * A Backbone View that provides the visual view of a contextual link. */ -(function (Drupal, Backbone, Modernizr) { - Drupal.contextual.VisualView = Backbone.View.extend(/** @lends Drupal.contextual.VisualView# */{ - - /** - * Events for the Backbone view. - * - * @return {object} - * A mapping of events to be used in the view. - */ - events() { - // Prevents delay and simulated mouse events. - const touchEndToClick = function (event) { - event.preventDefault(); - event.target.click(); - }; - const mapping = { - 'click .trigger': function () { - this.model.toggleOpen(); - }, - 'touchend .trigger': touchEndToClick, - 'click .contextual-links a': function () { - this.model.close().blur(); - }, - 'touchend .contextual-links a': touchEndToClick, - }; - // We only want mouse hover events on non-touch. - if (!Modernizr.touchevents) { - mapping.mouseenter = function () { - this.model.focus(); +(function(Drupal, Backbone, Modernizr) { + Drupal.contextual.VisualView = Backbone.View.extend( + /** @lends Drupal.contextual.VisualView# */ { + /** + * Events for the Backbone view. + * + * @return {object} + * A mapping of events to be used in the view. + */ + events() { + // Prevents delay and simulated mouse events. + const touchEndToClick = function(event) { + event.preventDefault(); + event.target.click(); }; - } - return mapping; - }, + const mapping = { + 'click .trigger': function() { + this.model.toggleOpen(); + }, + 'touchend .trigger': touchEndToClick, + 'click .contextual-links a': function() { + this.model.close().blur(); + }, + 'touchend .contextual-links a': touchEndToClick, + }; + // We only want mouse hover events on non-touch. + if (!Modernizr.touchevents) { + mapping.mouseenter = function() { + this.model.focus(); + }; + } + return mapping; + }, - /** - * Renders the visual view of a contextual link. Listens to mouse & touch. - * - * @constructs - * - * @augments Backbone.View - */ - initialize() { - this.listenTo(this.model, 'change', this.render); - }, + /** + * Renders the visual view of a contextual link. Listens to mouse & touch. + * + * @constructs + * + * @augments Backbone.View + */ + initialize() { + this.listenTo(this.model, 'change', this.render); + }, - /** - * @inheritdoc - * - * @return {Drupal.contextual.VisualView} - * The current contextual visual view. - */ - render() { - const isOpen = this.model.get('isOpen'); - // The trigger should be visible when: - // - the mouse hovered over the region, - // - the trigger is locked, - // - and for as long as the contextual menu is open. - const isVisible = this.model.get('isLocked') || this.model.get('regionIsHovered') || isOpen; + /** + * @inheritdoc + * + * @return {Drupal.contextual.VisualView} + * The current contextual visual view. + */ + render() { + const isOpen = this.model.get('isOpen'); + // The trigger should be visible when: + // - the mouse hovered over the region, + // - the trigger is locked, + // - and for as long as the contextual menu is open. + const isVisible = + this.model.get('isLocked') || + this.model.get('regionIsHovered') || + isOpen; - this.$el - // The open state determines if the links are visible. - .toggleClass('open', isOpen) - // Update the visibility of the trigger. - .find('.trigger').toggleClass('visually-hidden', !isVisible); + this.$el + // The open state determines if the links are visible. + .toggleClass('open', isOpen) + // Update the visibility of the trigger. + .find('.trigger') + .toggleClass('visually-hidden', !isVisible); - // Nested contextual region handling: hide any nested contextual triggers. - if ('isOpen' in this.model.changed) { - this.$el.closest('.contextual-region') - .find('.contextual .trigger:not(:first)') - .toggle(!isOpen); - } + // Nested contextual region handling: hide any nested contextual triggers. + if ('isOpen' in this.model.changed) { + this.$el + .closest('.contextual-region') + .find('.contextual .trigger:not(:first)') + .toggle(!isOpen); + } - return this; + return this; + }, }, - - }); -}(Drupal, Backbone, Modernizr)); + ); +})(Drupal, Backbone, Modernizr); |