You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2 lines
6.3 KiB
JavaScript

var a,b;a=this,b=function(){"use strict";function i(e,t){for(var n=0;n<t.length;n++){var i=t[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(e,i.key,i)}}function s(e){return e.innerHTML=""}function d(t,e,n,i,o,r){i({event:t,query:e instanceof HTMLInputElement?e.value:e.innerHTML,matches:o.matches,results:o.list.map(function(e){return e.value}),selection:o.list.find(function(e){return t.keyCode===f?e.index===Number(r.getAttribute(a)):"mousedown"===t.type?e.index===Number(t.currentTarget.getAttribute(a)):void 0})}),s(n)}function e(e,t){t=t||{bubbles:!1,cancelable:!1,detail:void 0};var n=document.createEvent("CustomEvent");return n.initCustomEvent(e,t.bubbles,t.cancelable,t.detail),n}var a="data-id",n="autoComplete_list",l="autoComplete_result",t="autoComplete_highlighted",h="autoComplete_selected",f=13,v=38,m=40,Q=function(e){return"string"==typeof e?document.querySelector(e):e()},U=function(e){var t=document.createElement(e.element);return t.setAttribute("id",n),e.container&&e.container(t),e.destination.insertAdjacentElement(e.position,t),t},u=function(e){return"<span class=".concat(t,">").concat(e,"</span>")},c=function(e,o,r){var s=document.createDocumentFragment();o.forEach(function(e,t){var n=document.createElement(r.element),i=o[t].index;n.setAttribute(a,i),n.setAttribute("class",l),r.content?r.content(e,n):n.innerHTML=e.match||e,s.appendChild(n)}),e.appendChild(s)},p=function(t,n,i,o){function r(e){c.classList.remove(h),a=1===e?c.nextSibling:c.previousSibling}function s(e){(c=e).classList.add(h)}var a,l=n.childNodes,u=l.length-1,c=void 0;t.onkeydown=function(e){if(0<l.length)switch(e.keyCode){case v:c?(r(0),s(a||l[u])):s(l[u]);break;case m:c?(r(1),s(a||l[0])):s(l[0]);break;case f:c&&d(e,t,n,i,o,c)}},l.forEach(function(e){e.onmousedown=function(e){return d(e,t,n,i,o)}})},g=s;e.prototype=window.Event.prototype;var y={CustomEventWrapper:"function"==typeof window.CustomEvent&&window.CustomEvent||e,initElementClosestPolyfill:function(){Element.prototype.matches||(Element.prototype.matches=Element.prototype.msMatchesSelector||Element.prototype.webkitMatchesSelector),Element.prototype.closest||(Element.prototype.closest=function(e){var t=this;do{if(t.matches(e))return t;t=t.parentElement||t.parentNode}while(null!==t&&1===t.nodeType);return null})}};return function(){function K(e){!function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,K);var t=e.selector,n=void 0===t?"#autoComplete":t,i=e.data,o=i.key,r=i.src,s=i.cache,a=void 0===s||s,l=e.query,u=e.trigger,c=(u=void 0===u?{}:u).event,d=void 0===c?["input"]:c,h=u.condition,f=void 0!==h&&h,v=e.searchEngine,m=void 0===v?"strict":v,p=e.threshold,g=void 0===p?0:p,y=e.debounce,b=void 0===y?0:y,E=e.resultsList,w=(E=void 0===E?{}:E).render,C=void 0!==w&&w,L=E.container,k=void 0!==L&&L,x=E.destination,S=E.position,T=void 0===S?"afterend":S,M=E.element,R=void 0===M?"ul":M,q=E.navigation,H=void 0!==q&&q,A=e.sort,P=void 0!==A&&A,I=e.placeHolder,j=e.maxResults,N=void 0===j?5:j,_=e.resultItem,V=(_=void 0===_?{}:_).content,W=void 0!==V&&V,D=_.element,F=void 0===D?"li":D,O=e.noResults,z=e.highlight,B=void 0!==z&&z,G=e.onSelection,J=C?U({container:k,destination:x||Q(n),position:T,element:R}):null;this.selector=n,this.data={src:function(){return"function"==typeof r?r():r},key:o,cache:a},this.query=l,this.trigger={event:d,condition:f},this.searchEngine="loose"===m?"loose":"function"==typeof m?m:"strict",this.threshold=g,this.debounce=b,this.resultsList={render:C,view:J,navigation:H},this.sort=P,this.placeHolder=I,this.maxResults=N,this.resultItem={content:W,element:F},this.noResults=O,this.highlight=B,this.onSelection=G,this.init()}return function(e,t,n){t&&i(e.prototype,t),n&&i(e,n)}(K,[{key:"search",value:function(e,t){var n=t.toLowerCase();if("loose"===this.searchEngine){e=e.replace(/ /g,"");for(var i=[],o=0,r=0;r<n.length;r++){var s=t[r];o<e.length&&n[r]===e[o]&&(s=this.highlight?u(s):s,o++),i.push(s)}return o===e.length&&i.join("")}if(n.includes(e))return e=new RegExp("".concat(e),"i").exec