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/contextual.es6.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/contextual.es6.js')
-rw-r--r-- | core/modules/contextual/js/contextual.es6.js | 69 |
1 files changed, 48 insertions, 21 deletions
diff --git a/core/modules/contextual/js/contextual.es6.js b/core/modules/contextual/js/contextual.es6.js index d3e5973440f6..46a57085dfa9 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, +); |