summaryrefslogtreecommitdiffstatshomepage
path: root/core/misc/ajax.es6.js
diff options
context:
space:
mode:
authorwebchick <drupal@webchick.net>2017-10-16 18:15:27 -0400
committerwebchick <drupal@webchick.net>2017-10-16 18:15:27 -0400
commit18f322a212d777e4f2c364fd8cc7ecfe442cf24c (patch)
treec4e632f0fd8efd7d95159e586e2f56ff2dc64309 /core/misc/ajax.es6.js
parentfd8d98399a69ba243679fc8ecc1d8bf221c18530 (diff)
downloaddrupal-18f322a212d777e4f2c364fd8cc7ecfe442cf24c.tar.gz
drupal-18f322a212d777e4f2c364fd8cc7ecfe442cf24c.zip
Issue #2764931 by tedbow, tim.plunkett, nod_, drpal, droplet, dawehner, Wim Leers, phenaproxima: Contextual links don't work with 'use-ajax' links
Diffstat (limited to 'core/misc/ajax.es6.js')
-rw-r--r--core/misc/ajax.es6.js55
1 files changed, 35 insertions, 20 deletions
diff --git a/core/misc/ajax.es6.js b/core/misc/ajax.es6.js
index 2e6fa91d77cf..7d7484e3759e 100644
--- a/core/misc/ajax.es6.js
+++ b/core/misc/ajax.es6.js
@@ -46,26 +46,7 @@
}
}
- // Bind Ajax behaviors to all items showing the class.
- $('.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');
- if (href) {
- element_settings.url = href;
- element_settings.event = 'click';
- }
- element_settings.dialogType = $(this).data('dialog-type');
- element_settings.dialogRenderer = $(this).data('dialog-renderer');
- element_settings.dialog = $(this).data('dialog-options');
- element_settings.base = $(this).attr('id');
- element_settings.element = this;
- Drupal.ajax(element_settings);
- });
+ Drupal.ajax.bindAjaxLinks(document.body);
// This class means to submit the form to the action using Ajax.
$('.use-ajax-submit').once('ajax').each(function () {
@@ -269,6 +250,39 @@
};
/**
+ * Bind Ajax functionality to links that use the 'use-ajax' class.
+ *
+ * @param {HTMLElement} 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((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'),
+ dialogRenderer: $linkElement.data('dialog-renderer'),
+ 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) {
+ elementSettings.url = href;
+ elementSettings.event = 'click';
+ }
+ Drupal.ajax(elementSettings);
+ });
+ };
+
+ /**
* Settings for an Ajax object.
*
* @typedef {object} Drupal.Ajax~element_settings
@@ -1340,4 +1354,5 @@
}
},
};
+
}(jQuery, window, Drupal, drupalSettings));