1const loader = 2 '<div class="loader-wrapper"><div class="lds-roller"><div></div><div></div><div></div><div></div><div></div><div></div><div></div><div></div></div></div>'; 3 4const wrapper = document.querySelector(".results .posts"); 5 6const country_usa = 'us'; 7 8const handleGrantedSheltersArchivePage = () => { 9 const shelters = _getAll(".granted_shelter"); 10 11 shelters.forEach((shelter) => { 12 const shelter_button = _get(".granted_shelter_button", shelter); 13 shelter_button.addEventListener("click", () => { 14 if (shelter_button.getAttribute("aria-expanded") === "false") { 15 shelter_button.setAttribute("aria-expanded", "true") 16 } else { 17 shelter_button.setAttribute("aria-expanded", "false") 18 } 19 20 const bottom = _get(".bottom", shelter); 21 shelter.classList.toggle("show"); 22 jQuery(bottom).slideToggle(200); 23 }); 24 }); 25 26 // helper function to update screen reader text with the number of current 27 // search results 28 function update_screen_reader_results_text(pageName) { 29 jQuery(`#${pageName}-live-results-count`).html(''); 30 31 var resultText = jQuery(`span.${pageName}-results-count`).text(); 32 33 if (resultText.charAt(0) === "0") { 34 resultText = "no results available"; 35 } 36 37 jQuery(`#${pageName}-live-results-count`).html(resultText); 38 39 setTimeout(function() { 40 jQuery(`#${pageName}-live-results-count`).html(''); 41 }, 100); 42 } 43 44 update_screen_reader_results_text('granted'); 45 update_screen_reader_results_text('resources'); 46 update_screen_reader_results_text('news'); 47}; 48 49handleGrantedSheltersArchivePage(); 50 51const handleSidebarSlideOut = (() => { 52 const triggers = Array.from( 53 document.querySelectorAll(".mobile-sidebar-trigger, .overlay") 54 ); 55 56 const sidebar = document.querySelector(".sidebar"); 57 const overlay = document.querySelector(".overlay"); 58 59 triggers.forEach((trigger) => { 60 trigger.addEventListener("click", (e) => { 61 e.preventDefault(); 62 63 if (sidebar.classList.contains("slide-left")) { 64 sidebar.classList.remove("slide-left"); 65 document.body.style.overflow = "hidden"; 66 overlay.classList.add("show"); 67 } else { 68 sidebar.classList.add("slide-left"); 69 document.body.style.overflow = "scroll"; 70 overlay.classList.remove("show"); 71 } 72 }); 73 }); 74})(); 75 76// Handling filter submission 77// - Serializes the text input fields from the form 78// - Creates a new URL removing the query string 79// - Adds new query string to URL 80// - Pushes new URL to the browser history 81// = Runs the query 82// - Handles filtering from page/2/ 83// - Handles multiple values for same key 84 85jQuery("#filter-form input, #filter-form select").change(function () { 86 wrapper.innerHTML = loader; 87 submitForm(); 88}); 89 90jQuery("#filter-form #s").keyup(function () { 91 wrapper.innerHTML = loader; 92 submitForm(); 93}); 94 95jQuery("#filter-form").submit(function (e) { 96 e.preventDefault(); 97 var data = jQuery("#filter-form").serializeArray(); 98 //console.log(data); 99 100 var queryIndex = window.location.href.indexOf("?"); 101 var href; 102 var url; 103 var isCountryEmpty = false; 104 if (queryIndex != -1) { 105 href = window.location.href.substring(0, queryIndex); 106 } else { 107 href = window.location.href; 108 } 109 110 // remove page number 111 href = href.replace(/page\/[0-9]+\//, ""); 112 113 url = new URL(href); 114 jQuery.each(data, function (i, val) { 115 116 if (val.value != "") { 117 if (!url.searchParams.get(val.name)) { 118 url.searchParams.set(val.name, val.value); 119 } else { 120 const lastValue = url.searchParams.get(val.name); 121 url.searchParams.set(val.name, `${lastValue},${val.value}`); 122 } 123 } 124 125 if(val.name === "granted_shelters-country" && val.value != country_usa) { 126 isCountryEmpty = true; 127 } 128 129 }); 130 131 // removes state search from non us countries 132 if(isCountryEmpty) { 133 url.searchParams.delete("granted_shelters-state"); 134 } 135 136 history.pushState("", document.title, url); 137 138 do_query(url); 139}); 140 141// Submits the form 142function submitForm() { 143 jQuery("#filter-form").submit(); 144} 145 146// AJAX 147// - Stops the previous query if one exists 148// - Retrieves the HTML from the page generated by the new URL 149var last_query; 150function do_query(url) {
151 if (last_query) { 152 last_query.abort(); 153 } 154 last_query = jQuery.get( 155 url, 156 {}, 157 function (html) { 158 update_page(html); 159 }, 160 "html" 161 ); 162} 163 164// Updates the page based on the HTML retrieved from the new URL 165function update_page(html) { 166 locStart = html.indexOf('<div class="posts-start"></div>'); 167 locEnd = html.indexOf('<div class="posts-end"></div>'); 168 newLoc = html.substr(locStart, locEnd - locStart); 169 170 jQuery(".results .posts") 171 .empty() 172 .append(newLoc) 173 .append('<div class="posts-end"></div>'); 174 175 initPagination(); 176 177 $archive = document.querySelector("#page .archive"); 178 const header = _get("header"); 179 180 jQuery("body,html").animate( 181 { scrollTop: jQuery($archive).offset().top - header.clientHeight }, 182 500 183 ); 184 185 document.querySelector("#page .archive").scrollIntoView(); 186 handleGrantedSheltersArchivePage(); 187} 188 189function initPagination() { 190 jQuery("nav a.page-numbers").click(function (e) { 191 e.preventDefault(); 192 url = jQuery(this).attr("href"); 193 history.pushState("", document.title, url); 194 do_query(url); 195 }); 196 197 jQuery(".granted_shelters-archive .results .posts nav.navigation.pagination").attr("aria-label", "pagination"); 198 jQuery(".resources-archive .results .posts nav.navigation.pagination").attr("aria-label", "pagination"); 199 jQuery(".news-archive .results .posts nav.navigation.pagination").attr("aria-label", "pagination"); 200} 201 202initPagination(); 203 204// clicks all the filters based on the url 205const handleUIOnLoad = (() => { 206 // replace the ? with a & and split them up by & 207 const search = window.location.search.replace("?", "&").split("&"); 208 let terms = []; 209 210 // loop them and split key from value 211 search.forEach((pair) => { 212 const temp = pair.split("="); 213 214 if (pair !== "") { 215 terms.push({ name: temp[0], value: temp[1] }); 216 } 217 }); 218 219 // loop terms, grab input and click it if it isnt already checked 220 terms.forEach(({ name, value }) => { 221 const values = value.split("%2C"); 222 223 values.forEach((value) => { 224 const target = document.querySelector(`input[name="${name}"].${value}`); 225 if (target && !target.checked) target.click(); 226 }); 227 228 if (name === "sort-by" || name === "granted_shelters-state") { 229 const select = document.querySelector(`select[name="${name}"]`); 230 if (select) { 231 select.value = value; 232 } 233 } 234 }); 235})(); 236 237const clearButton = document.querySelector(".clear-button"); 238clearButton.addEventListener("click", (e) => { 239 e.preventDefault(); 240 241 const sort = document.querySelector('select[name="sort-by"]'); 242 if (sort) sort.value = ""; 243 244 const state = document.querySelector('select[name="granted_shelters-state"]'); 245 if (state) state.value = ""; 246 247 const search = document.querySelector("input#s"); 248 if (search) search.value = ""; 249 250 const input = Array.from(document.querySelectorAll("#filter-form input")); 251 252 input.forEach((input) => { 253 input.checked = false; 254 }); 255 256 submitForm(); 257});
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.