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 ? '?' : '&';
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);
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) {
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>';