jQuery(document).ready(function() { function waitForAPIsToFinish(callback) { const interval = setInterval(function() { if (jQuery.active === 0) { // Check if no active API calls clearInterval(interval); // Stop checking callback(); // Execute the callback } }, 100); // Check every 100ms }
waitForAPIsToFinish(function() { jQuery("#event_calendar_filters_button").click();
});
// Attach click event to div#wpem-event-calendar-layout jQuery("div#wpem-event-calendar-layout").on("click", function () { console.log("div#wpem-event-calendar-layout clicked. Waiting for APIs to finish...");
// Wait for APIs to finish, then perform the click action waitForAPIsToFinish(function () { console.log("No active API calls. Clicking #event_calendar_filters_button..."); jQuery("#event_calendar_filters_button").click(); }); });
// Attach click event to a.reset jQuery("a.reset").on("click", function () { console.log("a.reset clicked. Waiting for APIs to finish...");
// Wait for APIs to finish, then perform the conditional click action waitForAPIsToFinish(function () { console.log("No active API calls. Checking for .wpem-active-layout...");
// Check if div#wpem-event-calendar-layout has class .wpem-active-layout setTimeout(function () { if (jQuery("div#wpem-event-calendar-layout").hasClass("wpem-active-layout")) { console.log("div#wpem-event-calendar-layout has .wpem-active-layout. Clicking #event_calendar_filters_button..."); jQuery("#event_calendar_filters_button").click(); } else { console.log("div#wpem-event-calendar-layout does not have .wpem-active-layout. No action taken."); } }, 1500); }); }); });