1var searcher = {initialized: false, query: {search: null, filter: null, offset: 0}, index: -1, feedReadyForMore: true}; 2 3function getResults() { 4 searcher.feedReadyForMore = false; 5 var div = $('[search-results-box]'), 6 fParam = searcher.query.filter == null ? '' : '&f=' + searcher.query.filter, 7 params = '?s=' + searcher.query.search + '&o=0' + fParam; 8 $.ajax({ 9 url: baseUrl + '/search/results' + params, 10 beforeSend: function () { 11 div.html(div.attr('loading')); 12 }, 13 success: function (data) { 14 div.html(data); 15 showFinds(); 16 searcher.feedReadyForMore = true; 17 }, 18 error: function () { 19 div.html(''); 20 searcher.feedReadyForMore = false; 21 } 22 }); 23} 24 25function getMoreResults(filter) { 26 searcher.feedReadyForMore = false; 27 var div = $('[more="' + filter + '"]'), 28 params = '?s=' + searcher.query.search + '&o=' + searcher.query.offset + '&f=' + filter; 29 $.ajax({ 30 url: baseUrl + '/search/more' + params, 31 success: function (data) { 32 div.append(data); 33 showFinds(); 34 searcher.feedReadyForMore = true; 35 }, 36 error: function () { 37 searcher.feedReadyForMore = false; 38 } 39 }); 40} 41 42function showFinds() { 43 $('.searcher-page-result-title').each(function (i, f) { 44 var 45 h = $(this).html(), 46 highlightedHtml = h.replace(QueryString.s, '<span class="find">' + QueryString.s + '</span>'); 47 $(this).html(highlightedHtml); 48 }); 49 $('.searcher-page-result-text').each(function (i, f) { 50 var 51 h = $(this).html(), 52 highlightedHtml = h.replace(QueryString.s, '<span class="find">' + QueryString.s + '</span>'); 53 $(this).html(highlightedHtml); 54 }); 55} 56 57function searcherInternalInput() { 58 if (!searcher.initialized) { 59 initSearcher(); 60 } 61} 62 63function searcherFocus() { 64 getRecentPredictions(); 65 $('[searcher]').attr('opened', 'yes'); 66 if (!searcher.initialized) { 67 initSearcher(); 68 } 69} 70 71function searcherBlur() { 72 if ( 73 $(".searcher-results-internal:hover").length == 0 && 74 $(".searcher-input:focus").length == 0 75 ) { 76 $('[searcher]').attr('opened', 'no'); 77 $('[in-focus]').attr('in-focus', 'no'); 78 $('[filter-in-focus]').attr('in-focus', 'no'); 79 } 80} 81 82function searcherSetKeys() { 83 $(window).keyup(function (event) { 84 console.log(event.key); 85 if (event.key == 'ArrowDown') { 86 if (searcher.index < 9) { 87 searcher.index++; 88 highlightResult(); 89 } 90 } 91 if (event.key == 'ArrowUp') { 92 if (searcher.index > 0) { 93 searcher.index--; 94 highlightResult(); 95 } 96 } 97 if (event.key == 'Enter') { 98 searcher.query.search = $('[searcher-input]').val(); 99 if ($('[in-focus="yes"]').length > 0) { 100 $('[in-focus="yes"]').click(); 101 } else if ($('[filter-in-focus="yes"]').length > 0) { 102 $('[filter-in-focus="yes"]').click(); 103 } else { 104 searcher.query.search = $('[searcher-input]').val(); 105 window.location.href = baseUrl + '/search/view?s=' + searcher.query.search; 106 } 107 } 108 if (event.key == 'Escape') { 109 escapeSearcher(); 110 } 111 }); 112} 113 114function escapeSearcher() { 115 $('[searcher]').attr('opened', 'no'); 116 $('[searcher-input]').val('').focusout(); 117 $('[filter]').attr('filter-state', 'off'); 118 searcher.query.search = null; 119 searcher.query.filter = null; 120 history.pushState(searcher.query, 'Search', '?s='); 121} 122 123function searcherSetBlur() { 124 $(window).mouseup(function (event) { 125 searcherBlur(); 126 }); 127} 128 129function highlightResult() { 130 $('[searcher-index]').attr('in-focus', 'no'); 131 $('[searcher-index="' + searcher.index + '"]').attr('in-focus', 'yes'); 132 $('[searcher-filter-index]').attr('filter-in-focus', 'no'); 133 $('[searcher-filter-index="' + searcher.index + '"]').attr('filter-in-focus', '
133yes'); 134} 135 136function seeResult(ele) { 137 $.ajax({ 138 url: baseUrl + '/search/register', 139 type: "POST", 140 dataType: 'json', 141 data: { 142 attributes: { 143 term: QueryString.s, 144 type: $(ele).attr('ty'), 145 subtype: $(ele).attr('st'), 146 type_id: $(ele).attr('tid'), 147 url: $(ele).attr('url'), 148 src: $(ele).attr('src'), 149 title: $(ele).attr('title') 150 } 151 }, 152 success: function () { 153 var url = parseUrl($(ele).attr('url')); 154 window.location.href = url; 155 }, 156 error: function () { 157 //TODO 158 } 159 }); 160} 161 162function setFilterByUrl() { 163 if (isset(QueryString.f)) { 164 searcher.query.filter = QueryString.f; 165 $('[filter="' + searcher.query.filter + '"]').attr('filter-state', 'on'); 166 } 167} 168 169function setFilter(ele) { 170 var filter = $(ele).attr('filter'); 171 $('[filter]').attr('filter-state', 'off'); 172 $('.searcher-filter[filter="' + filter + '"]').attr('filter-state', 'on'); 173 searcher.query.search = $('[searcher-input]').val(); 174 searcher.query.filter = filter; 175 reloadResults(); 176} 177 178function resetFilter() { 179 $('[filter]').attr('filter-state', 'off'); 180 searcher.query.search = $('[searcher-input]').val(); 181 searcher.query.filter = null; 182 reloadResults(); 183} 184 185function reloadResults() { 186 var fParam = searcher.query.filter == null ? '' : '&f=' + searcher.query.filter; 187 history.pushState(searcher.query, 'Search', '?s=' + searcher.query.search + fParam); 188 getResults(); 189} 190 191function initSearcherPage(s) { 192 searcher.query.search = s; 193 $('[searcher-input]').val(s); 194 setFilterByUrl(); 195 getResults(); 196} 197 198function initSearcher() { 199 searcher.initialized = true; 200 searcherSetKeys(); 201 searcherSetBlur(); 202} 203 204function emptySearcher() { 205 $('[searcher-input]').val(''); 206 $('[filter]').attr('filter-state', 'off'); 207 searcher.query = {search: null, filter: null, offset: 0}; 208 history.pushState(searcher.query, 'Search', ''); 209} 210 211// predictions 212 213function removePrediction(ele) { 214 var pid = $(ele).attr('pid'); 215 $('[pid="' + pid + '"]').remove(); 216 $.ajax({url: baseUrl + '/search/removePrediction?pid=' + pid}); 217} 218 219function getRecentPredictions() { 220 $.ajax({ 221 url: baseUrl + '/search/recent', 222 success: function (data) { 223 $('[searcher-results]').html(data); 224 }, 225 error: function () { 226 //TODO 227 } 228 }); 229} 230 231function getFreshPredictions() { 232 searcher.query.search = $('[searcher-input]').val(); 233 $.ajax({ 234 url: baseUrl + '/search/predictions?s=' + searcher.query.search, 235 success: function (data) { 236 $('[searcher-results]').html(data); 237 }, 238 error: function () { 239 //TODO 240 } 241 }); 242} 243 244function goToPrediction(ele) { 245 var url = parseUrl($(ele).attr('url')); 246 $.ajax({ 247 url: baseUrl + '/search/registerPrediction?pid=' + $(ele).attr('pid'), 248 success: function () { 249 window.location.href = url; 250 }, 251 error: function () { 252 window.location.href = url; 253 } 254 }); 255} 256 257function goToSearch(ele) { 258 window.location.href = baseUrl + '/search/view?s=' + $(ele).attr('term'); 259} 260 261function parseUrl(url) { 262 if (!url.includes('https://') && !url.includes('http://')) { 263 url = baseUrl + '/' + url; 264 } 265 return url; 266} 267 268function searcherInput() { 269 $('[searcher]').attr('opened', 'yes'); 270 searcher.query.search = $('[searcher-input]').val(); 271 console.log((searcher.query.search).length); 272 if ((searcher.query.search).length == 0) { 273 getRecentPredictions(); 274 } else { 275 getFreshPredictions(); 276 } 277} 278 279function toggleEditingMode(ele) { 280 var nextState = $("[editing-mode]").attr('editing-mode') == 'off' ? 'on' : 'off'; 281 $("[editing-mode]").attr('editing-mode', nextState); 282} 283 284$(window).on('scroll', throttle(function (event) { 285 if (searcher.query.filter != null && searcher.feedReadyForMore) { 286 if ($(window).scrollTop() + $(window).height() >
286 $(document).height() * 0.8) { 287 searcher.query.offset += 11; 288 getMoreResults(searcher.query.filter); 289 } 290 } 291}, 1000));
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.