Skip to content
Showing 5,095–5,103 of 5,625 results
(function($) {
console.log("Get FDat: Custom JS script loaded.");
// Function to check if the 'searching' class is present on the body
function isSearchingActive() {
return document.body.classList.contains('searching');
}
// Function to trigger the loading state
function startLoadingState() {
if (!isSearchingActive()) {
document.body.classList.add('searching');
console.log("Get FDat: 'searching' class ADDED to body.");
// Re-check immediately if the class was added
if (isSearchingActive()) {
console.log("Get FDat: Confirmed 'searching' class is now active.");
} else {
console.error("Get FDat: FAILED to add 'searching' class to body. Check for CSS/JS conflicts.");
}
// Disable relevant buttons and inputs
$('form.rtcl-widget-search-form').find('.rtin-search-btn, .rtcl-btn').prop('disabled', true).addClass('loading');
$('form.rtcl-widget-search-form').find('#rtc-geo-search, select.rtcl-category-search').prop('disabled', true);
$('.rtcl-filter-form .rtcl-filter-btn').prop('disabled', true).addClass('loading');
$('.rtcl-filter-form').find('#rtc-geo-search, select.rtcl-category-search, input[type="radio"][name^="filters[ad_type]"]').prop('disabled', true);
$('#el_load_more').prop('disabled', true).addClass('loading');
console.log("Get FDat: Inputs and buttons disabled.");
} else {
console.log("Get FDat: Loading state already active, skipping start.");
}
}
// Function to end the loading state
function endLoadingState() {
if (isSearchingActive()) {
document.body.classList.remove('searching');
console.log("Get FDat: 'searching' class REMOVED from body.");
// Re-enable relevant buttons and inputs
$('form.rtcl-widget-search-form').find('.rtin-search-btn, .rtcl-btn').prop('disabled', false).removeClass('loading');
$('form.rtcl-widget-search-form').find('#rtc-geo-search, select.rtcl-category-search').prop('disabled', false);
$('.rtcl-filter-form .rtcl-filter-btn').prop('disabled', false).removeClass('loading');
$('.rtcl-filter-form').find('#rtc-geo-search, select.rtcl-category-search, input[type="radio"][name^="filters[ad_type]"]').prop('disabled', false);
$('#el_load_more').prop('disabled', false).removeClass('loading');
console.log("Get FDat: Inputs and buttons re-enabled.");
} else {
console.log("Get FDat: Loading state not active, no need to remove.");
}
}
// This function sets up all our event listeners
function setupEventListeners() {
// Selectors for the main search form and its elements (header)
const mainSearchForm = $('form.rtcl-widget-search-form');
const sidebarFilterForm = $('.rtcl-filter-form');
const filterApplyButton = sidebarFilterForm.find('.rtcl-filter-btn');
const loadMoreButton = $('#el_load_more');
console.log("Get FDat: Setting up event listeners. Element presence:", {
mainSearchFormFound: mainSearchForm.length > 0,
sidebarFilterFormFound: sidebarFilterForm.length > 0,
filterApplyButtonFound: filterApplyButton.length > 0,
loadMoreButtonFound: loadMoreButton.length > 0
});
// --- Event Listeners for the main search form (header) ---
if (mainSearchForm.length) {
mainSearchForm.on('submit', function(event) {
console.log("Get FDat: Main search form submitted event detected.");
event.preventDefault(); // Prevent default form submission
startLoadingState();
});
}
// --- Event Listeners for sidebar filter form ---
if (sidebarFilterForm.length) {
// Listen for submission of the sidebar filter form (e.g., by pressing Enter)
sidebarFilterForm.on('submit', function(event) {
console.log("Get FDat: Sidebar filter form submitted event detected.");
event.preventDefault(); // Prevent default form submission
startLoadingState();
});
// Listen for changes on filter inputs/selects within the sidebar form
// Using event delegation on the form itself for robustness
sidebarFilterForm.on('change', '#rtc-geo-search, select.rtcl-category-search, input[type="radio"][name^="filters[ad_type]"]', function() {
console.log("Get FDat: Sidebar filter input/select changed:", this.id || this.name || this.className);
startLoadingState();
// If RTCL doesn't auto-submit on change, you might need to trigger it here.
// For now, relying on ajaxStart/ajaxStop to catch RTCL's internal AJAX.
});
// Handle click on the "Apply filters" button in the sidebar
if (filterApplyButton.length) {
filterApplyButton.on('click', function(event) {
console.log("Get FDat: 'Apply filters' button clicked.");
event.preventDefault(); // Prevent default button action
startLoadingState();
// Manually trigger form submission if RTCL doesn't do it automatically on button click
$(this).closest('form').submit();
});
}
}
// --- Event Listener for "Load More" button ---
if (loadMoreButton.length) {
loadMoreButton.on('click', function() {
console.log("Get FDat: 'Load More' button clicked.");
startLoadingState();
});
}
// --- Global AJAX Event Handlers ---
// These will catch any jQuery AJAX requests initiated by RTCL or other plugins.
$(document).ajaxStart(function() {
console.log("Get FDat: jQuery AJAX started.");
// Only start loading state if not already active to prevent flickering
if (!document.body.classList.contains('searching')) {
startLoadingState();
}
}).ajaxStop(function() {
console.log("Get FDat: jQuery AJAX stopped.");
// 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() {
console.log("Get FDat: Checking loading state after AJAX stop delay.");
// 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
});
}
// --- Initial setup and RTCL JS check ---
// Use a MutationObserver to ensure RTCL's JS has initialized and removed 'rtcl-no-js'
// or to manually remove it if RTCL fails to.
const observer = new MutationObserver((mutationsList, observer) => {
for (const mutation of mutationsList) {
if (mutation.type === 'attributes' && mutation.attributeName === 'class') {
const body = document.body;
if (body.classList.contains('rtcl-no-js')) {
body.classList.remove('rtcl-no-js');
body.classList.add('rtcl-js');
console.warn("Get FDat: MutationObserver: Manually corrected 'rtcl-no-js' to 'rtcl-js'.");
}
if (body.classList.contains('rtcl-js')) {
console.log("Get FDat: MutationObserver: 'rtcl-js' class detected. Initializing event listeners.");
observer.disconnect(); // Disconnect observer once we've confirmed RTCL is ready
setupEventListeners();
return; // Exit to prevent multiple setups
}
}
}
});
// Start observing the body for class changes
observer.observe(document.body, { attributes: true });
// Fallback if rtcl-js is already present on DOMContentLoaded or if observer fails
if ($('body').hasClass('rtcl-js')) {
console.log("Get FDat: 'rtcl-js' class already present on DOM ready. Initializing event listeners.");
if (observer) observer.disconnect(); // Ensure observer is disconnected if already ready
setupEventListeners();
} else {
// Fallback if rtcl-js is never added by RTCL or our observer (e.g., RTCL JS completely failed)
// Give RTCL's own JS a bit more time to run before our fallback.
setTimeout(() => {
if (!$('body').hasClass('rtcl-js')) {
$('body').removeClass('rtcl-no-js').addClass('rtcl-js'); // Ensure rtcl-js is present for our CSS
console.warn("Get FDat: Fallback: 'rtcl-js' not detected after 2 seconds. Manually setting and initializing.");
if (observer) observer.disconnect();
setupEventListeners();
}
}, 2000); // Give RTCL's own JS 2 seconds to run
}
});
})(jQuery);