1document.addEventListener('DOMContentLoaded', function () { 2 const resultsFound = document.querySelector('.results-found'); 3 const loadMoreButton = document.querySelector('.load-more-button'); 4 5 if (resultsFound) { 6 const resultsCount = parseInt(resultsFound.textContent.replace(/\D/g, ''), 10); 7 8 if (resultsCount < 20) { 9 loadMoreButton.style.display = 'none'; 10 } else { 11 loadMoreButton.style.display = 'inline-block'; 12 loadMoreButton.innerHTML = 'Load More Results'; 13 } 14 } 15}); 16 17 18function getUrlParam(name) { 19 const urlParams = new URLSearchParams(window.location.search); 20 return urlParams.get(name); 21} 22 23var page = 2; // Start loading from the second page 24 25jQuery(function($) { 26 27 $('#load-more-btn').on('click', function() { 28 var button = $(this); 29 const category = getUrlParam('ep_filter_category'); // Get the 'name' parameter 30 const tag = getUrlParam('ep_filter_post_tag'); // Get the 'name' parameter 31 const order = getUrlParam('order'); // Get the 'name' parameter 32 const orderby = getUrlParam('orderby'); // Get the 'name' parameter 33 const exact_match = getUrlParam('exact_match'); // Get the 'name' parameter 34 35 // Make AJAX request to load more posts 36 $.ajax({ 37 url: load_more_params.ajax_url, 38 type: 'GET', 39 data: { 40 action: 'load_more_posts', 41 query: load_more_params.query_vars, 42 page: page, 43 nonce: load_more_params.pagination_nonce, 44 category:category, 45 exact_match:exact_match, 46 tag:tag, 47 order:order, 48 orderby:orderby 49 }, 50 beforeSend: function() { 51 button.html('<i class="fa fa-spinner fa-spin" style="font-size:24px"></i> Loading Results'); // Change button text while loading 52 }, 53 success: function(response) { 54 if (response) { 55 //console.log(response.content.length); 56 // Append the new posts to the posts list 57 //$('.post-list-data:last').append(response.content); 58 59 var posts = $(response.content.join('')); 60 61 // Append the new posts after the last .post-list-data inside #posts-container 62 $('#posts-container .post-list-data').last().after(posts); 63 64 // Increment the page number for the next request 65 page++; 66 67 // If there are no more posts, hide the Load More button 68 if (response.content.length<20) { 69 button.hide(); 70 } else { 71 button.text('Load More Results'); 72 } 73 } 74 } 75 }); 76 }); 77}); 78 79jQuery(document).ready(function ($) { 80 setTimeout(() => { 81 $('.esep-live-search').each(function () { 82 const _this = $(this); 83 $(_this).on('input', function (e) { 84 let searchTerm = $(this).val(); 85 86 // Clear results if input is empty 87 if (!searchTerm.trim()) { 88 $('.esep-search-results-dropdown').html(''); 89 return; 90 } 91 92 // Send AJAX request 93 $.ajax({ 94 url: load_more_params.ajax_url, 95 method: 'GET', 96 data: { 97 action: 'esep_live_search', 98 searchTerm: searchTerm, 99 page: 1 100 }, 101 success: function (response) { 102 let resultsContainer = $('.esep-search-results-dropdown'); 103 resultsContainer.html(''); // Clear previous results 104 105 if (response.content.length > 0) { 106 let resultsHTML = '<ul>'; 107 response.content.forEach(item => { 108 resultsHTML += `<li> 109 <div class="left-col">
110 <span class="esep-mb-image">`; 111 112 // Check if item.image exists and is not empty 113 if (item.image) { 114 resultsHTML += `<img src="${item.image}" alt="${item.title}" />`; 115 } 116 117 resultsHTML += `</span> 118 </div> 119 <div class="right-col"> 120 <span class="esep-mb-title"><a href="${item.url}">${item.title}</a></span> 121 <p class="esep-mb-content">${item.excerpt}</p> 122 </div> 123 </li>`; 124 }); 125 resultsHTML += '</ul>'; 126 resultsContainer.html(resultsHTML); 127 } else { 128 resultsContainer.html('<p>No results found</p>'); 129 } 130 131 }, 132 }); 133 }); 134 }); 135 }, 1000); 136}); 137 138const searchResultsFunction = (searchTerm) => { 139} 140 141// Facet toggle 142window.addEventListener('mouseup', function(event) { 143 let facets = document.querySelectorAll('.widget_ep-facet'); 144 facets.forEach(function(facet) { 145 const terms = facet.querySelector('.terms'); 146 const isTerms = terms.contains(event.target); 147 const isFacet = event.target === facet || event.target.parentNode === facet; 148 if (!isTerms && !isFacet) { 149 terms.classList.remove('active'); 150 } 151 }); 152}); 153 154 155const initializeFilterToggle = () => { 156 jQuery(document).ready(function ($) { 157 $('.widget_ep-facet h3').on('click', function() { 158 $(this).siblings('.terms').toggleClass('active'); 159 }); 160 }); 161 162 document.querySelector('.clear-filters .clear-filters-link') && document.querySelector('.clear-filters .clear-filters-link').addEventListener('click', async (e) => { 163 e.preventDefault(); 164 e.stopImmediatePropagation(); 165 166 // Clear the search input field 167 const searchInput = document.querySelector('#searchform #s'); 168 if (searchInput) { 169 searchInput.value = ''; 170 } 171 172 173 const siteBaseURL = window.location.origin; 174 const targetPath = "/advanced-search/"; 175 const targetURL = siteBaseURL + targetPath; 176 177 // Redirect if the current page is not already at the target URL 178 if (window.location.href !== targetURL) { 179 window.location.href = targetURL; 180 return; // Stop further execution after redirect 181 } 182 183 const param = e.target.getAttribute('href'); 184 history.pushState(null, '', param); 185 await renderFilterContent(param); 186 187 // Submit the search form with a blank query 188 const searchForm = document.querySelector('#searchform'); 189 if (searchForm) { 190 searchForm.submit(); 191 } 192 }); 193} 194 195initializeFilterToggle(); 196 197const initializeFilterListeners = () => { 198 const widgets = document.querySelectorAll('.sortbyfilters .widget_ep-facet'); 199 widgets.forEach(widget => { 200 widget.querySelectorAll('.term:not(.empty-term) a').forEach(link => { 201 link.addEventListener('click', async (e) => { 202 e.preventDefault(); 203 e.stopImmediatePropagation() 204 const param = link.getAttribute('href'); 205 const currentUrl = new URL(window.location.href); 206 const searchParams = new URLSearchParams(currentUrl.search); 207 const order = searchParams.get("order") || "DESC"; // Default to 'DESC' 208 const exact_match = searchParams.get("exact_match") || 0; // Default to 'DESC' 209 const params_url = `${window.location.origin}${param}${param.includes('?') ? '&' : '?'}order=${order}&exact_match=${exact_match}`; 210 211 const widgetId = widget.getAttribute('id'); 212 history.pushState(null, '', params_url); 213 await renderFilterContent(params_url,`#${widgetId} .terms`); 214 }); 215 }); 216 }); 217}; 218
219const renderFilterContent = async (params_url,widget) => { 220 try { 221 const loadingDiv = document.querySelector('.loading_filter'); 222 loadingDiv.style.display = 'flex'; 223 const response = await fetch(params_url); 224 const responseText = await response.text(); 225 const html = new DOMParser().parseFromString(responseText, 'text/html'); 226 const selectors = ['#posts-container', '.results-found', '.sortbyfilters_left', 'input[type="hidden"][name="ep_filter_category"]', 'input[type="hidden"][name="ep_filter_post_tag"]', '#orderby', '#order']; 227 selectors.forEach(selector => { 228 const targetElement = document.querySelector(selector); 229 const sourceElement = html.querySelector(selector); 230 if (targetElement && sourceElement) { 231 targetElement.replaceWith(sourceElement); 232 } 233 }); 234 if(widget) document.querySelector(widget).classList.add('active'); 235 initializeFilterToggle(); 236 initializeFilterListeners(); 237 page = 2;
238 const loadMoreButton = document.querySelector('#load-more-btn'); 239 if(loadMoreButton){ 240 const resultsFound = document.querySelector('.results-found'); 241 const resultsCount = parseInt(resultsFound.textContent.replace(/\D/g, '')); 242 if (resultsCount < 20) { 243 loadMoreButton.style.display = 'none'; 244 }else{ 245 loadMoreButton.style.display = 'inline-block'; 246 loadMoreButton.innerHTML = 'Load More Results'; 247 } 248 } 249 loadingDiv.style.display = 'none'; 250 } catch (e) { 251 const loadingDiv = document.querySelector('.loading_filter'); 252 loadingDiv.style.display = 'none'; 253 console.error("Error updating filters:", e); 254 } 255}; 256 257document.addEventListener('DOMContentLoaded', initializeFilterListeners); 258 259function checkInvertedComma(input) { 260 var exactMatchField = document.getElementById('exact_match'); 261 var s_value = document.getElementById('s').value; 262 if (s_value.includes('"')) { 263 exactMatchField.value = 1; 264 } else { 265 exactMatchField.value = 0; 266 } 267}
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.