1;(function($){ 2 "use strict"; 3 var formData = {}; 4 var formDataFilter = {}; 5 var paged = 1; 6 var tax_val = wp_vars.course_tax_page; 7 var term_id = wp_vars.current_term_id; 8 9 $(document).on('change', '.tp-filter-dropdown-wrapper input[type="checkbox"], .tp-filter-dropdown-wrapper input[type="radio"], .tp-filter-dropdown-offcanvas input[type="checkbox"], .tp-filter-dropdown-offcanvas input[type="radio"]', function(){ 10 11 paged = 1; 12 formData['paged'] = paged; 13 if(1 == paged){ 14 $('.ac-lp-archive-load-more-2, .ac-lp-archive-load-more-3').css('display', 'inline-block'); 15 } 16 17 // blank array create and push data to the array also push the array in formData object 18 var sortBy = $('input[name="sort_by"]:checked').val() || ''; 19 20 if (sortBy !== '') { 21 formData['sort_by'] = sortBy; 22 } 23 24 // blank array create and push data to the array also push the array in formData object 25 let categories = []; 26 27 // Listen for changes on the checkboxes 28 $('input[name="categories"]').each(function() { 29 const value = $(this).val(); 30 31 if ($(this).is(':checked')) { 32 // Add the value if it's checked and not already in the array 33 if (!categories.includes(value)) { 34 categories.push(value); 35 } 36 } else { 37 // Remove the value if it's unchecked 38 categories = categories.filter(category => category !== value); 39 } 40 }); 41 42 if(categories.length > 0){ 43 formData['categories'] = categories; 44 }else{ 45 formData['categories'] = ''; 46 } 47 48 // blank array create and push data to the array also push the array in formData object 49 let instructors = []; 50 // Listen for changes on the checkboxes 51 $('input[name="instructors"]').each(function() { 52 const value = $(this).val(); 53 54 if ($(this).is(':checked')) { 55 // Add the value if it's checked and not already in the array 56 if (!instructors.includes(value)) { 57 instructors.push(value); 58 } 59 } else { 60 // Remove the value if it's unchecked 61 instructors = instructors.filter(instructor => instructor !== value); 62 } 63 }); 64 if(instructors.length > 0){ 65 formData['instructors'] = instructors; 66 } else { 67 formData['instructors'] = ''; 68 } 69 70 // blank array create and push data to the array also push the array in formData object 71 let sort_by_price = []; 72 $('input[name="sort_by_price"]:checked').each(function(){ 73 sort_by_price.push($(this).val()); 74 }); 75 if(sort_by_price.length > 0){ 76 formData['sort_by_price'] = sort_by_price; 77 } 78 79 // blank array create and push data to the array also push the array in formData object 80 let skills = []; 81 82 $('input[name="skills"]').each(function() { 83 const value = $(this).val(); 84 85 if ($(this).is(':checked')) { 86 // Add the value if it's checked and not already in the array 87 if (!skills.includes(value)) { 88 skills.push(value); 89 } 90 } else { 91 // Remove the value if it's unchecked 92 skills = skills.filter(skill => skill !== value); 93 } 94 }); 95 if(skills.length > 0){ 96 formData['skills'] = skills; 97 } else { 98 formData['skills'] = ''; 99 } 100 101 // Generate a nonce and add it to formData 102 let nonce = wp_vars_filter.nonce; 103 formData['nonce'] = nonce; 104 105 let urlParams = buildUrlParams(formData); 106 let newUrl = window.location.origin + window.location.pathname + '?' + urlParams; 107 window.history.pushState(null, null, newUrl); 108 109 ajax_filter_post_fetch(formData, '[data-ac-course-filter-content]', '[data-ac-course-filter-content-list]'); 110 }) 111 112 function buildUrlParams(data) { 113 let params = []; 114 115 for (let key in data) { 116 if (Array.isArray(data[key]) && data[key].length > 0) { 117 // Join array values by commas if it's non-empty 118 params.push(`${key}=${data[key].join(',')}`); 119 } else if (data[key] !== null && data[key] !== '') { 120 // Add single values (like rating) only if they are not null or empty 121 params.push(`${key}=${data[key]}`); 122 } 123 } 124 125 return params.join('&'); 126 } 127 128 // filter bar 129 window.ajax_filter_post_fetch = (params, result, result_list) => { 130 $.ajax({
131 url: wp_vars_filter.ajaxurl, 132 type: 'POST', 133 data: { 134 ...params, 135 action: 'ac_learnpress_filter_ajax_course' 136 }, 137 beforeSend:function(){ 138 block($(result)); 139 block($(result_list)); 140 block($('[data-ac-course-filter-open-content]')); 141 block($('[data-ac-course-filter-open-content-list]')); 142 }, 143 success:function(res){ 144 $(result).html(res?.data?.results); 145 $(result_list).html(res?.data?.results_list); 146 $('[data-ac-course-filter-open-content]').html(res?.data?.results_2); 147 $('[data-ac-course-filter-open-content-list]').html(res?.data?.results_list_2); 148 149 // res?.data?.total_posts > 0 && $('[data-total-courses]').html(res?.data?.totals); 150 // $('.total-courses span').text($('.tp-course-item').length); 151 // $('.tp-lp-double-result .total-courses span').text($('.tp-course-grid-item').length); 152 153 154 if(0 < res?.data?.total_posts){ 155 $('.lp-filter-result').html(res?.data?.totals); 156 $('.lp-filter-result .total-courses span').text($('.lp-archive-filter .tp-course-item').length); 157 } else { 158 $('.lp-filter-result p').text('No result found'); 159 } 160 161 if(0 < res?.data?.total_posts){ 162 $('.lp-double-result').html(res?.data?.totals); 163 $('.lp-double-result .total-courses span').text($('.lp-acadia-archive-filter-double .tp-course-grid-item').length); 164 } else { 165 $('.lp-double-result p').text('No result found'); 166 } 167 168 if(0 < res?.data?.total_posts){ 169 $('.ms-filter-result').html(res?.data?.totals); 170 $('.ms-filter-result .total-courses span').text($('.ms-acadia-archive-filter .tp-course-item').length); 171 } else { 172 $('.ms-filter-result p').text('No result found'); 173 } 174 175 if(0 < res?.data?.total_posts){ 176 $('.ms-double-result').html(res?.data?.totals); 177 $('.ms-double-result .total-courses span').text($('.ms-acadia-archive-filter-double .tp-course-grid-item').length); 178 } else { 179 $('.ms-double-result p').text('No result found'); 180 } 181 }, 182 complete: function(){ 183 unblock($(result)); 184 unblock($(result_list)); 185 block($('[data-ac-course-filter-open-content]')); 186 block($('[data-ac-course-filter-open-content-list]')); 187 }, 188 error:function(err){ 189 console.log(err); 190 } 191 }) 192 } 193 194 // ajax search 195 $(document).on('keyup', '.tp-course-filter-top-right-search.style-2 .course_search', function(e) { 196 $('.ac-lp-archive-load-more-2').css('display', 'inline-block'); 197 // Get the value from the input field 198 let searchValue = $(this).val().trim(); 199 // Get the current base URL (without query parameters) 200 let baseUrl = window.location.origin + window.location.pathname; 201 202 if (searchValue != '' && searchValue.length > 0) { 203 // Update the URL with the new query parameter 204 let newUrl = baseUrl + '?search_for=' + encodeURIComponent(searchValue) + '&paged=1'; 205 206 // Update the browser URL without reloading the page 207 window.history.pushState(null, null, newUrl); 208 209 if (e.keyCode == 13) { // Trigger form submission on Enter key 210 $('.ac-archive-filter-search-form').submit(); 211 } 212 213 search_filter_ajax_fetch_post(searchValue, '[data-ac-course-filter-content]', '[data-ac-course-filter-content-list]') 214 215 // Perform the AJAX search 216 // search_ajax_fetch_post(searchValue, '[data-ac-course-content]', '[data-ac-course-content-list]'); 217 } else { 218 // If the input is cleared (e.g., Ctrl + A + Backspace), reset the URL to the base URL 219 window.history.pushState(null, null, baseUrl); 220
221 search_filter_ajax_fetch_post('', '[data-ac-course-filter-content]', '[data-ac-course-filter-content-list]') 222 223 // Optionally, trigger the default search or reset action 224 // search_ajax_fetch_post('', '[data-ac-course-content]', '[data-ac-course-content-list]'); 225 } 226 formData['search_for'] = searchValue; 227 paged = 1; 228 formData['paged'] = paged; 229 }); 230 231 window.search_filter_ajax_fetch_post = (sarch_val, result, results_list) => { 232 $.ajax({ 233 url: wp_vars.ajaxurl, 234 type: 'POST', 235 data: { 236 action : 'ac_learnpress_filter_ajax_course', 237 search_for: sarch_val, 238 nonce : wp_vars_filter.nonce 239 }, 240 beforeSend: function(){ 241 block($(result)); 242 block($(results_list)); 243 }, 244 success: function(res){ 245 $(result).html(res?.data?.results); 246 $(results_list).html(res?.data?.results_list); 247 // $('[data-total-courses]').html(res?.data?.totals); 248 // $('.total-courses span').text($('.tp-course-item').length); 249 250 if(0 < res?.data?.total_posts){ 251 $('.lp-filter-result').html(res?.data?.totals); 252 $('.lp-filter-result .total-courses span').text($('.lp-archive-filter .tp-course-item').length); 253 } else { 254 $('.lp-filter-result p').text('No result found'); 255 } 256 257 if(0 < res?.data?.total_posts){ 258 $('.ms-filter-result').html(res?.data?.totals); 259 $('.ms-filter-result .total-courses span').text($('.ms-acadia-archive-filter .tp-course-item').length); 260 } else { 261 $('.ms-filter-result p').text('No result found'); 262 } 263 }, 264 complete: function(){ 265 unblock($(result)); 266 unblock($(results_list)); 267 }, 268 error:function(err){ 269 console.log(err); 270 } 271 }); 272 } 273 274 $(document).on('click', '.ac-lp-archive-load-more-2', function(e){ 275 e.preventDefault(); 276 paged++; 277 var url = new URL(window.location.href); 278 var params = new URLSearchParams(url.search); 279 280 if( params.get('search_for') != null ){ 281 formDataFilter['search_for'] = params.get('search_for'); 282 } 283 284 if( params.get('sort_by') != null ){ 285 formDataFilter['sort_by'] = params.get('sort_by'); 286 } 287 288 if( params.get('categories') != null ){ 289 formDataFilter['categories'] = params.get('categories').split(','); 290 } 291 292 if( params.get('instructors') != null ){ 293 formDataFilter['instructors'] = params.get('instructors').split(','); 294 } 295 296 if( params.get('sort_by_price') != null ){ 297 formDataFilter['sort_by_price'] = params.get('sort_by_price').split(','); 298 } 299 300 if( params.get('skills') != null ){ 301 formDataFilter['skills'] = params.get('skills').split(','); 302 } else { 303 formDataFilter['skills'] = ''; 304 } 305 formDataFilter['paged'] = paged; 306 ajax_filter_post_fetch_load(formDataFilter, '[data-ac-course-filter-content]', '[data-ac-course-filter-content-list]'); 307 }); 308 309 window.ajax_filter_post_fetch_load = (params, result, result_list) => { 310 $.ajax({
311 url: wp_vars_filter.ajaxurl, 312 type: 'POST', 313 data: { 314 ...params, 315 action: 'ac_learnpress_filter_ajax_course', 316 tax_val : tax_val, 317 term_id : term_id 318 }, 319 beforeSend:function(){ 320 block($(result)); 321 block($(result_list)); 322 }, 323 success:function(res){ 324 $(result).append(res?.data?.results); 325 $(result_list).append(res?.data?.results_list); 326 res?.data?.total_posts > 0 && $('[data-total-courses]').html(res?.data?.totals); 327 $('.total-courses span').text($('.tp-course-item').length); 328 329 if(0 == res.data.total_pagi){ 330 $('.ac-lp-archive-load-more-2').css('display', 'none'); 331 } 332 }, 333 complete: function(){ 334 unblock($(result)); 335 unblock($(result_list)); 336 }, 337 error:function(err){ 338 console.log(err); 339 } 340 }) 341 } 342})(jQuery);
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.