1jQuery(document).ready(function ($) { 2 $(".peoples-filter").show(); 3 4 // When true, we are changing filter UI values programmatically and should not 5 // re-trigger "reset other filters" logic. 6 var isResettingOtherFilters = false; 7 8 // Unified filter function that handles all filters via AJAX 9 function filterAllPeople() { 10 var category = $("#artcloud-select").length ? $("#artcloud-select").val() || "*" : "*"; 11 var province = $("#artcloud-province-select").length ? $("#artcloud-province-select").val() || "*" : "*"; 12 var city = $("#artcloud-city-select").length ? $("#artcloud-city-select").val() || "*" : "*"; 13 var searchTerm = $("#peopleSearch").length ? $("#peopleSearch").val() || "" : ""; 14 // Get parent category ID from either category select or province select 15 var parentCategoryId = $("#artcloud-select").data("parent-category-id") || 16 ($("#artcloud-province-select").length ? $("#artcloud-province-select").data("category-id") : 0) || 0; 17 18 // Show loading state if needed 19 $(".peoples-filter").addClass("filtering"); 20 21 // Get AJAX URL 22 var ajaxUrl = (typeof artcloudPeopleAjax !== "undefined" && artcloudPeopleAjax.ajaxurl) 23 ? artcloudPeopleAjax.ajaxurl 24 : (typeof ajaxurl !== "undefined" ? ajaxurl : "/wp-admin/admin-ajax.php"); 25 26 // Make AJAX call 27 $.ajax({ 28 url: ajaxUrl, 29 type: "POST", 30 data: { 31 action: "filter_people_by_all", 32 category: category, 33 province: province, 34 city: city, 35 search: searchTerm, 36 parent_category_id: parentCategoryId, 37 }, 38 success: function (response) { 39 if (response.success && response.data && response.data.post_ids) { 40 var allowedPostIds = response.data.post_ids; 41 // Convert to numbers for comparison and create a Set for faster lookup 42 var allowedPostIdsSet = new Set(); 43 allowedPostIds.forEach(function(id) { 44 allowedPostIdsSet.add(parseInt(id)); 45 }); 46 47 // First, show all people columns to reset any previous filters 48 $(".arcloud-people-column").show(); 49 $(".peoples-filter").show(); 50 51 // Then hide all people columns 52 $(".arcloud-people-column").hide(); 53 54 // Show only matching people - check all items, not just visible ones 55 $(".artcloud-peoples-item").each(function () { 56 var $item = $(this); 57 var personIdAttr = $item.attr("person-id"); 58 if (personIdAttr) { 59 var personId = parseInt(personIdAttr); 60 if (!isNaN(personId) && allowedPostIdsSet.has(personId)) { 61 var $column = $item.closest(".arcloud-people-column"); 62 $column.show(); 63 } 64 } 65 }); 66 67 // Show/hide parent filter divs based on visible children 68 $(".peoples-filter").each(function () { 69 var $parentDiv = $(this); 70 var hasVisible = $parentDiv.find(".arcloud-people-column:visible").length > 0; 71 if (hasVisible) { 72 $parentDiv.show(); 73 } else { 74 $parentDiv.hide(); 75 } 76 }); 77 } else { 78 // If no filter or error, show all 79 $(".arcloud-people-column").show(); 80 $(".peoples-filter").show(); 81 } 82 $(".peoples-filter").removeClass("filtering"); 83 }, 84 error: function (xhr, status, error) { 85 console.error("AJAX Error:", status, error); 86 // On error, show all 87 $(".arcloud-people-column").show(); 88 $(".peoples-filter").show(); 89 $(".peoples-filter").removeClass("filtering"); 90 }, 91 }); 92 } 93 94 function setTabActiveById(categoryId) { 95 var $tabs = $(".artcloud-tabView .artcloud-tabItem"); 96 if (!$tabs.length) return; 97 $tabs.removeClass("active"); 98 $tabs.filter('[data-id="' + categoryId + '"]').addClass("active"); 99 } 100 101 // Populate city dropdown options based on province (or all cities if province is "*"). 102 function populateCityDropdown(selectedProvince, selectedCity) { 103 var $citySelect = $("#artcloud-city-select"); 104 if (!$citySelect.length) return; 105 106 // Clear and reset city dropdown (keep first option) 107 $citySelect.find("option:not(:first)").remove(); 108 109 var cities = []; 110 if ( 111 selectedProvince && 112 selectedProvince !== "*" && 113 locationData.cities_by_province && 114 locationData.cities_by_province[selectedProvince] 115 ) { 116 cities = locationData.cities_by_province[selectedProvince]; 117 } else if (locationData.all_cities) { 118 cities = locationData.all_cities; 119 } 120
121 cities.forEach(function (city) { 122 $citySelect.append('<option value="' + city + '">' + city + "</option>"); 123 }); 124 125 if (typeof selectedCity !== "undefined") { 126 $citySelect.val(selectedCity); 127 } 128 } 129 130 // Make the *last* used filter the only active one by resetting the others. 131 // active: "category" | "province" | "city" | "search" 132 function resetOtherFilters(active, options) { 133 options = options || {}; 134 135 var $category = $("#artcloud-select"); 136 var $province = $("#artcloud-province-select"); 137 var $city = $("#artcloud-city-select"); 138 var $search = $("#peopleSearch"); 139 140 isResettingOtherFilters = true; 141 142 if (active !== "category" && $category.length) { 143 $category.val("*"); 144 setTabActiveById("*"); 145 } 146 147 if (active !== "province" && $province.length) { 148 $province.val("*"); 149 } 150 151 if (active !== "search" && $search.length) { 152 $search.val(""); 153 } 154 155 // City dropdown depends on province, so rebuild options based on the active filter. 156 if ($city.length) { 157 if (active === "province") { 158 // Province is active: show cities for that province, and reset city to "*". 159 populateCityDropdown($province.length ? $province.val() : "*", "*"); 160 } else if (active === "city") { 161 // City is active: remove province as an active filter, but keep the selected city. 162 if ($province.length) $province.val("*"); 163 populateCityDropdown("*", options.keepCity || "*"); 164 } else { 165 // Category or search is active: reset location filters fully. 166 populateCityDropdown("*", "*"); 167 } 168 } 169 170 isResettingOtherFilters = false; 171 } 172 173 // Category dropdown change - use AJAX 174 $("#artcloud-select").change(function () { 175 if (isResettingOtherFilters) return; 176 setTabActiveById($(this).val() || "*"); 177 resetOtherFilters("category"); 178 filterAllPeople(); 179 }); 180 181 // Tab view click - use AJAX 182 $(".artcloud-tabView li").on("click", function (e) { 183 e.preventDefault(); 184 var selectedCategory = $(this).find(".artcloud-tabItem").data("id"); 185 $(this).siblings().find(".artcloud-tabItem").removeClass("active"); 186 $(this).find(".artcloud-tabItem").addClass("active"); 187 188 // Update the select dropdown to match 189 $("#artcloud-select").val(selectedCategory); 190 191 if (!isResettingOtherFilters) { 192 resetOtherFilters("category"); 193 } 194 195 // Filter via AJAX 196 filterAllPeople(); 197 }); 198 199 // Search button - use AJAX 200 $("#peopleSearchButton").on("click", function (e) { 201 e.preventDefault(); // Prevent default form submission 202 if (isResettingOtherFilters) return; 203 resetOtherFilters("search"); 204 filterAllPeople(); 205 }); 206 207 // Search input - trigger on Enter key 208 $("#peopleSearch").on("keypress", function (e) { 209 if (e.which === 13) { // Enter key 210 e.preventDefault(); 211 if (isResettingOtherFilters) return; 212 resetOtherFilters("search"); 213 filterAllPeople(); 214 } 215 }); 216 217 // Province and City dropdown filtering 218 var locationData = { 219 cities_by_province: {}, 220 all_cities: [] 221 }; 222 var $citiesDataScript = $("#cities-by-province-data"); 223 if ($citiesDataScript.length) { 224 try { 225 locationData = JSON.parse($citiesDataScript.text()); 226 } catch (e) { 227 console.error("Error parsing cities by province data:", e); 228 } 229 } 230 231 // Handle province dropdown change - update city dropdown 232 $(document).on("change", "#artcloud-province-select", function () { 233 if (isResettingOtherFilters) return; 234 resetOtherFilters("province"); 235 236 // Trigger unified filter 237 filterAllPeople(); 238 }); 239 240 // Handle city dropdown change 241 $(document).on("change", "#artcloud-city-select", function () { 242 if (isResettingOtherFilters) return; 243 var selectedCity = $(this).val() || "*"; 244 resetOtherFilters("city", { keepCity: selectedCity }); 245 filterAllPeople(); 246 }); 247 248}); 249
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.