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

nod_’s picture

Version: 7.x-dev » 8.x-dev

Interesting, worth looking into.

nod_’s picture

Status: Active » Closed (duplicate)
ramkumar28b’s picture

Issue summary: View changes

I 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.