diff --git a/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js index a843a9a687d47ed6aad2dd3ae0ed89ec3ed07155..b01b07f406b20a4241dfd38abd8d378cf7cb69d7 100644 --- a/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -41,7 +41,7 @@ * @param string html * The server-side rendered HTML for this contextual link. */ - function initContextual($contextual, html) { + function initContextual ($contextual, html) { var $region = $contextual.closest('.contextual-region'); var contextual = Drupal.contextual; @@ -101,7 +101,7 @@ * A contextual links placeholder DOM element, containing the actual * contextual links as rendered by the server. */ - function adjustIfNestedAndOverlapping($contextual) { + function adjustIfNestedAndOverlapping ($contextual) { var $contextuals = $contextual // @todo confirm that .closest() is not sufficient .parents('.contextual-region').eq(-1) @@ -156,10 +156,17 @@ }); // Update all contextual links placeholders whose HTML is cached. - var uncachedIDs = _.filter(ids, function initIfCached(contextualID) { + var uncachedIDs = _.filter(ids, function initIfCached (contextualID) { var html = storage.getItem('Drupal.contextual.' + contextualID); if (html !== null) { - initContextual($context.find('[data-contextual-id="' + contextualID + '"]'), html); + // Initialize after the current executation cycle, to make the AJAX + // request for retrieving the uncached contextual links as soon as + // possible, but also to ensure that other Drupal behaviors have had the + // chance to set up an event listener on the Backbone collection + // Drupal.contextual.collection. + window.setTimeout(function () { + initContextual($context.find('[data-contextual-id="' + contextualID + '"]'), html); + }); return false; } return true;