Mercurial > hg > isophonics-drupal-site
diff core/modules/contextual/js/contextual.js @ 17:129ea1e6d783
Update, including to Drupal core 8.6.10
author | Chris Cannam |
---|---|
date | Thu, 28 Feb 2019 13:21:36 +0000 |
parents | 1fec387a4317 |
children |
line wrap: on
line diff
--- a/core/modules/contextual/js/contextual.js Tue Jul 10 15:07:59 2018 +0100 +++ b/core/modules/contextual/js/contextual.js Thu Feb 28 13:21:36 2019 +0000 @@ -26,13 +26,36 @@ storage.setItem('Drupal.contextual.permissionsHash', permissionsHash); } + function adjustIfNestedAndOverlapping($contextual) { + var $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; + if (firstTop === secondTop) { + var $nestedContextual = $contextuals.eq(1); + + var height = 0; + var $trigger = $nestedContextual.find('.trigger'); + + $trigger.removeClass('visually-hidden'); + height = $nestedContextual.height(); + $trigger.addClass('visually-hidden'); + + $nestedContextual.css({ top: $nestedContextual.position().top + height }); + } + } + function initContextual($contextual, html) { var $region = $contextual.closest('.contextual-region'); var contextual = Drupal.contextual; $contextual.html(html).addClass('contextual').prepend(Drupal.theme('contextualTrigger')); - var destination = 'destination=' + Drupal.encodePath(drupalSettings.path.currentPath); + var 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 ? '?' : '&'; @@ -61,29 +84,6 @@ adjustIfNestedAndOverlapping($contextual); } - function adjustIfNestedAndOverlapping($contextual) { - var $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; - if (firstTop === secondTop) { - var $nestedContextual = $contextuals.eq(1); - - var height = 0; - var $trigger = $nestedContextual.find('.trigger'); - - $trigger.removeClass('visually-hidden'); - height = $nestedContextual.height(); - $trigger.addClass('visually-hidden'); - - $nestedContextual.css({ top: $nestedContextual.position().top + height }); - } - } - Drupal.behaviors.contextual = { attach: function attach(context) { var $context = $(context); @@ -95,25 +95,31 @@ var ids = []; $placeholders.each(function () { - ids.push($(this).attr('data-contextual-id')); + ids.push({ + id: $(this).attr('data-contextual-id'), + token: $(this).attr('data-contextual-token') + }); }); - var uncachedIDs = _.filter(ids, function (contextualID) { - var html = storage.getItem('Drupal.contextual.' + contextualID); + var uncachedIDs = []; + var uncachedTokens = []; + ids.forEach(function (contextualID) { + var html = storage.getItem('Drupal.contextual.' + contextualID.id); if (html && html.length) { window.setTimeout(function () { - initContextual($context.find('[data-contextual-id="' + contextualID + '"]'), html); + initContextual($context.find('[data-contextual-id="' + contextualID.id + '"]'), html); }); - return false; + return; } - return true; + uncachedIDs.push(contextualID.id); + uncachedTokens.push(contextualID.token); }); if (uncachedIDs.length > 0) { $.ajax({ url: Drupal.url('contextual/render'), type: 'POST', - data: { 'ids[]': uncachedIDs }, + data: { 'ids[]': uncachedIDs, 'tokens[]': uncachedTokens }, dataType: 'json', success: function success(results) { _.each(results, function (html, contextualID) { @@ -139,7 +145,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>';