1jQuery(document).ready(function ($) { 2 // Check if ajax_object is defined 3 if (typeof ajax_object === 'undefined') { 4 console.error('YMCA Camps: ajax_object is not defined. Ensure wp_localize_script is working.'); 5 return; 6 } 7 8 // Function to scroll to #filter_age_date 9 function scrollToFilter() { 10 if (window.location.search.includes("age_group") || window.location.search.includes("date_group")) { 11 setTimeout(function () { 12 let target = $("#filter_age_date"); 13 if (target.length) { 14 $('html, body').animate({ 15 scrollTop: target.offset().top 16 }, 1000); 17 } 18 }, 500); 19 } 20 } 21 22 // Function to load camps via AJAX 23 function loadCamps(e) { 24 let parentBox = $(e.target).closest('.ymca-camp-main-box'); 25 let campID = parentBox.data('id'); 26 console.log(campID); 27 28 var age_group = $('.age_group').val() || ''; 29 var date_group = $('.dates').val() || ''; 30 var view_all = $('input[name="view_all_camps"]:checked').val() || ''; 31 var reset = $('input[name="reset"]:checked').val() || ''; 32 33 $.ajax({ 34 type: 'POST', 35 url: ajax_object.ajaxurl, 36 data: { 37 action: 'load_camps_filter', 38 camp_id: campID, 39 age_group: age_group, 40 date_group: date_group, 41 view_all: view_all, 42 reset: reset, 43 nonce: ajax_object.nonce // Include nonce 44 }, 45 beforeSend: function () { 46 $('.camp-acord').html('<p class="camp-loading-result">Loading camps...</p>'); 47 }, 48 success: function (response) { 49 console.log('YMCA Camps: AJAX success', response); 50 $('.camp-acord').html(response); 51 // Re-bind accordion events after AJAX load (includes link prevention) 52 bindAccordionEvents(); 53 }, 54 error: function (xhr, status, error) { 55 console.error('YMCA Camps: AJAX error', error); 56 $('.camp-acord').html('<p class="camp-error">Error loading camps. Please try again.</p>'); 57 } 58 }); 59 } 60 61 // Function to prevent accordion toggle when clicking links 62 function preventAccordionOnLinks() { 63 document.querySelectorAll(".accordion a").forEach(function(link) { 64 link.addEventListener("click", function(e) { 65 e.stopPropagation(); 66 }); 67 }); 68 } 69 70 // Function to bind accordion events 71 function bindAccordionEvents() { 72 // Mark first accordion as active (panel already shown via PHP/CSS) 73 $('.accordion').first().addClass('active'); 74 75 // Prevent accordion toggle when clicking links 76 preventAccordionOnLinks(); 77 78 $('.accordion').off('click').on('click', function (e) { 79 e.preventDefault(); 80 let $panel = $(this).next('.panel'); 81 if ($panel.is(':visible')) { 82 $panel.slideUp().removeClass('active'); 83 $(this).removeClass('active'); 84 } else { 85 $('.panel').slideUp().removeClass('active'); 86 $('.accordion').removeClass('active'); 87 $panel.slideDown().addClass('active'); 88 $(this).addClass('active'); 89 } 90 }); 91 } 92 93 // Initialize 94 scrollToFilter(); 95 bindAccordionEvents(); 96 97 // Event handlers 98 $('#rest-view, #view-all-filter').on('change', function (e) { 99 $('.age_group').val(''); 100 $('.dates').val(''); 101 loadCamps(e); 102 }); 103 104 $('.btn-submit').on('click', function (e) { 105 e.preventDefault(); 106 loadCamps(e); 107 }); 108 109 $('.bredcamp-dropdown-list ul li:last').on('click', function () { 110 $('.resources-dropdown-main').toggle(); 111 if ($('.resources-dropdown-main').is(':visible')) { 112 $(this).addClass('active'); 113 } else { 114 $(this).removeClass('active'); 115 } 116 }); 117}); 118 119// Prevent accordion expansion when clicking links (vanilla JS for better compatibility) 120document.addEventListener("DOMContentLoaded", function() { 121 document.querySelectorAll(".accordion a").forEach(function(link) { 122 link.addEventListener("click", function(e) { 123 e.stopPropagation(); 124 }); 125 }); 126});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.