There have been a couple instances recently where I wanted to fire some custom handlers when particular events in ajax.js were invoked. It's possible I'm a bit off track with this and there may be an alternate solution, as admittedly jQuery is not my strongest language.
To give an example, suppose you wanted to manipulate a page element when Drupal.ajax.prototype.beforeSend is called. Up to this point, I would handle this by adding something along these lines in a custom .js file:
(function ($) {
// Drupal's core beforeSend function
var beforeSend = Drupal.ajax.prototype.beforeSend;
// Add a trigger when beforeSend fires.
Drupal.ajax.prototype.beforeSend = function(xmlhttprequest, options) {
beforeSend.call(this, xmlhttprequest, options);
$(document).trigger('beforeSend');
}
})(jQuery);
Then, use $(document).bind('beforeSend', ...);
where necessary.
A use case could be when exposed filters on an ajax-enabled view are submitted, you want to fade the view-content before it's replaced.
What I am proposing is possibly adding these triggers directly in ajax.js
Comments
Comment #1
nod_Interesting, worth looking into.
Comment #2
nod_See here for new stuff in ajax.js #1533366: Simplify and optimize Drupal.ajax() instantiation and implementation
Comment #3
ramkumar28b CreditAttribution: ramkumar28b commentedI want to fire an ajax call, when textfield characters equal to 8. Can anyone help me how to use the above code in my scenario, since i am new to drupal 8.