diff options
author | Alex Pott <alex.a.pott@googlemail.com> | 2021-12-18 06:12:16 +0000 |
---|---|---|
committer | Alex Pott <alex.a.pott@googlemail.com> | 2021-12-18 06:12:16 +0000 |
commit | f1e57201c28dbc62dd07239c7d803b6d760ed44a (patch) | |
tree | 2c0359ed31b0a78632c2ac8d8407ff8e8b8df419 /core/modules/contextual/js/contextual.js | |
parent | 00ad1d7572f27c272b5b7fc70941016989b0cfa1 (diff) | |
download | drupal-f1e57201c28dbc62dd07239c7d803b6d760ed44a.tar.gz drupal-f1e57201c28dbc62dd07239c7d803b6d760ed44a.zip |
Issue #3253148 by mherchel, longwave, ckrina, droplet: Remove IE from core's browserlist, remove non-essential CSS importing and recompile assets
Diffstat (limited to 'core/modules/contextual/js/contextual.js')
-rw-r--r-- | core/modules/contextual/js/contextual.js | 77 |
1 files changed, 40 insertions, 37 deletions
diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js index 4911b2949b8f..c7f5da87f6ff 100644 --- a/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -6,18 +6,18 @@ **/ (function ($, Drupal, drupalSettings, _, Backbone, JSON, storage) { - var options = $.extend(drupalSettings.contextual, { + const options = $.extend(drupalSettings.contextual, { strings: { open: Drupal.t('Open'), close: Drupal.t('Close') } }); - var cachedPermissionsHash = storage.getItem('Drupal.contextual.permissionsHash'); - var permissionsHash = drupalSettings.user.permissionsHash; + const cachedPermissionsHash = storage.getItem('Drupal.contextual.permissionsHash'); + const permissionsHash = drupalSettings.user.permissionsHash; if (cachedPermissionsHash !== permissionsHash) { if (typeof permissionsHash === 'string') { - _.chain(storage).keys().each(function (key) { + _.chain(storage).keys().each(key => { if (key.substring(0, 18) === 'Drupal.contextual.') { storage.removeItem(key); } @@ -28,19 +28,19 @@ } function adjustIfNestedAndOverlapping($contextual) { - var $contextuals = $contextual.parents('.contextual-region').eq(-1).find('.contextual'); + const $contextuals = $contextual.parents('.contextual-region').eq(-1).find('.contextual'); if ($contextuals.length <= 1) { return; } - var firstTop = $contextuals.eq(0).offset().top; - var secondTop = $contextuals.eq(1).offset().top; + const firstTop = $contextuals.eq(0).offset().top; + const secondTop = $contextuals.eq(1).offset().top; if (firstTop === secondTop) { - var $nestedContextual = $contextuals.eq(1); - var height = 0; - var $trigger = $nestedContextual.find('.trigger'); + const $nestedContextual = $contextuals.eq(1); + let height = 0; + const $trigger = $nestedContextual.find('.trigger'); $trigger.removeClass('visually-hidden'); height = $nestedContextual.height(); $trigger.addClass('visually-hidden'); @@ -51,21 +51,21 @@ } function initContextual($contextual, html) { - var $region = $contextual.closest('.contextual-region'); - var contextual = Drupal.contextual; + const $region = $contextual.closest('.contextual-region'); + const contextual = Drupal.contextual; $contextual.html(html).addClass('contextual').prepend(Drupal.theme('contextualTrigger')); - var destination = "destination=".concat(Drupal.encodePath(Drupal.url(drupalSettings.path.currentPath))); + const destination = `destination=${Drupal.encodePath(Drupal.url(drupalSettings.path.currentPath))}`; $contextual.find('.contextual-links a').each(function () { - var url = this.getAttribute('href'); - var glue = url.indexOf('?') === -1 ? '?' : '&'; + const url = this.getAttribute('href'); + const glue = url.indexOf('?') === -1 ? '?' : '&'; this.setAttribute('href', url + glue + destination); }); - var model = new contextual.StateModel({ + const model = new contextual.StateModel({ title: $region.find('h2').eq(0).text().trim() }); - var viewOptions = $.extend({ + const viewOptions = $.extend({ el: $contextual, - model: model + model }, options); contextual.views.push({ visual: new contextual.VisualView(viewOptions), @@ -74,41 +74,41 @@ }); contextual.regionViews.push(new contextual.RegionView($.extend({ el: $region, - model: model + model }, options))); contextual.collection.add(model); $(document).trigger('drupalContextualLinkAdded', { $el: $contextual, - $region: $region, - model: model + $region, + model }); adjustIfNestedAndOverlapping($contextual); } Drupal.behaviors.contextual = { - attach: function attach(context) { - var $context = $(context); - var $placeholders = $(once('contextual-render', '[data-contextual-id]', context)); + attach(context) { + const $context = $(context); + let $placeholders = $(once('contextual-render', '[data-contextual-id]', context)); if ($placeholders.length === 0) { return; } - var ids = []; + const ids = []; $placeholders.each(function () { ids.push({ id: $(this).attr('data-contextual-id'), token: $(this).attr('data-contextual-token') }); }); - var uncachedIDs = []; - var uncachedTokens = []; - ids.forEach(function (contextualID) { - var html = storage.getItem("Drupal.contextual.".concat(contextualID.id)); + const uncachedIDs = []; + const uncachedTokens = []; + ids.forEach(contextualID => { + const html = storage.getItem(`Drupal.contextual.${contextualID.id}`); if (html && html.length) { - window.setTimeout(function () { - initContextual($context.find("[data-contextual-id=\"".concat(contextualID.id, "\"]:empty")).eq(0), html); + window.setTimeout(() => { + initContextual($context.find(`[data-contextual-id="${contextualID.id}"]:empty`).eq(0), html); }); return; } @@ -126,22 +126,25 @@ 'tokens[]': uncachedTokens }, dataType: 'json', - success: function success(results) { - _.each(results, function (html, contextualID) { - storage.setItem("Drupal.contextual.".concat(contextualID), html); + + success(results) { + _.each(results, (html, contextualID) => { + storage.setItem(`Drupal.contextual.${contextualID}`, html); if (html.length > 0) { - $placeholders = $context.find("[data-contextual-id=\"".concat(contextualID, "\"]")); + $placeholders = $context.find(`[data-contextual-id="${contextualID}"]`); - for (var i = 0; i < $placeholders.length; i++) { + for (let i = 0; i < $placeholders.length; i++) { initContextual($placeholders.eq(i), html); } } }); } + }); } } + }; Drupal.contextual = { views: [], @@ -155,7 +158,7 @@ return '<button class="trigger visually-hidden focusable" type="button"></button>'; }; - $(document).on('drupalContextualLinkAdded', function (event, data) { + $(document).on('drupalContextualLinkAdded', (event, data) => { Drupal.ajax.bindAjaxLinks(data.$el[0]); }); })(jQuery, Drupal, drupalSettings, _, Backbone, window.JSON, window.sessionStorage);
\ No newline at end of file |