1jQuery(document).ready(function($) { 2 function fetch_results(extraData = {}) { 3 var formData = $('#search-page-form').serializeArray(); 4 5 $.each(extraData, function(key, value) { 6 formData.push({ name: key, value: value }); 7 }); 8 9 $('#spinner').show(); 10 11 $('.search-total-results').addClass('hide-total'); 12 13 $.post( sdSearchFilter.ajaxURL, 14 { 15 action : 'search_filter', 16 formData: $.param(formData), 17 }, 18 function(data){ 19 if(data){ 20 21 $('#search-results').html(data); 22 23 if( $('#search-input').val() != '' ){ 24 $('.search-clear').addClass('active'); 25 } 26 } 27 }).done(function() { 28 $('#spinner').hide(); 29 30 var totalResults = $('.search-filter-results').attr('data-total'); 31 32 if ( totalResults == 1 ){ 33 $('.search-total-results').html(totalResults+' result found'); 34 } else if ( totalResults > 0 ){ 35 $('.search-total-results').html(totalResults+' results found'); 36 } else{ 37 $('.search-total-results').empty(); 38 } 39 40 $('.search-total-results').removeClass('hide-total'); 41 }).fail(function(jqXHR, textStatus, errorThrown) { 42 console.log(jqXHR); 43 console.log(textStatus); 44 console.log(errorThrown ); 45 }).always(function() { 46 }); 47 } 48 49 50 // Form changes trigger search 51 $('#search-page-form').on('change', 'select', function() { 52 fetch_results({ paged: 1 }); 53 }); 54 55 var typeTimer, typeInterval = 800; 56 57 $('#search-page-form').on('change keyup', 'input', function() { 58 59 var keywords = $(this).val(); 60 61 if( keywords.length > 2 ){ 62 63 clearTimeout(typeTimer); 64 typeTimer = setTimeout(fetch_results({ paged: 1 }), typeInterval); 65 } 66 67 if( keywords.length > 0 ){ 68 $('.search-clear').addClass('active'); 69 } else{ 70 $('.search-clear').removeClass('active'); 71 } 72 }); 73 74 // Pagination click 75 $('#search-results').on('click', '.search-filter-nav', function(e) { 76 e.preventDefault(); 77 78 let $pagination = $('#search-filter-pagination'); 79 let currentPage = parseInt($pagination.data('current')); 80 let totalPages = parseInt($pagination.data('total')); 81 let paged = currentPage; 82 83 if ($(this).hasClass('next') && currentPage < totalPages) { 84 paged = currentPage + 1; 85 } else if ($(this).hasClass('prev') && currentPage > 1) { 86 paged = currentPage - 1; 87 } 88 89 // Update data-current attribute 90 $pagination.attr('data-current', paged); 91 92 fetch_results({ paged: paged }); 93 $("html, body").animate({ scrollTop: 0 }, "slow"); 94}); 95 96 $(document).on('click', '.search-clear', function() { 97 $(this).removeClass('active'); 98 $('#search-input').val(''); 99 fetch_results({ paged: 1 }); 100 }); 101 102 // Load first page 103 fetch_results(); 104 105 $('.search-filter-btn').on('click', function() { 106 $(this).closest('.search-filter-item').toggleClass('active'); // Show/hide options 107 }); 108 109 $('.search-filter-options li').on('click', function() { 110 var selectedText = $(this).text(); 111 var selectedValue = $(this).attr('data-value'); 112 113 $('.search-filter-options li').removeClass('active'); 114 $(this).addClass('active'); 115 116 $(this).parent().prev('.dropdown-btn').text(selectedText); // Update button text 117 $(this).parent().next('input[name="category"]').val(selectedValue); // Update hidden input 118 119 fetch_results({ paged: 1 }); // Trigger AJAX filter on selection 120 }); 121});
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.