diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js index ebe1d2315b..b3cdaf214f 100644 --- a/core/misc/ajax.es6.js +++ b/core/misc/ajax.es6.js @@ -253,28 +253,32 @@ /** * Bind Ajax functionality to links that use the 'use-ajax' class. * - * @param $element + * @param {jQuery} $element * Element to enable Ajax functionality for. */ Drupal.ajax.bindAjaxLinks = ($element) => { // Bind Ajax behaviors to all items showing the class. - $element.find('.use-ajax').once('ajax').each(function () { - const 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. - const href = $(this).attr('href'); + $element.find('.use-ajax').once('ajax').each((i, ajaxLink) => { + const $linkElement = $(ajaxLink); + + const elementSettings = { + // Clicked links look better with the throbber than the progress bar. + progress: { type: 'throbber' }, + dialogType: $linkElement.data('dialog-type'), + dialog: $linkElement.data('dialog-options'), + base: $linkElement.attr('id'), + element: ajaxLink, + }; + const href = $linkElement.attr('href'); + /** + * For anchor tags, these will go to the target of the anchor rather + * than the usual location. + */ if (href) { - element_settings.url = href; - element_settings.event = 'click'; + elementSettings.url = href; + elementSettings.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(elementSettings); }); }; diff --git a/core/misc/ajax.js b/core/misc/ajax.js index 6a60e0d982..56e03b0076 100644 --- a/core/misc/ajax.js +++ b/core/misc/ajax.js @@ -124,21 +124,23 @@ function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr }; Drupal.ajax.bindAjaxLinks = function ($element) { - $element.find('.use-ajax').once('ajax').each(function () { - var element_settings = {}; + $element.find('.use-ajax').once('ajax').each(function (i, ajaxLink) { + var $linkElement = $(ajaxLink); + + var elementSettings = { + progress: { type: 'throbber' }, + dialogType: $linkElement.data('dialog-type'), + dialog: $linkElement.data('dialog-options'), + base: $linkElement.attr('id'), + element: ajaxLink + }; + var href = $linkElement.attr('href'); - element_settings.progress = { type: 'throbber' }; - - var href = $(this).attr('href'); if (href) { - element_settings.url = href; - element_settings.event = 'click'; + elementSettings.url = href; + elementSettings.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(elementSettings); }); }; diff --git a/core/modules/outside_in/js/outside_in.es6.js b/core/modules/outside_in/js/outside_in.es6.js index 1d7e8298b6..bf6a56895f 100644 --- a/core/modules/outside_in/js/outside_in.es6.js +++ b/core/modules/outside_in/js/outside_in.es6.js @@ -56,6 +56,10 @@ * @listens event:drupalContextualLinkAdded */ $(document).on('drupalContextualLinkAdded', (event, data) => { + /** + * When contextual links are add we need to set extra properties on the + * instances in Drupal.ajax.instances for them to work with Edit Mode. + */ prepareAjaxLinks(); // Bind a listener to all 'Quick edit' links for blocks