Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Note: I am using JS_Injector to load the JS code..
The issue: I have found that I have to duplicate some piece of JS code in order to load it upon initial page load and upon submitting the exposed form button via AJAX within same view.
Like this:
(function ($) {
$(document).ready(function() {
// CODE HERE //
});
})(jQuery);
(function ($) {
$(document).ajaxComplete(function(e, xhr, settings) {
if (settings.url == Drupal.settings.basePath + "?q=views/ajax" || settings.url == Drupal.settings.basePath + "views/ajax" || settings.url == Drupal.settings.basePath + "?q=system/ajax" || settings.url == Drupal.settings.basePath + "system/ajax") {
// SAME CODE HERE //
}
});
})(jQuery);
Any better solution to avoid the replication ?!
Comments
Comment #1
W.M. CreditAttribution: W.M. commentedComment #2
MustangGB CreditAttribution: MustangGB commented