1 2/* 3Tipue Search 6.1 4Copyright (c) 2017 Tipue 5Tipue Search is released under the MIT License 6http://www.tipue.com/search 7*/ 8 9 10(function($) { 11 12 $.fn.tipuesearch = function(options) { 13 14 var set = $.extend( { 15 16 'contentLocation' : 'tipuesearch/tipuesearch_content.json', 17 'contextBuffer' : 60, 18 'contextLength' : 60, 19 'contextStart' : 90, 20 'debug' : false, 21 'descriptiveWords' : 25, 22 'highlightTerms' : true, 23 'liveContent' : '*', 24 'liveDescription' : '*', 25 'minimumLength' : 3, 26 'mode' : 'static', 27 'newWindow' : false, 28 'show' : 30, 29 'showContext' : true, 30 'showRelated' : true, 31 'showTime' : true, 32 'showTitleCount' : true, 33 'showURL' : true, 34 'wholeWords' : false 35 36 }, options); 37 38 return this.each(function() { 39 40 var tipuesearch_in = { 41 pages: [] 42 }; 43 $.ajaxSetup({ 44 async: false 45 }); 46 var tipuesearch_t_c = 0; 47 48 $('#tipue_search_content').hide().html('<div class="tipue_search_spinner"><div class="tipue_search_rect1"></div><div class="tipue_search_rect2"></div><div class="rect3"></div></div>').show(); 49 50 if (set.mode == 'live') 51 { 52 for (var i = 0; i < tipuesearch_pages.length; i++) 53 { 54 $.get(tipuesearch_pages[i]).done(function(html) 55 { 56 var cont = $(set.liveContent, html).text(); 57 cont = cont.replace(/\s+/g, ' '); 58 var desc = $(set.liveDescription, html).text(); 59 desc = desc.replace(/\s+/g, ' '); 60 61 var t_1 = html.toLowerCase().indexOf('<title>'); 62 var t_2 = html.toLowerCase().indexOf('</title>', t_1 + 7); 63 if (t_1 != -1 && t_2 != -1) 64 { 65 var tit = html.slice(t_1 + 7, t_2); 66 } 67 else 68 { 69 var tit = tipuesearch_string_1; 70 } 71 72 tipuesearch_in.pages.push( 73 { 74 "title": tit, 75 "text": desc, 76 "tags": cont, 77 "url": tipuesearch_pages[i] 78 }); 79 }); 80 } 81 } 82 83 if (set.mode == 'json') 84 { 85 $.getJSON(set.contentLocation).done(function(json) 86 { 87 tipuesearch_in = $.extend({}, json); 88 }); 89 } 90 91 if (set.mode == 'static') 92 { 93 tipuesearch_in = $.extend({}, tipuesearch); 94 } 95 96 var tipue_search_w = ''; 97 if (set.newWindow) 98 { 99 tipue_search_w = ' target="_blank"'; 100 } 101 102 function getURLP(name) 103 { 104 var _locSearch = location.search; 105 var _splitted = (new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(_locSearch)||[,""]); 106 var searchString = _splitted[1].replace(/\+/g, '%20'); 107 try 108 { 109 searchString = decodeURIComponent(searchString); 110 } 111 catch(e) 112 { 113 searchString = unescape(searchString); 114 } 115 return searchString || null; 116 } 117 118 if (getURLP('q')) 119 {
120 $('#tipue_search_input').val(getURLP('q')); 121 getTipueSearch(0, true); 122 } 123 124 $(this).keyup(function(event) 125 { 126 if(event.keyCode == '13') 127 { 128 getTipueSearch(0, true); 129 } 130 }); 131 132 133 function getTipueSearch(start, replace) 134 { 135 var out = ''; 136 var show_replace = false; 137 var show_stop = false; 138 var standard = true; 139 var c = 0; 140 found = []; 141 142 var d_o = $('#tipue_search_input').val(); 143 var d = d_o.toLowerCase(); 144 d = $.trim(d); 145 146 if ((d.match("^\"") && d.match("\"$")) || (d.match("^'") && d.match("'$"))) 147 { 148 standard = false; 149 } 150 151 var d_w = d.split(' '); 152 153 if (standard) 154 { 155 d = ''; 156 for (var i = 0; i < d_w.length; i++) 157 { 158 var a_w = true; 159 for (var f = 0; f < tipuesearch_stop_words.length; f++) 160 { 161 if (d_w[i] == tipuesearch_stop_words[f]) 162 { 163 a_w = false; 164 show_stop = true; 165 } 166 } 167 if (a_w) 168 { 169 d = d + ' ' + d_w[i]; 170 } 171 } 172 d = $.trim(d); 173 d_w = d.split(' '); 174 } 175 else 176 { 177 d = d.substring(1, d.length - 1); 178 } 179 180 if (d.length >= set.minimumLength) 181 { 182 if (standard) 183 { 184 if (replace) 185 { 186 var d_r = d; 187 for (var i = 0; i < d_w.length; i++) 188 { 189 for (var f = 0; f < tipuesearch_replace.words.length; f++) 190 { 191 if (d_w[i] == tipuesearch_replace.words[f].word) 192 { 193 d = d.replace(d_w[i], tipuesearch_replace.words[f].replace_with); 194 show_replace = true; 195 } 196 } 197 } 198 d_w = d.split(' '); 199 } 200 201 var d_t = d; 202 for (var i = 0; i < d_w.length; i++) 203 { 204 for (var f = 0; f < tipuesearch_stem.words.length; f++) 205 { 206 if (d_w[i] == tipuesearch_stem.words[f].word) 207 { 208 d_t = d_t + ' ' + tipuesearch_stem.words[f].stem; 209 } 210 } 211 } 212 d_w = d_t.split(' '); 213 214 for (var i = 0; i < tipuesearch_in.pages.length; i++) 215 { 216 var score = 0; 217 var s_t = tipuesearch_in.pages[i].text; 218 for (var f = 0; f < d_w.length; f++) 219 { 220 if (set.wholeWords) 221 { 222 var pat = new RegExp('\\b' + d_w[f] + '\\b', 'gi'); 223 } 224 else 225 { 226 var pat = new RegExp(d_w[f], 'gi'); 227 } 228 if (tipuesearch_in.pages[i].title.search(pat) != -1) 229 { 230 var m_c = tipuesearch_in.pages[i].title.match(pat).length; 231 score += (20 * m_c); 232 } 233 if (tipuesearch_in.pages[i].text.search(pat) != -1) 234 { 235 var m_c = tipuesearch_in.pages[i].text.match(pat).length; 236 score += (20 * m_c); 237 } 238 239 if (tipuesearch_in.pages[i].tags.search(pat) != -1) 240 { 241 var m_c = tipuesearch_in.pages[i].tags.match(pat).length; 242 score += (10 * m_c); 243 } 244 245 if (tipuesearch_in.pages[i].url.search(pat) != -1) 246 { 247 score += 20; 248 } 249 250 if (score != 0) 251 { 252 for (var e = 0; e < tipuesearch_weight.weight.length; e++) 253 { 254 if (tipuesearch_in.pages[i].url == t
254ipuesearch_weight.weight[e].url) 255 { 256 score += tipuesearch_weight.weight[e].score; 257 } 258 } 259 } 260 261 if (d_w[f].match('^-')) 262 { 263 pat = new RegExp(d_w[f].substring(1), 'i'); 264 if (tipuesearch_in.pages[i].title.search(pat) != -1 || tipuesearch_in.pages[i].text.search(pat) != -1 || tipuesearch_in.pages[i].tags.search(pat) != -1) 265 { 266 score = 0; 267 } 268 } 269 } 270 271 if (score != 0) 272 { 273 found.push( 274 { 275 "score": score, 276 "title": tipuesearch_in.pages[i].title, 277 "desc": s_t, 278 "url": tipuesearch_in.pages[i].url 279 }); 280 c++; 281 } 282 } 283 } 284 else 285 { 286 for (var i = 0; i < tipuesearch_in.pages.length; i++) 287 { 288 var score = 0; 289 var s_t = tipuesearch_in.pages[i].text; 290 var pat = new RegExp(d, 'gi'); 291 if (tipuesearch_in.pages[i].title.search(pat) != -1) 292 { 293 var m_c = tipuesearch_in.pages[i].title.match(pat).length; 294 score += (20 * m_c); 295 } 296 if (tipuesearch_in.pages[i].text.search(pat) != -1) 297 { 298 var m_c = tipuesearch_in.pages[i].text.match(pat).length; 299 score += (20 * m_c); 300 } 301 302 if (tipuesearch_in.pages[i].tags.search(pat) != -1) 303 { 304 var m_c = tipuesearch_in.pages[i].tags.match(pat).length; 305 score += (10 * m_c); 306 } 307 308 if (tipuesearch_in.pages[i].url.search(pat) != -1) 309 { 310 score += 20; 311 } 312 313 if (score != 0) 314 { 315 for (var e = 0; e < tipuesearch_weight.weight.length; e++) 316 { 317 if (tipuesearch_in.pages[i].url == tipuesearch_weight.weight[e].url) 318 { 319 score += tipuesearch_weight.weight[e].score; 320 } 321 } 322 } 323 324 if (score != 0) 325 { 326 found.push( 327 { 328 "score": score, 329 "title": tipuesearch_in.pages[i].title, 330 "desc": s_t, 331 "url": tipuesearch_in.pages[i].url 332 }); 333 c++; 334 } 335 } 336 } 337 338 if (c != 0) 339 { 340 if (set.showTitleCount && tipuesearch_t_c == 0) 341 { 342 var title = document.title; 343 document.title = '(' + c + ') ' + title; 344 tipuesearch_t_c++; 345 } 346 347 if (show_replace) 348 { 349 out += '<div id="tipue_search_warning">' + tipuesearch_string_2 + ' ' + d + '. ' + tipuesearch_string_3 + ' <a id="tipue_search_replaced">' + d_r + '</a></div>'; 350 } 351 if (c == 1) 352 { 353 out += '<div id="tipue_search_results_count">' + tipuesearch_string_4; 354 } 355 else 356 { 357 c_c = c.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); 358 out += '<div id="tipue_search_results_count">' + c_c + ' ' + tipuesearch_string_5; 359 } 360 if (set.showTime) 361 { 362 var endTimer = new Date().getTime(); 363 var time = (endTimer - startTimer) / 1000; 364 out += ' (' + time.toFixed(2) + ' ' + tipuesearch_string_14 + ')'; 365 set.showTime = false;
366 } 367 out += '</div>'; 368 369 found.sort(function(a, b) { return b.score - a.score } ); 370 371 var l_o = 0; 372 for (var i = 0; i < found.length; i++) 373 { 374 if (l_o >= start && l_o < set.show + start) 375 { 376 out += '<div class="tipue_search_content_title"><a href="' + found[i].url + '"' + tipue_search_w + '>' + found[i].title + '</a></div>'; 377 378 if (set.debug) 379 { 380 out += '<div class="tipue_search_content_debug">Score: ' + found[i].score + '</div>'; 381 } 382 383 if (set.showURL) 384 { 385 var s_u = found[i].url.toLowerCase(); 386 if (s_u.indexOf('http://') == 0) 387 { 388 s_u = s_u.slice(7); 389 } 390 out += '<div class="tipue_search_content_url"><a href="' + found[i].url + '"' + tipue_search_w + '>' + s_u + '</a></div>'; 391 } 392 393 if (found[i].desc) 394 { 395 var t = found[i].desc; 396 397 if (set.showContext) 398 { 399 d_w = d.split(' '); 400 var s_1 = found[i].desc.toLowerCase().indexOf(d_w[0]); 401 if (s_1 > set.contextStart) 402 { 403 var t_1 = t.substr(s_1 - set.contextBuffer); 404 var s_2 = t_1.indexOf(' '); 405 t_1 = t.substr(s_1 - set.contextBuffer + s_2); 406 t_1 = $.trim(t_1); 407 408 if (t_1.length > set.contextLength) 409 { 410 t = '... ' + t_1; 411 } 412 } 413 } 414 415 if (standard) 416 { 417 d_w = d.split(' '); 418 for (var f = 0; f < d_w.length; f++) 419 { 420 if (set.highlightTerms) 421 { 422 var patr = new RegExp('(' + d_w[f] + ')', 'gi'); 423 t = t.replace(patr, "<h0011>$1<h0012>"); 424 } 425 } 426 } 427 else if (set.highlightTerms) 428 { 429 var patr = new RegExp('(' + d + ')', 'gi'); 430 t = t.replace(patr, "<span class=\"tipue_search_content_bold\">$1</span>"); 431 } 432 433 var t_d = ''; 434 var t_w = t.split(' '); 435 if (t_w.length < set.descriptiveWords) 436 { 437 t_d = t; 438 } 439 else 440 { 441 for (var f = 0; f < set.descriptiveWords; f++) 442 { 443 t_d += t_w[f] + ' '; 444 } 445 } 446 t_d = $.trim(t_d); 447 if (t_d.charAt(t_d.length - 1) != '.') 448 { 449 t_d += ' ...'; 450 } 451 452 t_d = t_d.replace(/h0011/g, 'span class=\"tipue_search_content_bold\"'); 453 t_d = t_d.replace(/h0012/g, '/span'); 454 455 out += '<div class="tipue_search_content_text">' + t_d + '</div>'; 456 } 457 } 458 l_o++; 459 } 460 461 if (set.showRelated && standard) 462 { 463 f = 0; 464 for (var i = 0; i < tipuesearch_related.searches.length; i++) 465 { 466 if (d == tipuesearch_related.searches[i].search) 467 { 468 if (show_replace) 469 { 470 d_o = d; 471 } 472 if (!f) 473 { 474 out += '<div class="tipue_search_related_title">' + tipuesearch_string_15 + ' <span class="tipue_search_related_bold">' + d_o + '</span></div><div class="tipue_search_related_cols">'; 475 } 476 477 out += '<div class="tipue_search_related_text"><a class="tipue_search_related" id="' + tipuesearch_related.searches[i].related + '">'; 478 if (tipuesearch_related.searches[i].before) 479 { 480 out += '<span class="tipue_search_related_before">' + tipuesearch_related.searches[i].before + '</span> '; 481 } 482 out += tipuesearch_related.searches[i].related; 483 if (tipuesearch_related.searches[i].after) 484 { 485 out += ' <span class="tipue_search_related_after">' + tipuesearch_related.searches[i].after + '</span>'; 486 } 487 out += '</a></div>'; 488 f++; 489 } 490 } 491 if (f) 492 { 493 out += '</div>'; 494 } 495 } 496 497 if (c > set.show) 498 { 499 var pages = Math.ceil(c / set.show); 500 var page = (start / set.show); 501 out += '<nav><div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">'; 502 503 if (start > 0) 504 { 505 out += '<li role="navigation"><a class="tipue_search_foot_box" accesskey="b" id="' + (start - set.show) + '_' + replace + '">' + tipuesearch_string_6 + '</a></li>'; 506 } 507 508 if (page <= 2) 509 { 510 var p_b = pages; 511 if (pages > 3) 512 { 513 p_b = 3; 514 } 515 for (var f = 0; f < p_b; f++) 516 { 517 if (f == page) 518 { 519 out += '<li class="current" role="navigation">' + (f + 1) + '</li>'; 520 } 521 else 522 { 523 out += '<li role="navigation"><a class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>'; 524 } 525 } 526 } 527 else 528 { 529 var p_b = page + 2; 530 if (p_b > pages) 531 { 532 p_b = pages; 533 } 534 for (var f = page - 1; f < p_b; f++) 535 { 536 if (f == page) 537 { 538 out += '<li class="current" role="navigation">' + (f + 1) + '</li>'; 539 } 540 else 541 { 542 out += '<li role="navigation"><a class="tipue_search_foot_box" id="' + (f * set.show) + '_' + replace + '">' + (f + 1) + '</a></li>'; 543 } 544 } 545 } 546 547 if (page + 1 != pages) 548 { 549 out += '<li role="navigation"><a class="tipue_search_foot_box" accesskey="m" id="' + (start + set.show) + '_' + replace + '">' + tipuesearch_string_7 + '</a></li>'; 550 } 551 552 out += '</ul></div></nav>'; 553 } 554 } 555 else 556 { 557 out += '<div id="tipue_search_warning">' + tipuesearch_string_8 + '</div>'; 558 } 559 } 560 else 561 { 562 if (show_stop) 563 { 564 out += '<div id="tipue_search_warning">' + tipuesearch_string_8 + '. ' + tipuesearch_string_9 + '</div>'; 565 } 566 else 567 { 568 out += '<div id="tipue_search_warning">' + tipuesearch_string_10 + '</div>'; 569 if (set.minimumLength == 1) 570 { 571 out += '<div id="tipue_search_warning">' + tipuesearch_string_11 + '</div>'; 572 } 573 else 574 { 575 out += '<div id="tipue_search_warning">' + tipuesearch_string_12 + ' ' + set.minimumLength + ' ' + tipuesearch_string_13 + '</div>'; 576 } 577 } 578 } 579
580 $('#tipue_search_content').hide().html(out).slideDown(200); 581 582 $('#tipue_search_replaced').click(function() 583 { 584 getTipueSearch(0, false); 585 }); 586 587 $('.tipue_search_related').click(function() 588 { 589 $('#tipue_search_input').val($(this).attr('id')); 590 getTipueSearch(0, true); 591 }); 592 593 $('.tipue_search_foot_box').click(function() 594 { 595 var id_v = $(this).attr('id'); 596 var id_a = id_v.split('_'); 597 598 getTipueSearch(parseInt(id_a[0]), id_a[1]); 599 }); 600 } 601 602 }); 603 }; 604 605})(jQuery);
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.