tipuesearch.min.js 8.1 KB

1234567891011121314151617
  1. (function(l){l.fn.tipuesearch=function(B){var d=l.extend({contextBuffer:60,contextLength:60,contextStart:90,debug:!1,descriptiveWords:25,footerPages:3,highlightTerms:!0,imageZoom:!0,minimumLength:3,newWindow:!1,show:10,showContext:!0,showRelated:!0,showTime:!0,showTitleCount:!0,showURL:!0,wholeWords:!0},B);return this.each(function(){function z(d){d=((new RegExp("[?|&]"+d+"=([^&;]+?)(&|#|;|$)")).exec(location.search)||[,""])[1].replace(/\+/g,"%20");try{d=decodeURIComponent(d)}catch(w){d=unescape(d)}return d||
  2. null}function x(u,w){window.scrollTo(0,0);var e="",t=!1,k=!1,p=!0,n=0,g=[],m=l("#tipue_search_input").val();m=m.replace(/\+/g," ").replace(/\s\s+/g," ");m=l.trim(m);var h=m.toLowerCase();if(h.match('^"')&&h.match('"$')||h.match("^'")&&h.match("'$"))p=!1;var c=h.split(" ");if(p){h="";for(var a=0;a<c.length;a++){for(var v=!0,b=0;b<tipuesearch_stop_words.length;b++)c[a]==tipuesearch_stop_words[b]&&(v=!1,k=!0);v&&(h=h+" "+c[a])}h=l.trim(h);c=h.split(" ")}else h=h.substring(1,h.length-1);if(h.length>=
  3. d.minimumLength){if(p){if(w){var r=h;for(a=0;a<c.length;a++)for(b=0;b<tipuesearch_replace.words.length;b++)c[a]==tipuesearch_replace.words[b].word&&(h=h.replace(c[a],tipuesearch_replace.words[b].replace_with),t=!0);c=h.split(" ")}k=h;for(a=0;a<c.length;a++)for(b=0;b<tipuesearch_stem.words.length;b++)c[a]==tipuesearch_stem.words[b].word&&(k=k+" "+tipuesearch_stem.words[b].stem);c=k.split(" ");for(a=0;a<tipuesearch.pages.length;a++){k=0;v=tipuesearch.pages[a].text;for(b=0;b<c.length;b++){var f=d.wholeWords?
  4. new RegExp("\\b"+c[b]+"\\b","gi"):new RegExp(c[b],"gi");if(-1!=tipuesearch.pages[a].title.search(f)){var q=tipuesearch.pages[a].title.match(f).length;k+=20*q}-1!=tipuesearch.pages[a].text.search(f)&&(q=tipuesearch.pages[a].text.match(f).length,k+=20*q);tipuesearch.pages[a].tags&&-1!=tipuesearch.pages[a].tags.search(f)&&(q=tipuesearch.pages[a].tags.match(f).length,k+=10*q);-1!=tipuesearch.pages[a].url.search(f)&&(k+=20);if(0!=k)for(f=0;f<tipuesearch_weight.weight.length;f++)tipuesearch.pages[a].url==
  5. tipuesearch_weight.weight[f].url&&(k+=tipuesearch_weight.weight[f].score);c[b].match("^-")&&(f=new RegExp(c[b].substring(1),"i"),-1!=tipuesearch.pages[a].title.search(f)||-1!=tipuesearch.pages[a].text.search(f)||-1!=tipuesearch.pages[a].tags.search(f))&&(k=0)}0!=k&&(g.push({score:k,title:tipuesearch.pages[a].title,desc:v,img:tipuesearch.pages[a].img,url:tipuesearch.pages[a].url,note:tipuesearch.pages[a].note}),n++)}}else for(a=0;a<tipuesearch.pages.length;a++){k=0;v=tipuesearch.pages[a].text;f=new RegExp(h,
  6. "gi");-1!=tipuesearch.pages[a].title.search(f)&&(q=tipuesearch.pages[a].title.match(f).length,k+=20*q);-1!=tipuesearch.pages[a].text.search(f)&&(q=tipuesearch.pages[a].text.match(f).length,k+=20*q);tipuesearch.pages[a].tags&&-1!=tipuesearch.pages[a].tags.search(f)&&(q=tipuesearch.pages[a].tags.match(f).length,k+=10*q);-1!=tipuesearch.pages[a].url.search(f)&&(k+=20);if(0!=k)for(f=0;f<tipuesearch_weight.weight.length;f++)tipuesearch.pages[a].url==tipuesearch_weight.weight[f].url&&(k+=tipuesearch_weight.weight[f].score);
  7. 0!=k&&(g.push({score:k,title:tipuesearch.pages[a].title,desc:v,img:tipuesearch.pages[a].img,url:tipuesearch.pages[a].url,note:tipuesearch.pages[a].note}),n++)}if(0!=n){d.showTitleCount&&0==A&&(document.title="("+n+") "+document.title,A++);1==n?e+='<div id="tipue_search_results_count">'+tipuesearch_string_4:(a=n.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),e+='<div id="tipue_search_results_count">'+a+" "+tipuesearch_string_5);d.showTime&&(a=((new Date).getTime()-startTimer)/1E3,e+=" ("+a.toFixed(2)+
  8. " "+tipuesearch_string_14+")",d.showTime=!1);e+="</div>";if(d.showRelated&&p){c="";for(a=b=0;a<tipuesearch_related.Related.length;a++)h==tipuesearch_related.Related[a].search&&(b||(e+='<div class="tipue_search_related">'+tipuesearch_string_10+": "),t&&(m=h),c+='<a class="tipue_search_related_btn" id="'+(tipuesearch_related.Related[a].include?m+" "+tipuesearch_related.Related[a].related:tipuesearch_related.Related[a].related)+'">'+tipuesearch_related.Related[a].related+"</a>, ",b++);b&&(c=c.slice(0,
  9. -2),e+=c+".</div>")}t&&(e+='<div id="tipue_search_replace">'+tipuesearch_string_2+" "+h+". "+tipuesearch_string_3+' <a id="tipue_search_replaced">'+r+"</a></div>");g.sort(function(a,b){return b.score-a.score});t=0;d.imageZoom&&(e+='<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>');for(a=0;a<g.length;a++){if(t>=
  10. u&&t<d.show+u){e+='<div class="tipue_search_result">';e+='<div class="tipue_search_content_title"><a href="'+g[a].url+'"'+y+">"+g[a].title+"</a></div>";d.debug&&(e+='<div class="tipue_search_content_debug">Score: '+g[a].score+"</div>");d.showURL&&(b=g[a].url.toLowerCase(),0==b.indexOf("http://")&&(b=b.slice(7)),e+='<div class="tipue_search_content_url"><a href="'+g[a].url+'"'+y+">"+b+"</a></div>");g[a].img&&(e=d.imageZoom?e+('<div class="tipue_search_image"><img class="tipue_search_img tipue_search_image_zoom" src="'+
  11. g[a].img+'" alt="'+g[a].title+'" data-url="'+g[a].url+'"></div>'):e+('<div class="tipue_search_image"><a href="'+g[a].url+'"'+y+'><img class="tipue_search_img" src="'+g[a].img+'" alt="'+g[a].title+'"></a></div>'));if(g[a].desc){m=g[a].desc;d.showContext&&(c=h.split(" "),b=g[a].desc.toLowerCase().indexOf(c[0]),b>d.contextStart&&(c=m.substr(b-d.contextBuffer),c=c.indexOf(" "),c=m.substr(b-d.contextBuffer+c),c=l.trim(c),c.length>d.contextLength&&(m="... "+c)));if(p)for(c=h.split(" "),b=0;b<c.length;b++)d.highlightTerms&&
  12. (r=new RegExp("("+c[b]+")","gi"),m=m.replace(r,"<h0011>$1<h0012>"));else d.highlightTerms&&(r=new RegExp("("+h+")","gi"),m=m.replace(r,'<span class="tipue_search_content_bold">$1</span>'));c="";r=m.split(" ");if(r.length<d.descriptiveWords)c=m;else for(b=0;b<d.descriptiveWords;b++)c+=r[b]+" ";c=l.trim(c);"."!=c.charAt(c.length-1)&&(c+=" ...");c=c.replace(/h0011/g,'span class="tipue_search_content_bold"');c=c.replace(/h0012/g,"/span");e+='<div class="tipue_search_content_text">'+c+"</div>"}g[a].note&&
  13. (e+='<div class="tipue_search_note">'+g[a].note+"</div>");e+="</div>"}t++}if(n>d.show){p=Math.ceil(n/d.show);n=u/d.show;3>d.footerPages&&(d.footerPages=3);e+='<div id="tipue_search_foot"><ul id="tipue_search_foot_boxes">';0<u&&(e+='<li role="navigation"><a class="tipue_search_foot_box" accesskey="b" id="'+(u-d.show)+"_"+w+'">'+tipuesearch_string_6+"</a></li>");2>=n?(g=p,p>d.footerPages&&(g=d.footerPages),b=0):(g=n+d.footerPages-1,g>p&&(g=p),b=n-1);for(;b<g;b++)e=b==n?e+('<li class="current" role="navigation">'+
  14. (b+1)+"</li>"):e+('<li role="navigation"><a class="tipue_search_foot_box" id="'+b*d.show+"_"+w+'">'+(b+1)+"</a></li>");n+1!=p&&(e+='<li role="navigation"><a class="tipue_search_foot_box" accesskey="m" id="'+(u+d.show)+"_"+w+'">'+tipuesearch_string_7+"</a></li>");e+="</ul></div>"}}else e+='<div id="tipue_search_error">'+tipuesearch_string_8+"</div>"}else e=k?e+('<div id="tipue_search_error">'+tipuesearch_string_8+" "+tipuesearch_string_9+"</div>"):1==d.minimumLength?e+('<div id="tipue_search_error">'+
  15. tipuesearch_string_11+"</div>"):e+('<div id="tipue_search_error">'+tipuesearch_string_12+" "+d.minimumLength+" "+tipuesearch_string_13+"</div>");l("#tipue_search_content").hide().html(e).slideDown(200);l("#tipue_search_replaced").click(function(){x(0,!1)});l(".tipue_search_related_btn").click(function(){l("#tipue_search_input").val(l(this).attr("id"));x(0,!0)});l(".tipue_search_image_zoom").click(function(){l("#tipue_search_image_modal").fadeIn(300);l("#tipue_search_zoom_img").attr("src",this.src);
  16. var a=l(this).attr("data-url");l("#tipue_search_zoom_url").attr("href",a);a=this.alt+'<div class="tipue_search_zoom_options"><a href="'+this.src+'" target="_blank">'+tipuesearch_string_15+'</a>&nbsp; <a href="'+a+'">'+tipuesearch_string_16+"</a></div>";l("#tipue_search_zoom_text").html(a)});l(".tipue_search_image_close").click(function(){l("#tipue_search_image_modal").fadeOut(300)});l(".tipue_search_foot_box").click(function(){var a=l(this).attr("id").split("_");x(parseInt(a[0]),a[1])})}var A=0,y=
  17. "";d.newWindow&&(y=' target="_blank"');z("q")&&(l("#tipue_search_input").val(z("q")),x(0,!0));l(this).keyup(function(d){"13"==d.keyCode&&x(0,!0)})})}})(jQuery);