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