8
0
daux.io/tipuesearch/tipuesearch.min.js

1 zeile
7.3 KiB
JavaScript

!function(e){e.fn.tipuesearch=function(t){var i=e.extend({show:7,newWindow:!1,showURL:!0,showTitleCount:!0,minimumLength:3,descriptiveWords:25,highlightTerms:!0,highlightEveryTerm:!1,mode:"static",liveDescription:"*",liveContent:"*",contentLocation:"tipuesearch/tipuesearch_content.json",debug:!1},t),r=function(){var e,t={},i=window.location.href.split("?")[1];if(i){i=i.split("&");for(var r=0;r<i.length;r++)e=i[r].split("="),t[decodeURIComponent(e[0])]=decodeURIComponent(e[1])}return t},s=function(e){var t=window.location.href,i=t.split("?")[0],r=[];for(var s in e)e.hasOwnProperty(s)&&r.push(encodeURIComponent(s)+"="+encodeURIComponent(e[s]));r.length&&(r.sort(),i+="?"+r.join("&")),window.location.href=i};return this.each(function(){function t(){var t=e.extend({search:"",start:"0"},r());e("#tipue_search_input").val(t.search),a(parseInt(t.start,10),!0)}function a(t,r){e("#tipue_search_content").hide();var h="",p=!1,u=!1,l=!0,_=0;found=[];var g=e("#tipue_search_input").val().toLowerCase();if(g=e.trim(g),!g)return void e(".doc_content").show();if(e("#tipue_search_content").html('<div class="tipue_search_spinner"><div class="tipue_search_rect1"></div><div class="tipue_search_rect2"></div><div class="rect3"></div></div>'),e("#tipue_search_content").show(),(g.match('^"')&&g.match('"$')||g.match("^'")&&g.match("'$"))&&(l=!1),l){var d=g.split(" ");g="";for(var v=0;v<d.length;v++){for(var f=!0,w=0;w<tipuesearch_stop_words.length;w++)d[v]==tipuesearch_stop_words[w]&&(f=!1,u=!0);f&&(g=g+" "+d[v])}g=e.trim(g),d=g.split(" ")}else g=g.substring(1,g.length-1);if(g.length>=i.minimumLength){if(l){if(r){for(var m=g,v=0;v<d.length;v++)for(var w=0;w<tipuesearch_replace.words.length;w++)d[v]==tipuesearch_replace.words[w].word&&(g=g.replace(d[v],tipuesearch_replace.words[w].replace_with),p=!0);d=g.split(" ")}for(var x=g,v=0;v<d.length;v++)for(var w=0;w<tipuesearch_stem.words.length;w++)d[v]==tipuesearch_stem.words[w].word&&(x=x+" "+tipuesearch_stem.words[w].stem);d=x.split(" ");for(var v=0;v<n.pages.length;v++){for(var b=0,L=n.pages[v].text,w=0;w<d.length;w++){var C=new RegExp(d[w],"gi");if(-1!=n.pages[v].title.search(C)){var E=n.pages[v].title.match(C).length;b+=20*E}if(-1!=n.pages[v].text.search(C)){var E=n.pages[v].text.match(C).length;b+=20*E}if(i.highlightTerms){if(i.highlightEveryTerm)var R=new RegExp("("+d[w]+")","gi");else var R=new RegExp("("+d[w]+")","i");L=L.replace(R,'<span class="h01">$1</span>')}if(-1!=n.pages[v].tags.search(C)){var E=n.pages[v].tags.match(C).length;b+=10*E}if(-1!=n.pages[v].url.search(C)&&(b+=20),0!=b)for(var y=0;y<tipuesearch_weight.weight.length;y++)n.pages[v].url==tipuesearch_weight.weight[y].url&&(b+=tipuesearch_weight.weight[y].score);d[w].match("^-")&&(C=new RegExp(d[w].substring(1),"i"),(-1!=n.pages[v].title.search(C)||-1!=n.pages[v].text.search(C)||-1!=n.pages[v].tags.search(C))&&(b=0))}0!=b&&(found.push({score:b,title:n.pages[v].title,desc:L,url:n.pages[v].url}),_++)}}else for(var v=0;v<n.pages.length;v++){var b=0,L=n.pages[v].text,C=new RegExp(g,"gi");if(-1!=n.pages[v].title.search(C)){var E=n.pages[v].title.match(C).length;b+=20*E}if(-1!=n.pages[v].text.search(C)){var E=n.pages[v].text.match(C).length;b+=20*E}if(i.highlightTerms){if(i.highlightEveryTerm)var R=new RegExp("("+g+")","gi");else var R=new RegExp("("+g+")","i");L=L.replace(R,'<span class="h01">$1</span>')}if(-1!=n.pages[v].tags.search(C)){var E=n.pages[v].tags.match(C).length;b+=10*E}if(-1!=n.pages[v].url.search(C)&&(b+=20),0!=b)for(var y=0;y<tipuesearch_weight.weight.length;y++)n.pages[v].url==tipuesearch_weight.weight[y].url&&(b+=tipuesearch_weight.weight[y].score);0!=b&&(found.push({score:b,title:n.pages[v].title,desc:L,url:n.pages[v].url}),_++)}if(0!=_){if(i.showTitleCount&&0==c){var T=document.title;document.title="("+_+") "+T,c++}1==p&&(h+='<div id="tipue_search_warning">'+tipuesearch_string_2+" "+g+". "+tipuesearch_string_3+' <a id="tipue_search_replaced">'+m+"</a></div>"),1==_?h+='<div id="tipue_search_results_count">'+tipuesearch_string_4+"</div>":(c_c=_.toString().replace(/\B(?=(\d{3})+(?!\d))/g,","),h+='<div id="tipue_search_res