`; listingsContainer.insertAdjacentHTML('afterend', btnHtml); } else { const btn = document.getElementById('load-more-btn'); btn.setAttribute('data-next-page', data.next_page); btn.disabled = false; btn.textContent = 'Load More'; } } else { const wrapper = document.getElementById('load-more-wrapper'); if (wrapper) wrapper.remove(); } }); } document.addEventListener('click', function (e) { if (e.target && e.target.id === 'load-more-btn') { const btn = e.target; const page = btn.getAttribute('data-next-page'); const keyword = searchInput ? searchInput.value : ''; btn.disabled = true; btn.textContent = 'Loading...'; fetchListings(page, keyword); } }); }); $(document).ready(function () { $('body').on('click', '.sort-add, .sort-remove', function() { var listing_id = $(this).data('listing-id'); var $button = $(this); if ($button.hasClass('sort-add')) { setCookies("listing_cookie_" + listing_id, listing_id, 10); showNotification('Alert', 'Listing Save Successfully...!!!', 'success'); $button.addClass('sort-remove').removeClass('sort-add').html(''); } else { setCookies("listing_cookie_" + listing_id, listing_id, 0); showNotification('Alert', 'Listing UnSaved Successfully...!!!', 'error'); $button.addClass('sort-add').removeClass('sort-remove').html(''); } }); let selectedItem = null; $("#home-search").autocomplete({ minLength: 2, source: function (request, response) { const param2 = $("#search_listing_locations").val(); $.ajax({ url: "common-autocomplete", data: { term: request.term, param2 }, success: function (data) { const grouped = {}; data.forEach(item => { (grouped[item.group] = grouped[item.group] || []).push(item); }); const list = []; Object.keys(grouped).forEach(g => { list.push({ groupHeader: true, label: g }); list.push(...grouped[g]); }); response(list); }, error: () => response([]) }); }, focus: function (event, ui) { if (!ui.item.groupHeader) { $("#home-search").val(ui.item.label_no_highlight); } return false; }, select: function (event, ui) { if (ui.item.groupHeader) return false; $("#home-search").val(ui.item.label_no_highlight); selectedItem = ui.item; const badge = selectedItem.badge; let url = ""; if (badge === "Region") { url = `https://www.nurseriesandschools.org/search_result/searchregion/${selectedItem.slug}`; } else if (badge === "County") { url = `https://www.nurseriesandschools.org/search_result/searchcounty/${selectedItem.slug}`; } else if (badge === "Town") { url = `https://www.nurseriesandschools.org/search_result/searchlocation/${selectedItem.slug}`; } else if (badge === "Postcode" || badge === "Postcode Area") { url = `https://www.nurseriesandschools.org/search_result/searchpostcode/${selectedItem.slug}`; } else { const pathMap = { "childminder": "nannies/", "tutor": "tutors/", "company": "business/", "college-university": "college-university/", "special-needs": "special-need/", "sports": "sport/", "camps": "camp/", "things-to-do": "family-day-out-listing/", "club": "club/", "maternity": "maternity/" }; const path = pathMap[selectedItem.type] || "listing/"; url = `https://www.nurseriesandschools.org/${path}${selectedItem.slug}`; } $('#SearchButtonOne').prop('disabled', true).text('Please wait...'); $('#loadingSpinner, #loadingOverlay').show(); setTimeout(() => window.location.href = url, 300); return false; } }) .autocomplete("instance")._renderItem = function (ul, item) { if (item.groupHeader) { return $("
  • ") .text(item.label) .appendTo(ul); } const term = this.term; const regex = new RegExp(`(${term})`, "gi"); const mark = txt => (txt || "").replace(regex, "$1"); return $(`
  • ${mark(item.label)}
    ${item.desc}
    ${item.badge || ""}
  • `).appendTo(ul); }; $("#searchForm").on("submit", function (e) { const term = $("#home-search").val().trim(); e.preventDefault(); if (selectedItem && selectedItem.slug) { return false; } fetch(`/nurseriesandschools.org/search-term-type?term=${encodeURIComponent(term)}`) .then(res => res.json()) .then(data => { const slug = term.replace(/\s+/g, ''); let url = ''; if (data.type === 'postcode') { url = `https://www.nurseriesandschools.org/search_result/searchpostcode/${slug}`; } else if (data.type === 'location') { url = `https://www.nurseriesandschools.org/search_result/searchlocation/${slug}`; } else { showNotification("No data found. Please search properly.", 'error', 7500, 'top'); return; } $('#SearchButtonOne').prop('disabled', true).text('Please wait...'); $('#loadingSpinner, #loadingOverlay').show(); setTimeout(() => window.location.href = url, 300); }) .catch(() => this.submit()); // normal submit if API fails }); }); function setCookies(cname, cvalue, exdays) { var d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); var expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } document.addEventListener("DOMContentLoaded", function () { const rotateAllBanners = (containerIds, interval = 100) => { containerIds.forEach(containerId => { const container = document.getElementById(containerId); if (!container) return; const images = container.getElementsByClassName('banner-img'); if (images.length === 0) return; let current = 0; setInterval(() => { images[current].style.display = 'none'; current = (current + 1) % images.length; images[current].style.display = 'block'; }, interval); }); }; // List of all banner container IDs const bannerContainers = [ 'position_one_banner', ]; rotateAllBanners(bannerContainers, 1500); });