summaryrefslogtreecommitdiffstatshomepage
path: root/core/modules/contextual/js/contextual.js
diff options
context:
space:
mode:
Diffstat (limited to 'core/modules/contextual/js/contextual.js')
-rw-r--r--core/modules/contextual/js/contextual.js50
1 files changed, 26 insertions, 24 deletions
diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js
index 6264b74c2099..97a7453d3f62 100644
--- a/core/modules/contextual/js/contextual.js
+++ b/core/modules/contextual/js/contextual.js
@@ -12,9 +12,9 @@
close: Drupal.t('Close')
}
});
-
var cachedPermissionsHash = storage.getItem('Drupal.contextual.permissionsHash');
var permissionsHash = drupalSettings.user.permissionsHash;
+
if (cachedPermissionsHash !== permissionsHash) {
if (typeof permissionsHash === 'string') {
_.chain(storage).keys().each(function (key) {
@@ -23,6 +23,7 @@
}
});
}
+
storage.setItem('Drupal.contextual.permissionsHash', permissionsHash);
}
@@ -35,60 +36,60 @@
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 });
+ $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(Drupal.url(drupalSettings.path.currentPath));
+ var destination = "destination=".concat(Drupal.encodePath(Drupal.url(drupalSettings.path.currentPath)));
$contextual.find('.contextual-links a').each(function () {
var url = this.getAttribute('href');
var glue = url.indexOf('?') === -1 ? '?' : '&';
this.setAttribute('href', url + glue + destination);
});
-
var model = new contextual.StateModel({
title: $region.find('h2').eq(0).text().trim()
});
- var viewOptions = $.extend({ el: $contextual, model: model }, options);
+ var viewOptions = $.extend({
+ el: $contextual,
+ model: model
+ }, options);
contextual.views.push({
visual: new contextual.VisualView(viewOptions),
aural: new contextual.AuralView(viewOptions),
keyboard: new contextual.KeyboardView(viewOptions)
});
- contextual.regionViews.push(new contextual.RegionView($.extend({ el: $region, model: model }, options)));
-
+ contextual.regionViews.push(new contextual.RegionView($.extend({
+ el: $region,
+ model: model
+ }, options)));
contextual.collection.add(model);
-
$(document).trigger('drupalContextualLinkAdded', {
$el: $contextual,
$region: $region,
model: model
});
-
adjustIfNestedAndOverlapping($contextual);
}
Drupal.behaviors.contextual = {
attach: function attach(context) {
var $context = $(context);
-
var $placeholders = $context.find('[data-contextual-id]').once('contextual-render');
+
if ($placeholders.length === 0) {
return;
}
@@ -100,17 +101,18 @@
token: $(this).attr('data-contextual-token')
});
});
-
var uncachedIDs = [];
var uncachedTokens = [];
ids.forEach(function (contextualID) {
- var html = storage.getItem('Drupal.contextual.' + contextualID.id);
+ var html = storage.getItem("Drupal.contextual.".concat(contextualID.id));
+
if (html && html.length) {
window.setTimeout(function () {
- initContextual($context.find('[data-contextual-id="' + contextualID.id + '"]'), html);
+ initContextual($context.find("[data-contextual-id=\"".concat(contextualID.id, "\"]")), html);
});
return;
}
+
uncachedIDs.push(contextualID.id);
uncachedTokens.push(contextualID.token);
});
@@ -119,14 +121,17 @@
$.ajax({
url: Drupal.url('contextual/render'),
type: 'POST',
- data: { 'ids[]': uncachedIDs, 'tokens[]': uncachedTokens },
+ data: {
+ 'ids[]': uncachedIDs,
+ 'tokens[]': uncachedTokens
+ },
dataType: 'json',
success: function success(results) {
_.each(results, function (html, contextualID) {
- storage.setItem('Drupal.contextual.' + contextualID, html);
+ storage.setItem("Drupal.contextual.".concat(contextualID), html);
if (html.length > 0) {
- $placeholders = $context.find('[data-contextual-id="' + contextualID + '"]');
+ $placeholders = $context.find("[data-contextual-id=\"".concat(contextualID, "\"]"));
for (var i = 0; i < $placeholders.length; i++) {
initContextual($placeholders.eq(i), html);
@@ -138,13 +143,10 @@
}
}
};
-
Drupal.contextual = {
views: [],
-
regionViews: []
};
-
Drupal.contextual.collection = new Backbone.Collection([], {
model: Drupal.contextual.StateModel
});