reverted: --- b/core/misc/ajax.js +++ a/core/misc/ajax.js @@ -50,7 +50,25 @@ } } + // Bind Ajax behaviors to all items showing the class. + $('.use-ajax').once('ajax').each(function () { + var element_settings = {}; + // Clicked links look better with the throbber than the progress bar. + element_settings.progress = {type: 'throbber'}; + + // For anchor tags, these will go to the target of the anchor rather + // than the usual location. + var href = $(this).attr('href'); + if (href) { + element_settings.url = href; + element_settings.event = 'click'; + } + element_settings.dialogType = $(this).data('dialog-type'); + element_settings.dialog = $(this).data('dialog-options'); + element_settings.base = $(this).attr('id'); + element_settings.element = this; + Drupal.ajax(element_settings); + }); - Drupal.ajax.bindAjaxLinks($(window)); // This class means to submit the form to the action using Ajax. $('.use-ajax-submit').once('ajax').each(function () { @@ -259,34 +277,6 @@ }; /** - * Bind Ajax functionality to links that use the 'use-ajax' class. - * - * @param $element - * Element to enable Ajax functionality for. - */ - Drupal.ajax.bindAjaxLinks = function ($element) { - // Bind Ajax behaviors to all items showing the class. - $element.find('.use-ajax').once('ajax').each(function () { - var element_settings = {}; - // Clicked links look better with the throbber than the progress bar. - element_settings.progress = {type: 'throbber'}; - - // For anchor tags, these will go to the target of the anchor rather - // than the usual location. - var href = $(this).attr('href'); - if (href) { - element_settings.url = href; - element_settings.event = 'click'; - } - element_settings.dialogType = $(this).data('dialog-type'); - element_settings.dialog = $(this).data('dialog-options'); - element_settings.base = $(this).attr('id'); - element_settings.element = this; - Drupal.ajax(element_settings); - }); - }; - - /** * Settings for an Ajax object. * * @typedef {object} Drupal.Ajax~element_settings diff -u b/core/modules/contextual/js/contextual.js b/core/modules/contextual/js/contextual.js --- b/core/modules/contextual/js/contextual.js +++ b/core/modules/contextual/js/contextual.js @@ -81,9 +81,6 @@ // trigger the model change event handler in its views. contextual.collection.add(model); - // Enable Ajax functionality for contextual links. - Drupal.ajax.bindAjaxLinks($region); - // Let other JavaScript react to the adding of a new contextual link. $(document).trigger('drupalContextualLinkAdded', { $el: $contextual, @@ -212,6 +209,12 @@ } }); } + + + // Let other JavaScript react to the adding of a new contextual link. + $(document).once('contextual-ajax').on('drupalContextualLinkAdded', function (event, data) { + Drupal.attachBehaviors(data.$el[0]); + }); } }; diff -u b/core/modules/contextual/tests/modules/contextual_ajax_test/contextual_ajax_test.module b/core/modules/contextual/tests/modules/contextual_ajax_test/contextual_ajax_test.module --- b/core/modules/contextual/tests/modules/contextual_ajax_test/contextual_ajax_test.module +++ b/core/modules/contextual/tests/modules/contextual_ajax_test/contextual_ajax_test.module @@ -11,7 +11,6 @@ * Change Configure Blocks into modal links. */ function contextual_ajax_test_contextual_links_view_alter(&$element, $items) { - drupal_set_message('fffff'); if (isset($element['#links']['contextual-ajax-test'])) { $element['#links']['contextual-ajax-test']['attributes'] = [ 'class' => ['use-ajax'],