Zulma-Theme/static/js/zulma_search.js

2 lines
2.7 KiB
JavaScript
Raw Normal View History

!function(e){var t={};function n(r){if(t[r])return t[r].exports;var o=t[r]={i:r,l:!1,exports:{}};return e[r].call(o.exports,o,o.exports,n),o.l=!0,o.exports}n.m=e,n.c=t,n.d=function(e,t,r){n.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:r})},n.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},n.t=function(e,t){if(1&t&&(e=n(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var r=Object.create(null);if(n.r(r),Object.defineProperty(r,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var o in e)n.d(r,o,function(t){return e[t]}.bind(null,o));return r},n.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return n.d(t,"a",t),t},n.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},n.p="",n(n.s=1)}([,function(e,t){function n(e,t){return'<div class="search-results__item box">'+'<a href="'.concat(e.ref,'">').concat(e.doc.title,"</a>")+"<div>".concat(function(e,t){var n=t.map((function(e){return elasticlunr.stemmer(e.toLowerCase())})),r=!1,o=0,u=[],i=e.toLowerCase().split(". ");for(var l in i){var a=i[l].split(" "),c=8;for(var s in a){if((g=a[s]).length>0){for(var d in n)elasticlunr.stemmer(g).startsWith(n[d])&&(c=40,r=!0);u.push([g,c,o]),c=2}o+=g.length,o+=1}o+=1}if(0===u.length)return e;var f=[],p=Math.min(u.length,30),m=0;for(l=0;l<p;l++)m+=u[l][1];for(f.push(m),l=0;l<u.length-p;l++)m-=u[l][1],m+=u[l+p][1],f.push(m);var v=0;if(r){var h=0;for(l=f.length-1;l>=0;l--)f[l]>h&&(h=f[l],v=l)}var y=[],b=u[v][2];for(l=v;l<v+p;l++){var g;b<(g=u[l])[2]&&(y.push(e.substring(b,g[2])),b=g[2]),40===g[1]&&y.push("<b>"),b=g[2]+g[0].length,y.push(e.substring(g[2],b)),40===g[1]&&y.push("</b>")}return y.push("…"),y.join("")}(e.doc.body,t),"</div>")+"</div>"}function r(){var e,t,r,o=document.getElementById("search"),u=document.querySelector(".search-results"),i=document.querySelector(".search-results__items"),l={bool:"AND",fields:{title:{boost:2},body:{boost:1}}},a=elasticlunr.Index.load(window.searchIndex);o.addEventListener("keyup",(e=function(){var e=o.value.trim();if(a&&(u.style.display=""===e?"none":"block",i.innerHTML="",""!==e)){var t=a.search(e,l);if(0!==t.length){e;for(var r=0;r<Math.min(t.length,10);r++){var c=document.createElement("li");c.innerHTML=n(t[r],e.split(" ")),i.appendChild(c)}}else u.style.display="none"}},t=150,function(){var n=this,o=arguments;clearTimeout(r),r=setTimeout((function(){r=null,e.apply(n,o)}),t)}))}"complete"===document.readyState||"loading"!==document.readyState&&!document.documentElement.doScroll?r():document.addEventListener("DOMContentLoaded",r)}]);
//# sourceMappingURL=zulma_search.js.map