Skip to content
Showing 802–810 of 1,474 results
(function($) {
$(document).ready(function() {
// --- IMPORTANT: Ensure RTCL's JS is recognized as active ---
// The presence of 'rtcl-no-js' indicates a potential issue with RTCL's core JS loading.
// We'll try to manually correct this, though ideally RTCL should manage this itself.
if ($('body').hasClass('rtcl-no-js')) {
$('body').removeClass('rtcl-no-js').addClass('rtcl-js');
console.warn("Get FDat: Manually removed 'rtcl-no-js' and added 'rtcl-js' to the body. Please check for underlying RTCL JavaScript loading issues if problems persist.");
}
// Selectors for the main search form and its elements
// Based on the 'all-ads' HTML structure
const mainSearchForm = $('form.rtcl-widget-search-form');
const locationInput = mainSearchForm.find('#rtc-geo-search');
const categorySelect = mainSearchForm.find('select.rtcl-category-search[name="rtcl_category"]');
const subcategorySelect = mainSearchForm.find('.rtcl-child-terms select.rtcl-category-search');
const searchButton = mainSearchForm.find('.rtin-search-btn, .rtcl-btn');
const filterApplyButton = $('.rtcl-filter-form .rtcl-filter-btn'); // Selector for the "Apply filters" button in the sidebar
// Function to trigger the loading state
function startLoadingState() {
// Add the 'searching' class to the body
document.body.classList.add('searching');
// Disable search button and inputs to prevent further interaction
searchButton.prop('disabled', true).addClass('loading');
locationInput.prop('disabled', true);
categorySelect.prop('disabled', true);
subcategorySelect.prop('disabled', true);
filterApplyButton.prop('disabled', true).addClass('loading'); // Disable apply filters button
console.log("Get FDat: Loading state started. 'searching' class added.");
}
// Function to end the loading state
function endLoadingState() {
// Remove the 'searching' class from the body
document.body.classList.remove('searching');
// Re-enable search button and inputs
searchButton.prop('disabled', false).removeClass('loading');
locationInput.prop('disabled', false);
categorySelect.prop('disabled', false);
subcategorySelect.prop('disabled', false);
filterApplyButton.prop('disabled', false).removeClass('loading'); // Re-enable apply filters button
console.log("Get FDat: Loading state ended. 'searching' class removed.");
}
// --- Event Listeners for the main search form ---
// Handle explicit form submission (e.g., clicking the "Search" button in the header)
if (mainSearchForm.length) {
mainSearchForm.on('submit', function(event) {
// Prevent default form submission to allow our loading state to show
// and to let RTCL's AJAX handler (if any) take over.
event.preventDefault();
startLoadingState();
// For RTCL, it often handles the actual AJAX submission after event.preventDefault()
// if its own JS is set up to intercept the submit.
// The global ajaxStart/ajaxStop handlers should pick it up.
});
}
// Handle changes in filter dropdowns (location, category, subcategory)
// We attach to the document to catch changes on dynamically loaded elements too.
$(document).on('change', '#rtc-geo-search, select.rtcl-category-search', function() {
startLoadingState();
// RTCL's own JS will likely trigger the AJAX search after this change.
// The global ajaxStop will then remove the loading state.
});
// Handle click on the "Apply filters" button in the sidebar
if (filterApplyButton.length) {
filterApplyButton.on('click', function(event) {
event.preventDefault(); // Prevent default button action if it's not already handled by RTCL
startLoadingState();
// If RTCL has its own click handler for this button that triggers AJAX,
// the global ajaxStart/ajaxStop will manage the loading state.
// If not, you might need to manually trigger RTCL's filter application here.
// For now, we assume RTCL's JS will handle the actual filtering.
});
}
// --- Global AJAX Event Handlers ---
// These will catch any jQuery AJAX requests initiated by RTCL or other plugins.
// This is the most reliable way to detect when RTCL's dynamic content loading starts and stops.
$(document).ajaxStart(function() {
// Only start loading state if not already active to prevent flickering
if (!document.body.classList.contains('searching')) {
startLoadingState();
}
}).ajaxStop(function() {
// Ensure all AJAX requests are truly finished before removing the loading state.
// A small delay can prevent flickering if one AJAX call finishes just before another starts.
setTimeout(function() {
// Double-check if 'searching' class is still present before removing,
// in case another AJAX call started during the timeout.
if (document.body.classList.contains('searching')) {
endLoadingState();
}
}, 500); // Increased delay to 500ms for better visibility of spinner
});
});
})(jQuery);