1 2 3jQuery(document).ready(function () { 4 //$('.search-field:visible').popup(); 5 // Init 6 new IndexSearchAutoComplete(); 7 8 $(document).on('keydown',function(event){ 9 10 if (event.keyCode === 13) { 11 let sel=$('.highlighted > #full-search'); 12 if(sel.length > 0){ 13 event.preventDefault(); 14 viewAllResults(); 15 } 16 } 17 }); 18}); 19 20function viewAllResults(){ 21 forms=[$('#search-form'),$('.search-form:visible')]; 22 forms.forEach(function (form) { 23 if(form.length){ 24 form.submit(); 25 } 26 }); 27} 28 29function IndexSearchAutoComplete() { 30 var debounceTimeout = null; // Used to reduce the amount of querys 31 var lastSearchQuery = ''; // Used to reduce the amount of querys 32 33 // Check whether there is an input box to apply the autocomplete to 34 if (jQuery('input.search, input.tx-indexedsearch-searchbox-sword, input.indexed-search-atocomplete-sword, input.indexed-search-autocomplete-sword').length == 0) 35 return; 36 37 // Initialise the autocomplete 38 var that = this; 39 jQuery('input.search, input.tx-indexedsearch-searchbox-sword, input.indexed-search-atocomplete-sword, input.indexed-search-autocomplete-sword:visible') 40 .on('input keypress keyup', function (e) { 41 that.autocomplete(e, this); 42 }).attr('autocomplete', 'off'); 43 44 // When a click is performed somewhere on the page, remove the autocomplete-box 45 jQuery('*').click(function () { 46 var elem = jQuery(this); 47 var targetClass = '.search-autocomplete-results'; 48 49 if (jQuery('.search-autocomplete-results > *').length == 0) { 50 return; // Result-Div is not shown 51 } 52 53 while (elem.prop("tagName") != 'HTML' && !elem.hasClass(targetClass)) { 54 elem = elem.parent(); 55 } 56 57 if (elem.prop("tagName") == 'HTML') { 58 jQuery(targetClass).html('').hide().removeClass('results').addClass('no-results'); 59 } 60 61 }); 62 63} 64 65 66/** 67 * Autocomplete a query 68 * 69 * @param e jQuery-Event which gets fired in case of a keypress 70 */ 71IndexSearchAutoComplete.prototype.autocomplete = function(e, ref) { 72 var $input = jQuery(ref); 73 var $elem = jQuery(ref); 74 var $results; 75 76 // Find the corrosponding div for the results 77 var cnt = 0; 78 while ($elem.prop("tagName") !== 'HTML') { 79 $results = $elem.find('.search-autocomplete-results'); 80 if ($results.length > 0) { 81 break; 82 } 83 $elem = $elem.parent(); 84 } 85 if ($elem.prop("tagName") === 'HTML') { 86 console.log("we couldn't find a result div (.search-autocomplete-results)"); 87 return; 88 } 89 90 // Retrive options 91 var mode = typeof $results.data('mode') === 'undefined' ? 'word' : $results.data('mode'); 92 var soc = $results.data('searchonclick') == true; 93 94 // navigate through the suggestions/results 95 if (e.which === 38 || e.which === 40 || e.keyCode === 10 || e.keyCode === 13) { // up / down / enter 96 97 if (e.which === 38 && e.type === 'keyup') { // up 98 var $prev = $results.find('li.highlighted').prev(); 99 100 if ($results.find('li.highlighted').length === 0 || $prev.length === 0) { 101 $results.find('li.highlighted').removeClass('highlighted'); 102 $results.find('li').last().addClass('highlighted'); 103 return; 104 } 105 106 $results.find('li.highlighted').removeClass('highlighted'); 107 $prev.addClass('highlighted'); 108 } 109 110 if (e.which === 40 && e.type === 'keyup') { // down 111 var $next = $results.find('li.highlighted').next(); 112 if ($results.find('li.highlighted').length === 0 || $next.length === 0) { 113 $results.find('li.highlighted').removeClass('highlighted'); 114 $results.find('li').first().addClass('highlighted'); 115 return; 116 } 117 118 $results.find('li.highlighted').removeClass('highlighted'); 119 $next.addClass('highlighted'); 120 } 121 122 if ((e.keyCode === 10 || e.keyCode === 13) && e.type === 'keypress') { // enter 123 if ($results.is(':visible') && $results.find('li.highlighted').length > 0) { 124 if (mode === 'word') { 125 $results.find('li.highlighted').click(); 126 127 // Search on click 128 if (soc) { 129 $input.closest('form').submit(); 130 } 131 } else { 132 window.location = $results.find('li.highlighted a.navigate-on-enter').attr('href'); 133 } 134 e.preventDefault(); 135 } 136 } 137 138 return; 139 } 140 141 // Catch left / right arrow keys 142 if (e.keyCode === 37 || e.keyCode === 39) 143 return; 144 145 // Do only start a query if a key is released to save querys 146 if (e.type !== 'keyup') 147 return; 148 149 // Empty the results 150 $results.html('').hide().removeClass('results').addClass('no-results'); 151 152 // Retrive the query 153 var val = jQuery(ref).val().trim(); 154 var minlen = typeof $results.data('minlength') === 'undefined' ? 3 : $results.data('minlength'); 155 var maxResults = typeof $results.data('maxresults') === 'undefined' ? 10 : $results.data('maxresults'); 156 157 // Check if the query is long enough 158 if (val.length < minlen) 159 return; 160 161 // Check whether the search term changed 162 if (val == this.lastSearchQuery) 163 return; 164 165 // Set the old query value 166 this.lastSearchQuery = val; 167 168 // tell the user the search is running 169 $results.addClass('autocomplete_searching'); 170 171 // Perform the query 172 this.performQuery(val, mode, maxResults, $results, $input); 173} 174 175 176IndexSearchAutoComplete.prototype.performQuery = function(val, mode, maxResults, $results, $input) { 177 var m=mode; 178 // Debounce 179 clearTimeout(this.debounceTimeout); 180 this.debounceTimeout = setTimeout(function() { 181 clearTimeout(this.debounceTimeout); 182 $('.search-loader').show(); 183 // Execute the query 184 jQuery.ajax({ 185 url: $results.data('searchurl'), 186 cache: false, 187 method: 'POST', 188 data: { 189 s: val, 190 m: mode, 191 mr: maxResults 192 }, 193 success: function (data) { 194 if(m==='file'){ 195 files=JSON.parse(data); 196 window.files = files; 197 //trigger dom change 198 $('#file-results').attr('data-time',Date.now()); 199 }else { 200 // Insert the results 201 $li = $results 202 .show() 203 .html(data) 204 .removeClass('autocomplete_searching') 205 .find('li'); 206 207 // Add a click action 208 //$li.click(function () { 209 // $input.val(jQuery(this).text().trim()); 210 // $results.html('').hide(); 211 //}); 212 213 // Check if there are results and update the FE depending on it 214 if ($li.length == 0) { 215 216 // No results 217 $results.html('').hide(); 218 $results.removeClass('results').addClass('no-results'); 219 } else { 220 221 // Results 222 $results.removeClass('no-results').addClass('results'); 223 } 224 } 225 $('.search-loader').hide(); 226 } 227 }); 228 }, 250); 229};
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.