-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathen.fancy-search.min.de24ecd18cde6f14e126fb9b38a62fea7ae1a6bbd4a1459a29f0ee6003d85ad2.js
1 lines (1 loc) · 6.2 KB
/
en.fancy-search.min.de24ecd18cde6f14e126fb9b38a62fea7ae1a6bbd4a1459a29f0ee6003d85ad2.js
1
"use strict";(function(e){e.addEvent=function(e,t,n){e.attachEvent?e.attachEvent("on"+t,n):e.addEventListener(t,n)},e.removeEvent=function(e,t,n){e.detachEvent?e.detachEvent("on"+t,n):e.removeEventListener(t,n)},e.onReady=function(e){document.readyState!="loading"?e():document.addEventListener?document.addEventListener("DOMContentLoaded",e):document.attachEvent("onreadystatechange",function(){document.readyState=="complete"&&e()})};const o=document.getElementById("search-input");function n(){var e=new XMLHttpRequest;e.open("GET","/en.fancy-search-data.b8096004ebe6c93087dff2bb02b980f2b3014966ab7ccc4f3f04a865695b0337.json",!0),e.onload=function(){if(e.status>=200&&e.status<400){var n,t=JSON.parse(e.responseText);lunr.tokenizer.separator=/[\s\-_]+/,n=lunr(function(){this.ref("id"),this.field("title",{boost:200}),this.field("content",{boost:2}),this.field("relUrl"),this.metadataWhitelist=["position"];for(var e in t)this.add({id:e,title:t[e].title,content:t[e].content,relUrl:t[e].relUrl})}),s(n,t)}else console.log("Error loading ajax request. Request status:"+e.status)},e.onerror=function(){console.log("There was a connection error")},e.send()}function s(t,n){var a,t=t,n=n,s=document.getElementById("search-input"),o=document.getElementById("search-results"),d=document.getElementById("book-search"),i=0;function l(){document.documentElement.classList.add("search-active")}function r(){document.documentElement.classList.remove("search-active")}function c(){i++;var c,d,u,h,e=s.value;if(e===""?r():(l(),window.scroll(0,-1),setTimeout(function(){window.scroll(0,0)},0)),e===a)return;if(a=e,o.innerHTML="",e==="")return;c=t.query(function(t){var n=lunr.tokenizer(e);t.term(n,{boost:10}),t.term(n,{wildcard:lunr.Query.wildcard.LEADING|lunr.Query.wildcard.TRAILING})}),c.length==0&&e.length>2&&(h=lunr.tokenizer(e).filter(function(e){return e.str.length<20}),h.length>0&&(c=t.query(function(t){t.term(h,{editDistance:Math.round(Math.sqrt(e.length/2-1))})}))),c.length==0?(d=document.createElement("div"),d.classList.add("search-no-result"),d.innerText="No results found",o.appendChild(d)):(u=document.createElement("ul"),u.classList.add("search-results-list"),o.appendChild(u),m(u,c,0,10,100,i));function m(e,t,n,s,o,a){if(a!=i)return;for(var r=n;r<n+s;r++){if(r==t.length)return;p(e,t[r])}setTimeout(function(){m(e,t,n+s,s,o,a)},o)}function p(e,t){var s,i,a,r,c,l,d,u,h,m,p,g,v,b,j,y,_,w,O,x,C,E,k,A,S,F,T,o=n[t.ref],M=document.createElement("li");M.classList.add("search-results-list-item"),e.appendChild(M),p=document.createElement("a"),p.classList.add("search-result"),p.setAttribute("href",o.url),M.appendChild(p),b=document.createElement("div"),b.classList.add("search-result-title"),p.appendChild(b),v=document.createElement("div"),v.classList.add("search-result-doc"),v.innerHTML='<svg viewBox="0 0 24 24" class="search-result-icon"><use xlink:href="#svg-doc"></use></svg>',b.appendChild(v),_=document.createElement("div"),_.classList.add("search-result-doc-title"),_.innerHTML=o.doc,v.appendChild(_),C=_,o.doc!=o.title&&(v.classList.add("search-result-doc-parent"),y=document.createElement("div"),y.classList.add("search-result-section"),y.innerHTML=o.title,b.appendChild(y),C=y),F=t.matchData.metadata,w=[],m=[];for(a in F){if(O=F[a],O.title){g=O.title.position;for(r in g)w.push(g[r])}if(O.content){g=O.content.position;for(r in g){for(i=g[r],u=i[0],h=i[0]+i[1],A=!0,E=!0,r=0;r<5;r++){if(d=o.content.lastIndexOf(" ",u-2),c=o.content.lastIndexOf(". ",u-2),c>=0&&c>d){u=c+1,A=!1;break}if(d<0){u=0,A=!1;break}u=d+1}for(r=0;r<10;r++){if(d=o.content.indexOf(" ",h+1),c=o.content.indexOf(". ",h+1),c>=0&&c<d){h=c,E=!1;break}if(d<0){h=o.content.length,E=!1;break}h=d}m.push({highlight:i,previewStart:u,previewEnd:h,ellipsesBefore:A,ellipsesAfter:E})}}}if(w.length>0&&(w.sort(function(e,t){return e[0]-t[0]}),C.innerHTML="",f(C,o.title,0,o.title.length,w)),m.length>0){m.sort(function(e,t){return e.highlight[0]-t.highlight[0]});for(s=m[0],l={highlight:[s.highlight],previewStart:s.previewStart,previewEnd:s.previewEnd,ellipsesBefore:s.ellipsesBefore,ellipsesAfter:s.ellipsesAfter},x=[l],a=1;a<m.length;a++)s=m[a],l.previewEnd<s.previewStart?(l={highlight:[s.highlight],previewStart:s.previewStart,previewEnd:s.previewEnd,ellipsesBefore:s.ellipsesBefore,ellipsesAfter:s.ellipsesAfter},x.push(l)):(l.highlight.push(s.highlight),l.previewEnd=s.previewEnd,l.ellipsesAfter=s.ellipsesAfter);k=document.createElement("div"),k.classList.add("search-result-previews"),p.appendChild(k);for(T=o.content,a=0;a<Math.min(x.length,3);a++)i=x[a],j=document.createElement("div"),j.classList.add("search-result-preview"),k.appendChild(j),i.ellipsesBefore&&j.appendChild(document.createTextNode("... ")),f(j,T,i.previewStart,i.previewEnd,i.highlight),i.ellipsesAfter&&j.appendChild(document.createTextNode(" ..."))}S=document.createElement("span"),S.classList.add("search-result-rel-url"),S.innerText=o.relUrl,b.appendChild(S)}function f(e,t,n,s,o){var i,a,c,l,r=n;for(l in o)a=o[l],i=document.createElement("span"),i.innerHTML=t.substring(r,a[0]),e.appendChild(i),r=a[0]+a[1],c=document.createElement("span"),c.classList.add("search-result-highlight"),c.innerHTML=t.substring(a[0],r),e.appendChild(c);i=document.createElement("span"),i.innerHTML=t.substring(r,s),e.appendChild(i)}}e.addEvent(s,"focus",function(){setTimeout(c,0)}),e.addEvent(s,"keyup",function(e){switch(e.keyCode){case 27:s.value="";break;case 38:case 40:case 13:e.preventDefault();return}c()}),e.addEvent(s,"keydown",function(e){switch(e.keyCode){case 38:e.preventDefault();var n,s,o,t=document.querySelector(".search-result.active");t&&(t.classList.remove("active"),t.parentElement.previousSibling&&(o=t.parentElement.previousSibling.querySelector(".search-result"),o.classList.add("active")));return;case 40:e.preventDefault(),t=document.querySelector(".search-result.active"),t?t.parentElement.nextSibling&&(n=t.parentElement.nextSibling.querySelector(".search-result"),t.classList.remove("active"),n.classList.add("active")):(n=document.querySelector(".search-result"),n&&n.classList.add("active"));return;case 13:e.preventDefault(),t=document.querySelector(".search-result.active"),t?t.click():(s=document.querySelector(".search-result"),s&&s.click());return}}),e.addEvent(document,"click",function(e){e.target!=s&&r()})}e.onReady(function(){n()})})(window.jtd=window.jtd||{})