1jQuery(document).ready(function($) { 2 3 if (!afLiveSearch.enabled) return; 4 5 let timer; 6 const resultsBox = $('#af-live-search-results'); 7 const searchInput = $('input[type="search"]'); 8 9 let items = []; 10 let index = -1; 11 12 function resetNavigation() { 13 items = resultsBox.find('[role="option"]'); 14 index = -1; 15 items.attr('aria-selected', 'false'); 16 } 17 18 searchInput.on('keyup', function (e) { 19 20 // Keyboard navigation 21 if (e.key === 'ArrowDown' && items.length) { 22 index = (index + 1) % items.length; 23 items.attr('aria-selected', 'false') 24 .eq(index).attr('aria-selected', 'true').focus(); 25 return; 26 } 27 28 if (e.key === 'ArrowUp' && items.length) { 29 index = (index - 1 + items.length) % items.length; 30 items.attr('aria-selected', 'false') 31 .eq(index).attr('aria-selected', 'true').focus(); 32 return; 33 } 34 35 if (e.key === 'Enter' && index >= 0) { 36 window.location = items.eq(index).find('a').attr('href'); 37 return; 38 } 39 40 // Regular typing 41 const query = $(this).val().trim(); 42 clearTimeout(timer); 43 44 timer = setTimeout(function() { 45 46 if (query.length < 2) { 47 resultsBox.html('').attr('aria-expanded', 'false'); 48 return; 49 } 50 51 $.ajax({ 52 url: afLiveSearch.ajax_url, 53 type: 'POST', 54 data: { 55 action: 'morenews_live_search', 56 s: query, 57 nonce: afLiveSearch.nonce, 58 limit: afLiveSearch.results_count 59 }, 60 beforeSend: function () { 61 resultsBox 62 .html('<div class="loading" role="status">' + afLiveSearch.searching_text + '</div>') 63 .attr('aria-expanded', 'true'); 64 }, 65 success: function (response) { 66 resultsBox.html(response).attr('aria-expanded', 'true'); 67 resetNavigation(); 68 } 69 }); 70 71 }, 300); 72 }); 73 74 // Close when clicking outside 75 $(document).on('click', function(e){ 76 if (!$(e.target).closest('.af-search-wrap').length) { 77 resultsBox.html('').attr('aria-expanded', 'false'); 78 } 79 }); 80});
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.