1// No return statement, so no variable needed or used. Also, it isn't in the `$()` so top-level is running immediately. 2(function () { 3 const $searchInput = $('.jsModuleSearchInput'); 4 let archiveSearchTermTimeout = 0; 5 let moduleSearchTermTimeout = 0; 6 7 $(function () { 8 bindHandlers(); 9 setPreviousArchiveSearch(); 10 }); 11 12 function bindHandlers() { 13 $(document) 14 // Archive 15 .on('change', '.jsFilters', function () { 16 postArchiveForm(); 17 }) 18 // Archive 19 .on('keyup', '.jsSearch', function () { 20 window.clearTimeout(archiveSearchTermTimeout); 21 archiveSearchTermTimeout = window.setTimeout(postArchiveForm, 500); 22 }) 23 // Archive 24 .on('click', '#newsroomSearchReset', function (e) { 25 e.preventDefault(); 26 resetArchiveSearch(); 27 }) 28 .on('scroller.prePost', function (event, postData) { 29 postData['search'] = $searchInput.val(); 30 semScroller.setPostData(postData); 31 }) 32 // Module 33 .on('keyup', '.jsModuleSearchInput', function () { 34 window.clearTimeout(moduleSearchTermTimeout); 35 moduleSearchTermTimeout = window.setTimeout(postModuleForm, 500); 36 }) 37 // Prevents "Enter" key from submitting search form 38 .on('keydown', 'form', function (event) { 39 // TODO: Seems that changing this to `event.keyCode !== 13` is better 40 return event.key != 'Enter'; 41 }); 42 } 43 44 function storeArchiveFormValues() { 45 const categoryFilters = []; 46 const $form = $('#jsFilterForm'); 47 48 $('.jsFilters :input').each(function () { 49 const $this = $(this); 50 51 if ($this.is(':checked')) { 52 categoryFilters.push($this.val()); 53 } 54 55 $('.jsInfiniteScroller') 56 .attr('data-postdata', $form.serialize()); 57 }); 58 59 window.localStorage.setItem('newsArchiveCategories', JSON.stringify(categoryFilters)); 60 window.localStorage.setItem('newsArchiveSearchTerm', $('.jsSearch :input').val()); 61 } 62 63 function setPreviousArchiveSearch() { 64 const storedCategories = JSON.parse(window.localStorage.getItem('newsArchiveCategories')); 65 66 if (storedCategories) { 67 $(storedCategories).each(function () { 68 $('.jsFilters').find('[value="' + parseInt(this) + '"]').prop('checked', 'true'); 69 }); 70 } 71 72 if (window.localStorage.getItem('newsArchiveSearchTerm') !== 'undefined') { 73 $('.jsSearch :input').val(window.localStorage.getItem('newsArchiveSearchTerm')); 74 $('.jsSearch').trigger('keyup'); 75 } 76 77 storeArchiveFormValues(); 78 } 79 80 function postModuleForm() { 81 if ($searchInput.length) { 82 const searchTerm = $searchInput.val(); 83 const postData = $('.jsInfiniteScroller').data('postdata'); 84 85 postData['search'] = searchTerm; 86 $.post( 87 $searchInput.data('url'), 88 postData, 89 function (returnData) { 90 $('.jsNewsList').html($(returnData).find('.jsNewsList').html()); 91 } 92 ); 93 } 94 } 95 96 function postArchiveForm() { 97 storeArchiveFormValues(); 98 99 const $form = $('#jsFilterForm'); 100 101 if ($form.length) { 102 const $formData = $form.serializeArray(); 103 104 $.post( 105 $form.data('url'), 106 $formData, 107 function (returnData) { 108 $('#jsArchiveContainer').html($(returnData).html()); 109 storeArchiveFormValues(); 110 } 111 ); 112 } 113 } 114 115 function resetArchiveSearch() { 116 $('.jsFilters input').prop('checked', false); 117 $('.jsSearch input').val(''); 118 storeArchiveFormValues(); 119 $('.jsFilters').change(); 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.