How to detect Drupal (8) views ajax call start (with JS only)

1.4k views Asked by At

I'm trying to do some custom UI tweaks while a view is being reloaded with ajax. I can find ways to trigger events when the ajaxcall is complete but I can't seem to find something similar for when the ajaxcall is started.

The view gets updated with multiple facet blocks and text search so it would be great to be able to trigger my custom behavior by checking for a single event no matter what element is triggering the ajaxcall.

1

There are 1 answers

0
danielarend On

I think you are looking for drupal behaviors.

Drupal.behaviors.myBehavior = {
  attach: function (context, settings) {
   //this will run on every drupal ajax call or page load.
   console.log(context);
  }
};

Check the api:

https://www.drupal.org/docs/8/api/javascript-api/javascript-api-overview