shimatta-kenkyusho/shimatta_kenkyusho/static/js/autocomplete.umd.min.js

2 lines
9.6 KiB
JavaScript
Raw Normal View History

var t,e;t=this,e=function(){function t(t,e,s){return e in t?Object.defineProperty(t,e,{value:s,enumerable:!0,configurable:!0,writable:!0}):t[e]=s,t}return class{constructor(e,{delay:s=500,clearButton:i=!0,howManyCharacters:h=1,selectFirst:r=!1,insertToInput:o=!1,showAllValues:l=!1,cache:n=!1,disableCloseOnSelect:a=!1,classGroup:c,classPreventClosing:d,classPrefix:u,onSearch:p,onResults:m=(()=>{}),onSubmit:f=(()=>{}),onOpened:L=(()=>{}),onReset:v=(()=>{}),onRender:x=(()=>{}),onClose:A=(()=>{}),noResults:g=(()=>{}),onSelectedItem:b=(()=>{})}){var y;t(this,"init",()=>{const t=this.root;this.clearbutton(),this.output(),t.addEventListener("input",this.handleInput),this.showAll&&t.addEventListener("click",this.handleInput),this.onRender({element:t,results:this.resultList})}),t(this,"cacheAct",(t,e)=>{const s=this.root;this.cache&&("update"===t?s.setAttribute(this.cacheData,e.value):"remove"===t?s.removeAttribute(this.cacheData):s.value=s.getAttribute(this.cacheData))}),t(this,"handleInput",({target:t,type:e})=>{if("true"===this.root.getAttribute("aria-expanded")&&"click"===e)return;const s=t.value.replace(this.regex,"\\$&");if(this.cacheAct("update",t),this.showAll&&"click"===e)return this.reset(),void this.searchItem(s.trim());clearTimeout(this.timeout),this.timeout=setTimeout(()=>{this.searchItem(s.trim())},this.delay)}),t(this,"output",()=>{this.setAttr(this.resultList,{id:this.outputUl,tabIndex:"0",role:"listbox"}),this.setAttr(this.resultWrap,{addClass:this.prefix+"-wrapper"}),this.resultWrap.insertAdjacentElement("beforeend",this.resultList),this.root.parentNode.insertBefore(this.resultWrap,this.root.nextSibling)}),t(this,"reset",()=>{var t;this.setAttr(this.root,{"aria-owns":this.id+"-list","aria-expanded":"false","aria-autocomplete":"list","aria-activedescendant":"",role:"combobox",removeClass:"auto-expanded"}),this.resultWrap.classList.remove(this.isActive),this.scrollResultsToTop(),(0==(null===(t=this.matches)||void 0===t?void 0:t.length)&&!this.toInput||this.showAll)&&(this.resultList.innerHTML=""),this.index=this.selectFirst?0:-1,this.onClose()}),t(this,"scrollResultsToTop",()=>{this.resultList.scrollTop=this.resultList.offsetTop-this.resultWrap.offsetHeight}),t(this,"searchItem",t=>{this.value=t,this.onLoading(!0),this.showBtn(),0==t.length&&this.clearButton&&this.cBtn.classList.add("hidden"),this.characters>t.length&&!this.showAll?this.onLoading():this.onSearch({currentValue:t,element:this.root}).then(e=>{const s=this.root.value.length,i=e.length;this.matches=Array.isArray(e)?[...e]:JSON.parse(JSON.stringify(e)),this.onLoading(),this.error(),0==i&&0==s&&this.cBtn.classList.add("hidden"),0==i&&s?(this.root.classList.remove("auto-expanded"),this.reset(),this.noResults({element:this.root,currentValue:t,template:this.results}),this.events()):(i>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(e))&&(this.index=this.selectFirst?0:-1,this.results(),this.events())}).catch(()=>{this.onLoading(),this.reset()})}),t(this,"onLoading",t=>this.root.parentNode.classList[t?"add":"remove"](this.isLoading)),t(this,"error",()=>this.root.classList.remove(this.err)),t(this,"events",()=>{this.root.addEventListener("keydown",this.handleKeys),this.root.addEventListener("click",this.handleShowItems),["mousemove","click"].map(t=>{this.resultList.addEventListener(t,this.handleMouse)}),document.addEventListener("click",this.handleDocClick)}),t(this,"results",t=>{this.setAttr(this.root,{"aria-expanded":"true",addClass:this.prefix+"-expanded"}),this.resultList.innerHTML=0===this.matches.length?this.onResults({currentValue:this.value,matches:0,template:t}):this.onResults({currentValue:this.value,matches:this.matches,classGroup:this.classGroup}),this.resultWrap.classList.add(this.isActive),this.scrollResultsToTop();const e=this.classGroup?`:not(.${this.classGroup})`:"";this.itemsLi=document.querySelectorAll(`#${this.outputUl} > li${e}`),this.selectFirstEl(),this.onOpened({type:"results",element:this.root,results:this.resultList}),this.addAria()}),t(this,"handleDocClick",({target:t})=>{let e=null;(t.closest("ul")&&this.disable||t.closest(".