Views provides custom events you can use to trigger your custom JavaScript code. This allows your custom JavaScript code to work even after Custom Search or Pagination results are updated using AJAX.
If you add code to an element using the document.ready jQuery method this code will stop working when a View is updated via AJAX through custom searches or pagination. This is why you need to reattach it to your page.
You can use Frontend events in combination with the code you put into the Loop Wizard JS editor or the one loaded from external JavaScript file, for example.
To preserve your JavaScript code from getting lost you have to do the following:
- Expand the JS editor (below the main Search and Pagination editor).
- Click the Frontend events button as shown in the following image.
- The Insert Views frontend event handler dialog appears. You can select events that belong to one of the following features:
- Pagination
- Custom search
- Google Maps (available only when Toolset Maps plugin is active)
Select events you want to insert the code for and click the Insert event trigger button.
That’s it! Now, you can add your custom JavaScript callbacks to the code that Views inserted into the JS editor.