diff options
Diffstat (limited to 'plugins/localsearch/localsearch/files/assets/js/tipuesearch.min.js')
-rw-r--r-- | plugins/localsearch/localsearch/files/assets/js/tipuesearch.min.js | 181 |
1 files changed, 181 insertions, 0 deletions
diff --git a/plugins/localsearch/localsearch/files/assets/js/tipuesearch.min.js b/plugins/localsearch/localsearch/files/assets/js/tipuesearch.min.js new file mode 100644 index 00000000..f50ef6ee --- /dev/null +++ b/plugins/localsearch/localsearch/files/assets/js/tipuesearch.min.js | |||
@@ -0,0 +1,181 @@ | |||
1 | (function($){$.fn.tipuesearch=function(options){var set=$.extend({'contextBuffer':60,'contextLength':60,'contextStart':90,'debug':false,'descriptiveWords':25,'footerPages':3,'highlightTerms':true,'imageZoom':true,'minimumLength':3,'newWindow':false,'show':10,'showContext':true,'showRelated':true,'showTime':true,'showTitleCount':true,'showURL':true,'wholeWords':true},options);return this.each(function(){var tipuesearch_t_c=0;var tipue_search_w='';if(set.newWindow) | ||
2 | {tipue_search_w=' target="_blank"';} | ||
3 | function getURLP(name) | ||
4 | {var locSearch=location.search;var splitted=(new RegExp('[?|&]'+name+'='+'([^&;]+?)(&|#|;|$)').exec(locSearch)||[,""]);var searchString=splitted[1].replace(/\+/g,'%20');try | ||
5 | {searchString=decodeURIComponent(searchString);} | ||
6 | catch(e) | ||
7 | {searchString=unescape(searchString);} | ||
8 | return searchString||null;} | ||
9 | if(getURLP('q')) | ||
10 | {$('#tipue_search_input').val(getURLP('q'));getTipueSearch(0,true);} | ||
11 | $(this).keyup(function(event) | ||
12 | {if(event.keyCode=='13') | ||
13 | {getTipueSearch(0,true);}});function getTipueSearch(start,replace) | ||
14 | {window.scrollTo(0,0);var out='';var show_replace=false;var show_stop=false;var standard=true;var c=0;var found=[];var d_o=$('#tipue_search_input').val();d_o=d_o.replace(/\+/g,' ').replace(/\s\s+/g,' ');d_o=$.trim(d_o);var d=d_o.toLowerCase();if((d.match("^\"")&&d.match("\"$"))||(d.match("^'")&&d.match("'$"))) | ||
15 | {standard=false;} | ||
16 | var d_w=d.split(' ');if(standard) | ||
17 | {d='';for(var i=0;i<d_w.length;i++) | ||
18 | {var a_w=true;for(var f=0;f<tipuesearch_stop_words.length;f++) | ||
19 | {if(d_w[i]==tipuesearch_stop_words[f]) | ||
20 | {a_w=false;show_stop=true;}} | ||
21 | if(a_w) | ||
22 | {d=d+' '+d_w[i];}} | ||
23 | d=$.trim(d);d_w=d.split(' ');} | ||
24 | else | ||
25 | {d=d.substring(1,d.length-1);} | ||
26 | if(d.length>=set.minimumLength) | ||
27 | {if(standard) | ||
28 | {if(replace) | ||
29 | {var d_r=d;for(var i=0;i<d_w.length;i++) | ||
30 | {for(var f=0;f<tipuesearch_replace.words.length;f++) | ||
31 | {if(d_w[i]==tipuesearch_replace.words[f].word) | ||
32 | {d=d.replace(d_w[i],tipuesearch_replace.words[f].replace_with);show_replace=true;}}} | ||
33 | d_w=d.split(' ');} | ||
34 | var d_t=d;for(var i=0;i<d_w.length;i++) | ||
35 | {for(var f=0;f<tipuesearch_stem.words.length;f++) | ||
36 | {if(d_w[i]==tipuesearch_stem.words[f].word) | ||
37 | {d_t=d_t+' '+tipuesearch_stem.words[f].stem;}}} | ||
38 | d_w=d_t.split(' ');for(var i=0;i<tipuesearch.pages.length;i++) | ||
39 | {var score=0;var s_t=tipuesearch.pages[i].text;for(var f=0;f<d_w.length;f++) | ||
40 | {if(set.wholeWords) | ||
41 | {var pat=new RegExp('\\b'+d_w[f]+'\\b','gi');} | ||
42 | else | ||
43 | {var pat=new RegExp(d_w[f],'gi');} | ||
44 | if(tipuesearch.pages[i].title.search(pat)!=-1) | ||
45 | {var m_c=tipuesearch.pages[i].title.match(pat).length;score+=(20*m_c);} | ||
46 | if(tipuesearch.pages[i].text.search(pat)!=-1) | ||
47 | {var m_c=tipuesearch.pages[i].text.match(pat).length;score+=(20*m_c);} | ||
48 | if(tipuesearch.pages[i].tags) | ||
49 | {if(tipuesearch.pages[i].tags.search(pat)!=-1) | ||
50 | {var m_c=tipuesearch.pages[i].tags.match(pat).length;score+=(10*m_c);}} | ||
51 | if(tipuesearch.pages[i].url.search(pat)!=-1) | ||
52 | {score+=20;} | ||
53 | if(score!=0) | ||
54 | {for(var e=0;e<tipuesearch_weight.weight.length;e++) | ||
55 | {if(tipuesearch.pages[i].url==tipuesearch_weight.weight[e].url) | ||
56 | {score+=tipuesearch_weight.weight[e].score;}}} | ||
57 | if(d_w[f].match('^-')) | ||
58 | {pat=new RegExp(d_w[f].substring(1),'i');if(tipuesearch.pages[i].title.search(pat)!=-1||tipuesearch.pages[i].text.search(pat)!=-1||tipuesearch.pages[i].tags.search(pat)!=-1) | ||
59 | {score=0;}}} | ||
60 | if(score!=0) | ||
61 | {found.push({"score":score,"title":tipuesearch.pages[i].title,"desc":s_t,"img":tipuesearch.pages[i].img,"url":tipuesearch.pages[i].url,"note":tipuesearch.pages[i].note});c++;}}} | ||
62 | else | ||
63 | {for(var i=0;i<tipuesearch.pages.length;i++) | ||
64 | {var score=0;var s_t=tipuesearch.pages[i].text;var pat=new RegExp(d,'gi');if(tipuesearch.pages[i].title.search(pat)!=-1) | ||
65 | {var m_c=tipuesearch.pages[i].title.match(pat).length;score+=(20*m_c);} | ||
66 | if(tipuesearch.pages[i].text.search(pat)!=-1) | ||
67 | {var m_c=tipuesearch.pages[i].text.match(pat).length;score+=(20*m_c);} | ||
68 | if(tipuesearch.pages[i].tags) | ||
69 | {if(tipuesearch.pages[i].tags.search(pat)!=-1) | ||
70 | {var m_c=tipuesearch.pages[i].tags.match(pat).length;score+=(10*m_c);}} | ||
71 | if(tipuesearch.pages[i].url.search(pat)!=-1) | ||
72 | {score+=20;} | ||
73 | if(score!=0) | ||
74 | {for(var e=0;e<tipuesearch_weight.weight.length;e++) | ||
75 | {if(tipuesearch.pages[i].url==tipuesearch_weight.weight[e].url) | ||
76 | {score+=tipuesearch_weight.weight[e].score;}}} | ||
77 | if(score!=0) | ||
78 | {found.push({"score":score,"title":tipuesearch.pages[i].title,"desc":s_t,"img":tipuesearch.pages[i].img,"url":tipuesearch.pages[i].url,"note":tipuesearch.pages[i].note});c++;}}} | ||
79 | if(c!=0) | ||
80 | {if(set.showTitleCount&&tipuesearch_t_c==0) | ||
81 | {var title=document.title;document.title='('+c+') '+title;tipuesearch_t_c++;} | ||
82 | if(c==1) | ||
83 | {out+='<div id="tipue_search_results_count">'+tipuesearch_string_4;} | ||
84 | else | ||
85 | {var c_c=c.toString().replace(/\B(?=(\d{3})+(?!\d))/g,",");out+='<div id="tipue_search_results_count">'+c_c+' '+tipuesearch_string_5;} | ||
86 | if(set.showTime) | ||
87 | {var endTimer=new Date().getTime();var time=(endTimer-startTimer)/ 1000;out+=' ('+time.toFixed(2)+' '+tipuesearch_string_14+')';set.showTime=false;} | ||
88 | out+='</div>';if(set.showRelated&&standard) | ||
89 | {var ront='';f=0;for(var i=0;i<tipuesearch_related.Related.length;i++) | ||
90 | {if(d==tipuesearch_related.Related[i].search) | ||
91 | {if(!f) | ||
92 | {out+='<div class="tipue_search_related">'+tipuesearch_string_10+': ';} | ||
93 | if(show_replace) | ||
94 | {d_o=d;} | ||
95 | if(tipuesearch_related.Related[i].include) | ||
96 | {var r_d=d_o+' '+tipuesearch_related.Related[i].related;} | ||
97 | else | ||
98 | {var r_d=tipuesearch_related.Related[i].related;} | ||
99 | ront+='<a class="tipue_search_related_btn" id="'+r_d+'">'+tipuesearch_related.Related[i].related+'</a>, ';f++;}} | ||
100 | if(f) | ||
101 | {ront=ront.slice(0,-2);ront+='.</div>';out+=ront;}} | ||
102 | if(show_replace) | ||
103 | {out+='<div id="tipue_search_replace">'+tipuesearch_string_2+' '+d+'. '+tipuesearch_string_3+' <a id="tipue_search_replaced">'+d_r+'</a></div>';} | ||
104 | found.sort(function(a,b){return b.score-a.score});var l_o=0;if(set.imageZoom) | ||
105 | {out+='<div id="tipue_search_image_modal"><div class="tipue_search_image_close">✕</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>';} | ||
106 | for(var i=0;i<found.length;i++) | ||
107 | {if(l_o>=start&&l_o<set.show+start) | ||
108 | {out+='<div class="tipue_search_result">';out+='<div class="tipue_search_content_title"><a href="'+found[i].url+'"'+tipue_search_w+'>'+found[i].title+'</a></div>';if(set.debug) | ||
109 | {out+='<div class="tipue_search_content_debug">Score: '+found[i].score+'</div>';} | ||
110 | if(set.showURL) | ||
111 | {var s_u=found[i].url.toLowerCase();if(s_u.indexOf('http://')==0) | ||
112 | {s_u=s_u.slice(7);} | ||
113 | out+='<div class="tipue_search_content_url"><a href="'+found[i].url+'"'+tipue_search_w+'>'+s_u+'</a></div>';} | ||
114 | if(found[i].img) | ||
115 | {if(set.imageZoom) | ||
116 | {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>';} | ||
117 | else | ||
118 | {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>';}} | ||
119 | if(found[i].desc) | ||
120 | {var t=found[i].desc;if(set.showContext) | ||
121 | {d_w=d.split(' ');var s_1=found[i].desc.toLowerCase().indexOf(d_w[0]);if(s_1>set.contextStart) | ||
122 | {var t_1=t.substr(s_1-set.contextBuffer);var s_2=t_1.indexOf(' ');t_1=t.substr(s_1-set.contextBuffer+s_2);t_1=$.trim(t_1);if(t_1.length>set.contextLength) | ||
123 | {t='... '+t_1;}}} | ||
124 | if(standard) | ||
125 | {d_w=d.split(' ');for(var f=0;f<d_w.length;f++) | ||
126 | {if(set.highlightTerms) | ||
127 | {var patr=new RegExp('('+d_w[f]+')','gi');t=t.replace(patr,"<h0011>$1<h0012>");}}} | ||
128 | else if(set.highlightTerms) | ||
129 | {var patr=new RegExp('('+d+')','gi');t=t.replace(patr,"<span class=\"tipue_search_content_bold\">$1</span>");} | ||
130 | var t_d='';var t_w=t.split(' ');if(t_w.length<set.descriptiveWords) | ||
131 | {t_d=t;} | ||
132 | else | ||
133 | {for(var f=0;f<set.descriptiveWords;f++) | ||
134 | {t_d+=t_w[f]+' ';}} | ||
135 | t_d=$.trim(t_d);if(t_d.charAt(t_d.length-1)!='.') | ||
136 | {t_d+=' ...';} | ||
137 | t_d=t_d.replace(/h0011/g,'span class=\"tipue_search_content_bold\"');t_d=t_d.replace(/h0012/g,'/span');out+='<div class="tipue_search_content_text">'+t_d+'</div>';} | ||
138 | if(found[i].note) | ||
139 | {out+='<div class="tipue_search_note">'+found[i].note+'</div>';} | ||
140 | out+='</div>';} | ||
141 | l_o++;} | ||
142 | if(c>set.show) | ||
143 | {var pages=Math.ceil(c / set.show);var page=(start / set.show);if(set.footerPages<3) | ||
144 | {set.footerPages=3;} | ||
145 | out+='<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';if(start>0) | ||
146 | {out+='<li role="navigation"><a class="tipue_search_foot_box" accesskey="b" id="'+(start-set.show)+'_'+replace+'">'+tipuesearch_string_6+'</a></li>';} | ||
147 | if(page<=2) | ||
148 | {var p_b=pages;if(pages>set.footerPages) | ||
149 | {p_b=set.footerPages;} | ||
150 | for(var f=0;f<p_b;f++) | ||
151 | {if(f==page) | ||
152 | {out+='<li class="current" role="navigation">'+(f+1)+'</li>';} | ||
153 | else | ||
154 | {out+='<li role="navigation"><a class="tipue_search_foot_box" id="'+(f*set.show)+'_'+replace+'">'+(f+1)+'</a></li>';}}} | ||
155 | else | ||
156 | {var p_b=page+set.footerPages-1;if(p_b>pages) | ||
157 | {p_b=pages;} | ||
158 | for(var f=page-1;f<p_b;f++) | ||
159 | {if(f==page) | ||
160 | {out+='<li class="current" role="navigation">'+(f+1)+'</li>';} | ||
161 | else | ||
162 | {out+='<li role="navigation"><a class="tipue_search_foot_box" id="'+(f*set.show)+'_'+replace+'">'+(f+1)+'</a></li>';}}} | ||
163 | if(page+1!=pages) | ||
164 | {out+='<li role="navigation"><a class="tipue_search_foot_box" accesskey="m" id="'+(start+set.show)+'_'+replace+'">'+tipuesearch_string_7+'</a></li>';} | ||
165 | out+='</ul></div>';}} | ||
166 | else | ||
167 | {out+='<div id="tipue_search_error">'+tipuesearch_string_8+'</div>';}} | ||
168 | else | ||
169 | {if(show_stop) | ||
170 | {out+='<div id="tipue_search_error">'+tipuesearch_string_8+' '+tipuesearch_string_9+'</div>';} | ||
171 | else | ||
172 | {if(set.minimumLength==1) | ||
173 | {out+='<div id="tipue_search_error">'+tipuesearch_string_11+'</div>';} | ||
174 | else | ||
175 | {out+='<div id="tipue_search_error">'+tipuesearch_string_12+' '+set.minimumLength+' '+tipuesearch_string_13+'</div>';}}} | ||
176 | $('#tipue_search_content').hide().html(out).slideDown(200);$('#tipue_search_replaced').click(function() | ||
177 | {getTipueSearch(0,false);});$('.tipue_search_related_btn').click(function() | ||
178 | {$('#tipue_search_input').val($(this).attr('id'));getTipueSearch(0,true);});$('.tipue_search_image_zoom').click(function() | ||
179 | {$('#tipue_search_image_modal').fadeIn(300);$('#tipue_search_zoom_img').attr('src',this.src);var z_u=$(this).attr('data-url');$('#tipue_search_zoom_url').attr('href',z_u);var z_o=this.alt+'<div class="tipue_search_zoom_options"><a href="'+this.src+'" target="_blank">'+tipuesearch_string_15+'</a> <a href="'+z_u+'">'+tipuesearch_string_16+'</a></div>';$('#tipue_search_zoom_text').html(z_o);});$('.tipue_search_image_close').click(function() | ||
180 | {$('#tipue_search_image_modal').fadeOut(300);});$('.tipue_search_foot_box').click(function() | ||
181 | {var id_v=$(this).attr('id');var id_a=id_v.split('_');getTipueSearch(parseInt(id_a[0]),id_a[1]);});}});};})(jQuery); \ No newline at end of file | ||