-
Notifications
You must be signed in to change notification settings - Fork 0
/
accordion-search.min.js
1 lines (1 loc) · 24.2 KB
/
accordion-search.min.js
1
var AccordionSearch;(()=>{var e={976:(e,t,s)=>{"use strict";s.d(t,{Z:()=>a});class i{constructor(e,t=!0,s=[],i=5e3){this.ctx=e,this.iframes=t,this.exclude=s,this.iframesTimeout=i}static matches(e,t){const s="string"==typeof t?[t]:t,i=e.matches||e.matchesSelector||e.msMatchesSelector||e.mozMatchesSelector||e.oMatchesSelector||e.webkitMatchesSelector;if(i){let t=!1;return s.every((s=>!i.call(e,s)||(t=!0,!1))),t}return!1}getContexts(){let e,t=[];return e=void 0!==this.ctx&&this.ctx?NodeList.prototype.isPrototypeOf(this.ctx)?Array.prototype.slice.call(this.ctx):Array.isArray(this.ctx)?this.ctx:"string"==typeof this.ctx?Array.prototype.slice.call(document.querySelectorAll(this.ctx)):[this.ctx]:[],e.forEach((e=>{const s=t.filter((t=>t.contains(e))).length>0;-1!==t.indexOf(e)||s||t.push(e)})),t}getIframeContents(e,t,s=(()=>{})){let i;try{const t=e.contentWindow;if(i=t.document,!t||!i)throw new Error("iframe inaccessible")}catch(e){s()}i&&t(i)}isIframeBlank(e){const t="about:blank",s=e.getAttribute("src").trim();return e.contentWindow.location.href===t&&s!==t&&s}observeIframeLoad(e,t,s){let i=!1,n=null;const o=()=>{if(!i){i=!0,clearTimeout(n);try{this.isIframeBlank(e)||(e.removeEventListener("load",o),this.getIframeContents(e,t,s))}catch(e){s()}}};e.addEventListener("load",o),n=setTimeout(o,this.iframesTimeout)}onIframeReady(e,t,s){try{"complete"===e.contentWindow.document.readyState?this.isIframeBlank(e)?this.observeIframeLoad(e,t,s):this.getIframeContents(e,t,s):this.observeIframeLoad(e,t,s)}catch(e){s()}}waitForIframes(e,t){let s=0;this.forEachIframe(e,(()=>!0),(e=>{s++,this.waitForIframes(e.querySelector("html"),(()=>{--s||t()}))}),(e=>{e||t()}))}forEachIframe(e,t,s,n=(()=>{})){let o=e.querySelectorAll("iframe"),r=o.length,a=0;o=Array.prototype.slice.call(o);const c=()=>{--r<=0&&n(a)};r||c(),o.forEach((e=>{i.matches(e,this.exclude)?c():this.onIframeReady(e,(i=>{t(e)&&(a++,s(i)),c()}),c)}))}createIterator(e,t,s){return document.createNodeIterator(e,t,s,!1)}createInstanceOnIframe(e){return new i(e.querySelector("html"),this.iframes)}compareNodeIframe(e,t,s){if(e.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_PRECEDING){if(null===t)return!0;if(t.compareDocumentPosition(s)&Node.DOCUMENT_POSITION_FOLLOWING)return!0}return!1}getIteratorNode(e){const t=e.previousNode();let s;return s=(null===t||e.nextNode())&&e.nextNode(),{prevNode:t,node:s}}checkIframeFilter(e,t,s,i){let n=!1,o=!1;return i.forEach(((e,t)=>{e.val===s&&(n=t,o=e.handled)})),this.compareNodeIframe(e,t,s)?(!1!==n||o?!1===n||o||(i[n].handled=!0):i.push({val:s,handled:!0}),!0):(!1===n&&i.push({val:s,handled:!1}),!1)}handleOpenIframes(e,t,s,i){e.forEach((e=>{e.handled||this.getIframeContents(e.val,(e=>{this.createInstanceOnIframe(e).forEachNode(t,s,i)}))}))}iterateThroughNodes(e,t,s,i,n){const o=this.createIterator(t,e,i);let r,a,c=[],l=[],h=()=>(({prevNode:a,node:r}=this.getIteratorNode(o)),r);for(;h();)this.iframes&&this.forEachIframe(t,(e=>this.checkIframeFilter(r,a,e,c)),(t=>{this.createInstanceOnIframe(t).forEachNode(e,(e=>l.push(e)),i)})),l.push(r);l.forEach((e=>{s(e)})),this.iframes&&this.handleOpenIframes(c,e,s,i),n()}forEachNode(e,t,s,i=(()=>{})){const n=this.getContexts();let o=n.length;o||i(),n.forEach((n=>{const r=()=>{this.iterateThroughNodes(e,n,t,s,(()=>{--o<=0&&i()}))};this.iframes?this.waitForIframes(n,r):r()}))}}class n{constructor(e){this.ctx=e,this.ie=!1;const t=window.navigator.userAgent;(t.indexOf("MSIE")>-1||t.indexOf("Trident")>-1)&&(this.ie=!0)}set opt(e){this._opt=Object.assign({},{element:"",className:"",exclude:[],iframes:!1,iframesTimeout:5e3,separateWordSearch:!0,diacritics:!0,synonyms:{},accuracy:"partially",acrossElements:!1,caseSensitive:!1,ignoreJoiners:!1,ignoreGroups:0,ignorePunctuation:[],wildcards:"disabled",each:()=>{},noMatch:()=>{},filter:()=>!0,done:()=>{},debug:!1,log:window.console},e)}get opt(){return this._opt}get iterator(){return new i(this.ctx,this.opt.iframes,this.opt.exclude,this.opt.iframesTimeout)}log(e,t="debug"){const s=this.opt.log;this.opt.debug&&"object"==typeof s&&"function"==typeof s[t]&&s[t](`mark.js: ${e}`)}escapeStr(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")}createRegExp(e){return"disabled"!==this.opt.wildcards&&(e=this.setupWildcardsRegExp(e)),e=this.escapeStr(e),Object.keys(this.opt.synonyms).length&&(e=this.createSynonymsRegExp(e)),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),this.opt.diacritics&&(e=this.createDiacriticsRegExp(e)),e=this.createMergedBlanksRegExp(e),(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.createJoinersRegExp(e)),"disabled"!==this.opt.wildcards&&(e=this.createWildcardsRegExp(e)),this.createAccuracyRegExp(e)}createSynonymsRegExp(e){const t=this.opt.synonyms,s=this.opt.caseSensitive?"":"i",i=this.opt.ignoreJoiners||this.opt.ignorePunctuation.length?"\0":"";for(let n in t)if(t.hasOwnProperty(n)){const o=t[n],r="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(n):this.escapeStr(n),a="disabled"!==this.opt.wildcards?this.setupWildcardsRegExp(o):this.escapeStr(o);""!==r&&""!==a&&(e=e.replace(new RegExp(`(${this.escapeStr(r)}|${this.escapeStr(a)})`,`gm${s}`),i+`(${this.processSynomyms(r)}|`+`${this.processSynomyms(a)})`+i))}return e}processSynomyms(e){return(this.opt.ignoreJoiners||this.opt.ignorePunctuation.length)&&(e=this.setupIgnoreJoinersRegExp(e)),e}setupWildcardsRegExp(e){return(e=e.replace(/(?:\\)*\?/g,(e=>"\\"===e.charAt(0)?"?":""))).replace(/(?:\\)*\*/g,(e=>"\\"===e.charAt(0)?"*":""))}createWildcardsRegExp(e){let t="withSpaces"===this.opt.wildcards;return e.replace(/\u0001/g,t?"[\\S\\s]?":"\\S?").replace(/\u0002/g,t?"[\\S\\s]*?":"\\S*")}setupIgnoreJoinersRegExp(e){return e.replace(/[^(|)\\]/g,((e,t,s)=>{let i=s.charAt(t+1);return/[(|)\\]/.test(i)||""===i?e:e+"\0"}))}createJoinersRegExp(e){let t=[];const s=this.opt.ignorePunctuation;return Array.isArray(s)&&s.length&&t.push(this.escapeStr(s.join(""))),this.opt.ignoreJoiners&&t.push("\\u00ad\\u200b\\u200c\\u200d"),t.length?e.split(/\u0000+/).join(`[${t.join("")}]*`):e}createDiacriticsRegExp(e){const t=this.opt.caseSensitive?"":"i",s=this.opt.caseSensitive?["aàáảãạăằắẳẵặâầấẩẫậäåāą","AÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćč","CÇĆČ","dđď","DĐĎ","eèéẻẽẹêềếểễệëěēę","EÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïī","IÌÍỈĨỊÎÏĪ","lł","LŁ","nñňń","NÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøō","OÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rř","RŘ","sšśșş","SŠŚȘŞ","tťțţ","TŤȚŢ","uùúủũụưừứửữựûüůū","UÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿ","YÝỲỶỸỴŸ","zžżź","ZŽŻŹ"]:["aàáảãạăằắẳẵặâầấẩẫậäåāąAÀÁẢÃẠĂẰẮẲẴẶÂẦẤẨẪẬÄÅĀĄ","cçćčCÇĆČ","dđďDĐĎ","eèéẻẽẹêềếểễệëěēęEÈÉẺẼẸÊỀẾỂỄỆËĚĒĘ","iìíỉĩịîïīIÌÍỈĨỊÎÏĪ","lłLŁ","nñňńNÑŇŃ","oòóỏõọôồốổỗộơởỡớờợöøōOÒÓỎÕỌÔỒỐỔỖỘƠỞỠỚỜỢÖØŌ","rřRŘ","sšśșşSŠŚȘŞ","tťțţTŤȚŢ","uùúủũụưừứửữựûüůūUÙÚỦŨỤƯỪỨỬỮỰÛÜŮŪ","yýỳỷỹỵÿYÝỲỶỸỴŸ","zžżźZŽŻŹ"];let i=[];return e.split("").forEach((n=>{s.every((s=>{if(-1!==s.indexOf(n)){if(i.indexOf(s)>-1)return!1;e=e.replace(new RegExp(`[${s}]`,`gm${t}`),`[${s}]`),i.push(s)}return!0}))})),e}createMergedBlanksRegExp(e){return e.replace(/[\s]+/gim,"[\\s]+")}createAccuracyRegExp(e){let t=this.opt.accuracy,s="string"==typeof t?t:t.value,i="string"==typeof t?[]:t.limiters,n="";switch(i.forEach((e=>{n+=`|${this.escapeStr(e)}`})),s){case"partially":default:return`()(${e})`;case"complementary":return n="\\s"+(n||this.escapeStr("!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~¡¿")),`()([^${n}]*${e}[^${n}]*)`;case"exactly":return`(^|\\s${n})(${e})(?=$|\\s${n})`}}getSeparatedKeywords(e){let t=[];return e.forEach((e=>{this.opt.separateWordSearch?e.split(" ").forEach((e=>{e.trim()&&-1===t.indexOf(e)&&t.push(e)})):e.trim()&&-1===t.indexOf(e)&&t.push(e)})),{keywords:t.sort(((e,t)=>t.length-e.length)),length:t.length}}isNumeric(e){return Number(parseFloat(e))==e}checkRanges(e){if(!Array.isArray(e)||"[object Object]"!==Object.prototype.toString.call(e[0]))return this.log("markRanges() will only accept an array of objects"),this.opt.noMatch(e),[];const t=[];let s=0;return e.sort(((e,t)=>e.start-t.start)).forEach((e=>{let{start:i,end:n,valid:o}=this.callNoMatchOnInvalidRanges(e,s);o&&(e.start=i,e.length=n-i,t.push(e),s=n)})),t}callNoMatchOnInvalidRanges(e,t){let s,i,n=!1;return e&&void 0!==e.start?(s=parseInt(e.start,10),i=s+parseInt(e.length,10),this.isNumeric(e.start)&&this.isNumeric(e.length)&&i-t>0&&i-s>0?n=!0:(this.log(`Ignoring invalid or overlapping range: ${JSON.stringify(e)}`),this.opt.noMatch(e))):(this.log(`Ignoring invalid range: ${JSON.stringify(e)}`),this.opt.noMatch(e)),{start:s,end:i,valid:n}}checkWhitespaceRanges(e,t,s){let i,n=!0,o=s.length,r=t-o,a=parseInt(e.start,10)-r;return a=a>o?o:a,i=a+parseInt(e.length,10),i>o&&(i=o,this.log(`End range automatically set to the max value of ${o}`)),a<0||i-a<0||a>o||i>o?(n=!1,this.log(`Invalid range: ${JSON.stringify(e)}`),this.opt.noMatch(e)):""===s.substring(a,i).replace(/\s+/g,"")&&(n=!1,this.log("Skipping whitespace only range: "+JSON.stringify(e)),this.opt.noMatch(e)),{start:a,end:i,valid:n}}getTextNodes(e){let t="",s=[];this.iterator.forEachNode(NodeFilter.SHOW_TEXT,(e=>{s.push({start:t.length,end:(t+=e.textContent).length,node:e})}),(e=>this.matchesExclude(e.parentNode)?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT),(()=>{e({value:t,nodes:s})}))}matchesExclude(e){return i.matches(e,this.opt.exclude.concat(["script","style","title","head","html"]))}wrapRangeInTextNode(e,t,s){const i=this.opt.element?this.opt.element:"mark",n=e.splitText(t),o=n.splitText(s-t);let r=document.createElement(i);return r.setAttribute("data-markjs","true"),this.opt.className&&r.setAttribute("class",this.opt.className),r.textContent=n.textContent,n.parentNode.replaceChild(r,n),o}wrapRangeInMappedTextNode(e,t,s,i,n){e.nodes.every(((o,r)=>{const a=e.nodes[r+1];if(void 0===a||a.start>t){if(!i(o.node))return!1;const a=t-o.start,c=(s>o.end?o.end:s)-o.start,l=e.value.substr(0,o.start),h=e.value.substr(c+o.start);if(o.node=this.wrapRangeInTextNode(o.node,a,c),e.value=l+h,e.nodes.forEach(((t,s)=>{s>=r&&(e.nodes[s].start>0&&s!==r&&(e.nodes[s].start-=c),e.nodes[s].end-=c)})),s-=c,n(o.node.previousSibling,o.start),!(s>o.end))return!1;t=o.end}return!0}))}wrapMatches(e,t,s,i,n){const o=0===t?0:t+1;this.getTextNodes((t=>{t.nodes.forEach((t=>{let n;for(t=t.node;null!==(n=e.exec(t.textContent))&&""!==n[o];){if(!s(n[o],t))continue;let r=n.index;if(0!==o)for(let e=1;e<o;e++)r+=n[e].length;t=this.wrapRangeInTextNode(t,r,r+n[o].length),i(t.previousSibling),e.lastIndex=0}})),n()}))}wrapMatchesAcrossElements(e,t,s,i,n){const o=0===t?0:t+1;this.getTextNodes((t=>{let r;for(;null!==(r=e.exec(t.value))&&""!==r[o];){let n=r.index;if(0!==o)for(let e=1;e<o;e++)n+=r[e].length;const a=n+r[o].length;this.wrapRangeInMappedTextNode(t,n,a,(e=>s(r[o],e)),((t,s)=>{e.lastIndex=s,i(t)}))}n()}))}wrapRangeFromIndex(e,t,s,i){this.getTextNodes((n=>{const o=n.value.length;e.forEach(((e,i)=>{let{start:r,end:a,valid:c}=this.checkWhitespaceRanges(e,o,n.value);c&&this.wrapRangeInMappedTextNode(n,r,a,(s=>t(s,e,n.value.substring(r,a),i)),(t=>{s(t,e)}))})),i()}))}unwrapMatches(e){const t=e.parentNode;let s=document.createDocumentFragment();for(;e.firstChild;)s.appendChild(e.removeChild(e.firstChild));t.replaceChild(s,e),this.ie?this.normalizeTextNode(t):t.normalize()}normalizeTextNode(e){if(e){if(3===e.nodeType)for(;e.nextSibling&&3===e.nextSibling.nodeType;)e.nodeValue+=e.nextSibling.nodeValue,e.parentNode.removeChild(e.nextSibling);else this.normalizeTextNode(e.firstChild);this.normalizeTextNode(e.nextSibling)}}markRegExp(e,t){this.opt=t,this.log(`Searching with expression "${e}"`);let s=0,i="wrapMatches";this.opt.acrossElements&&(i="wrapMatchesAcrossElements"),this[i](e,this.opt.ignoreGroups,((e,t)=>this.opt.filter(t,e,s)),(e=>{s++,this.opt.each(e)}),(()=>{0===s&&this.opt.noMatch(e),this.opt.done(s)}))}mark(e,t){this.opt=t;let s=0,i="wrapMatches";const{keywords:n,length:o}=this.getSeparatedKeywords("string"==typeof e?[e]:e),r=this.opt.caseSensitive?"":"i",a=e=>{let t=new RegExp(this.createRegExp(e),`gm${r}`),c=0;this.log(`Searching with expression "${t}"`),this[i](t,1,((t,i)=>this.opt.filter(i,e,s,c)),(e=>{c++,s++,this.opt.each(e)}),(()=>{0===c&&this.opt.noMatch(e),n[o-1]===e?this.opt.done(s):a(n[n.indexOf(e)+1])}))};this.opt.acrossElements&&(i="wrapMatchesAcrossElements"),0===o?this.opt.done(s):a(n[0])}markRanges(e,t){this.opt=t;let s=0,i=this.checkRanges(e);i&&i.length?(this.log("Starting to mark with the following ranges: "+JSON.stringify(i)),this.wrapRangeFromIndex(i,((e,t,s,i)=>this.opt.filter(e,t,s,i)),((e,t)=>{s++,this.opt.each(e,t)}),(()=>{this.opt.done(s)}))):this.opt.done(s)}unmark(e){this.opt=e;let t=this.opt.element?this.opt.element:"*";t+="[data-markjs]",this.opt.className&&(t+=`.${this.opt.className}`),this.log(`Removal selector "${t}"`),this.iterator.forEachNode(NodeFilter.SHOW_ELEMENT,(e=>{this.unwrapMatches(e)}),(e=>{const s=i.matches(e,t),n=this.matchesExclude(e);return!s||n?NodeFilter.FILTER_REJECT:NodeFilter.FILTER_ACCEPT}),this.opt.done)}}function o(e){const t=new n(e);return this.mark=(e,s)=>(t.mark(e,s),this),this.markRegExp=(e,s)=>(t.markRegExp(e,s),this),this.markRanges=(e,s)=>(t.markRanges(e,s),this),this.unmark=e=>(t.unmark(e),this),this}class r{static slideUp(e,t=500){e.style.height=e.offsetHeight+"px",e.offsetHeight,e.style.overflow="hidden",e.style.height=0,e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",setTimeout((()=>{e.classList.add("as-d-none"),e.style.removeProperty("height"),e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property")}),t)}static slideDown(e,t=500){e.classList.remove("as-d-none");let s=e.offsetHeight;e.style.height=0,e.style.overflow="hidden",e.style.paddingTop=0,e.style.paddingBottom=0,e.style.marginTop=0,e.style.marginBottom=0,e.offsetHeight,e.style.transitionProperty="height, margin, padding",e.style.transitionDuration=t+"ms",e.style.height=s+"px",e.style.removeProperty("padding-top"),e.style.removeProperty("padding-bottom"),e.style.removeProperty("margin-top"),e.style.removeProperty("margin-bottom"),setTimeout((()=>{e.style.removeProperty("height"),e.style.removeProperty("overflow"),e.style.removeProperty("transition-duration"),e.style.removeProperty("transition-property")}),t)}}class a{constructor(e,t={}){if(this.ctx=e,this.config={...window.AccordionSearchConfig},this.config=Object.assign(this.config,t),this.elementSearchInput=this.ctx.querySelector(".as-search__input"),this.elementSearchBtnSearch=this.ctx.querySelector(".as-search__search_btn"),this.elementSearchBtnClear=this.ctx.querySelector(".as-search__clear_btn"),this.elementSearchResult=this.ctx.querySelector(".as-search-result"),this.elementAccordions=this.ctx.querySelectorAll(".as-accordion"),this.instanceMark=new o(this.config.searchOnlyTitle?this.ctx.querySelectorAll(".as-accordion .as-accordion__title"):this.elementAccordions),this.itemsToShow=[],this.searchActivated=!0,this.initHtml(),this.initEvent(),this.config.queryUrl){const e=new URLSearchParams(window.location.search).get(this.config.queryUrlName);null!=e&&(this.elementSearchInput.value=e,this.elementSearchInput.dispatchEvent(new KeyboardEvent("keyup")),this.config.searchOnClick&&this.elementSearchBtnSearch.click())}this.config.pagination&&(this.config.pagination=this.config.paginationLimit>0,this.config.pagination&&this.pagination())}initHtml(){for(const e of this.elementAccordions)e.querySelector(".as-accordion__content").classList.add("as-d-none"),e.querySelector(".as-accordion__title").innerHTML=`<span class="as-accordion__title-icon">${this.config.iconOpen}</span>`+e.querySelector(".as-accordion__title").innerHTML;if(this.elementSearchBtnSearch.innerHTML=this.config.iconSearch,this.elementSearchBtnClear.innerHTML=this.config.iconClear,this.elementSearchResult.classList.add("as-d-none"),this.elementSearchBtnSearch.classList.add("as-d-none"),this.elementSearchBtnClear.classList.add("as-d-none"),this.config.searchOnClick&&this.elementSearchBtnSearch.classList.add("as-cursor-pointer"),this.config.suggestionBox&&Array.isArray(this.config.suggestionBoxKeywords)&&this.config.suggestionBoxKeywords.length>0){let e=document.createElement("div");e.classList.add("as-search-suggestion-box");let t=document.createElement("p");t.classList.add("as-search-suggestion-box__title"),t.innerHTML=this.config.suggestionBoxTitle,e.appendChild(t);let s=document.createElement("div");s.classList.add("as-search-suggestion-box__items");for(const e of this.config.suggestionBoxKeywords){if(e.length<=2)continue;let t=document.createElement("p");t.innerText=e,t.addEventListener("click",(e=>this.onSuggestion(e.currentTarget))),s.appendChild(t)}e.appendChild(s),this.ctx.querySelector(".as-search-container").after(e)}if(this.config.btnOpenCloseAll){let e=document.createElement("div");e.classList.add("as-accordion-btn-all");let t=document.createElement("small");t.classList.add("as-accordion-btn-all__open"),t.innerHTML=this.config.iconOpenAll,e.appendChild(t);let s=document.createElement("small");s.classList.add("as-accordion-btn-all__close"),s.innerHTML=this.config.iconCloseAll,e.appendChild(s),this.elementSearchResult.after(e)}if(0!=this.config.itemsOpened)if(Array.isArray(this.config.itemsOpened))for(let e=0;e<this.config.itemsOpened.length;e++)null!=this.elementAccordions[this.config.itemsOpened[e]]&&this.openAccordion(this.elementAccordions[this.config.itemsOpened[e]]);else if(Number.isInteger(this.config.itemsOpened)&&this.config.itemsOpened<this.elementAccordions.length)for(let e=0;e<this.config.itemsOpened;e++)null!=this.elementAccordions[e]&&this.openAccordion(this.elementAccordions[e]);else"all"==this.config.itemsOpened&&this.onAll()}initEvent(){let e=this.ctx.querySelectorAll(".as-accordion__title");for(const t of e)t.addEventListener("click",(e=>{e.preventDefault();const t=e.currentTarget.parentElement;t.querySelector(".as-accordion__content").classList.contains("as-d-none")?this.openAccordion(t):this.closeAccordion(t)}));this.elementSearchInput.addEventListener("keyup",(e=>{if(!this.searchActivated)return!1;e.target.value.length<=2?this.reset():(this.elementSearchBtnSearch.classList.remove("as-d-none"),this.elementSearchBtnClear.classList.remove("as-d-none"),this.config.searchOnClick&&"Enter"!=e.key||this.search())})),this.elementSearchInput.addEventListener("paste",(e=>{this.elementSearchInput.dispatchEvent(new KeyboardEvent("keyup"))})),this.config.searchOnClick&&this.elementSearchBtnSearch.addEventListener("click",(e=>{this.search()})),this.elementSearchBtnClear.addEventListener("click",(e=>{if(!this.searchActivated)return!1;this.elementSearchInput.value="",this.reset()})),this.config.btnOpenCloseAll&&(this.ctx.querySelector(".as-accordion-btn-all__open").addEventListener("click",(e=>this.onAll())),this.ctx.querySelector(".as-accordion-btn-all__close").addEventListener("click",(e=>this.onAll(!1))))}openAccordion(e){r.slideDown(e.querySelector(".as-accordion__content")),e.querySelector(".as-accordion__title-icon").innerHTML=this.config.iconClose}closeAccordion(e){r.slideUp(e.querySelector(".as-accordion__content")),e.querySelector(".as-accordion__title-icon").innerHTML=this.config.iconOpen}search(){if(!this.searchActivated)return!1;this.config.loader&&this.loader(!0),this.itemsToShow=[],this.instanceMark.unmark(),this.instanceMark.mark(this.elementSearchInput.value,{separateWordSearch:!1,caseSensitive:this.config.caseSensitive,each:e=>this.addItemToShow(e),done:e=>this.result(e)})}reset(){this.config.loader&&this.loader(!0),this.elementSearchBtnSearch.classList.add("as-d-none"),this.elementSearchBtnClear.classList.add("as-d-none"),this.elementSearchResult.classList.add("as-d-none"),this.instanceMark.unmark();for(const e of this.elementAccordions)e.classList.remove("as-d-none"),e.querySelector(".as-accordion__content").classList.contains("as-d-none")||this.closeAccordion(e),e.classList.contains("as-accordion-pagination-hide")&&e.classList.remove("as-accordion-pagination-hide");this.config.btnOpenCloseAll&&this.ctx.querySelector(".as-accordion-btn-all").classList.remove("as-d-none"),this.config.pagination&&this.pagination(),this.config.loader&&this.loader(!1)}result(e){const t=0==e?this.config.msgNoResult:1==e?this.config.msgItemFound:this.config.msgItemsFound;this.elementSearchResult.innerHTML=e+" "+t,this.elementSearchResult.classList.remove("as-d-none");for(const e of this.elementAccordions)this.itemsToShow.includes(e)?e.classList.remove("as-d-none"):e.classList.add("as-d-none"),e.classList.contains("as-accordion-pagination-hide")&&e.classList.remove("as-accordion-pagination-hide");for(const e of this.itemsToShow)this.openAccordion(e);this.config.btnOpenCloseAll&&(0==e?this.ctx.querySelector(".as-accordion-btn-all").classList.add("as-d-none"):this.ctx.querySelector(".as-accordion-btn-all").classList.remove("as-d-none")),this.config.pagination&&this.pagination(),this.config.loader&&this.loader(!1)}addItemToShow(e){const t=e.closest(".as-accordion");this.itemsToShow.includes(t)||this.itemsToShow.push(t)}onAll(e=!0){for(const t of this.elementAccordions){const s=t.querySelector(".as-accordion__content").classList.contains("as-d-none");e&&s?this.openAccordion(t):e||s||this.closeAccordion(t)}}onSuggestion(e){if(!this.searchActivated)return!1;this.elementSearchInput.value=e.textContent,this.elementSearchInput.dispatchEvent(new KeyboardEvent("keyup")),this.config.searchOnClick&&this.elementSearchBtnSearch.click()}pagination(e=0){let t=this.ctx.querySelector(".as-accordion-pagination");null==t?(t=document.createElement("div"),t.classList.add("as-accordion-pagination")):t.querySelectorAll("*").forEach((e=>e.remove()));const s=Math.ceil(this.ctx.querySelectorAll(".as-accordion:not(.as-d-none)").length/this.config.paginationLimit);let i;for(let n=0;n<s;n++){let s=document.createElement("p");s.innerText=n+1,e==n?(i=s,s.classList.add("as-accordion-pagination__active")):s.classList.remove("as-accordion-pagination__active"),s.addEventListener("click",(e=>this.pagination(n))),t.appendChild(s)}this.ctx.appendChild(t),this.onPagination(i)}onPagination(e){const t=Array.prototype.slice.call(this.ctx.querySelectorAll(".as-accordion-pagination > *")).indexOf(e)*this.config.paginationLimit,s=Array.prototype.slice.call(this.ctx.querySelectorAll(".as-accordion:not(.as-d-none)"));for(const e of s)e.classList.add("as-accordion-pagination-hide");const i=s.slice(t,t+this.config.paginationLimit);for(const e of i)e.classList.remove("as-accordion-pagination-hide")}loader(e=!0){if(this.searchActivated=!e,this.elementSearchBtnSearch.classList.toggle("as-cursor-not-allowed"),this.elementSearchBtnClear.classList.toggle("as-cursor-not-allowed"),this.elementSearchInput.classList.toggle("as-cursor-not-allowed"),this.config.suggestionBox)for(const e of this.ctx.querySelectorAll(".as-search-suggestion-box__items > *"))e.classList.toggle("as-cursor-not-allowed");this.elementSearchInput.readOnly=e;const t=e?this.config.iconLoader:this.config.iconSearch;this.elementSearchBtnSearch.innerHTML=t}}},138:(e,t,s)=>{const i=s(976).Z;window.AccordionSearchConfig={searchOnlyTitle:!1,searchOnClick:!1,caseSensitive:!1,itemsOpened:0,suggestionBox:!1,suggestionBoxTitle:"Popular Searches:",suggestionBoxKeywords:[],btnOpenCloseAll:!1,pagination:!1,paginationLimit:2,loader:!1,queryUrl:!1,queryUrlName:"asQuery",msgItemFound:"Item Found !",msgItemsFound:"Items Found !",msgNoResult:"Nothing Found !",iconSearch:'<i class="fas fa-search"></i>',iconClear:'<i class="fas fa-times"></i>',iconLoader:'<i class="fas fa-spinner fa-spin"></i>',iconOpen:'<i class="fas fa-plus"></i>',iconClose:'<i class="fas fa-minus"></i>',iconOpenAll:'<i class="fas fa-plus"></i>',iconCloseAll:'<i class="fas fa-minus"></i>'},e.exports=i}},t={};function s(i){var n=t[i];if(void 0!==n)return n.exports;var o=t[i]={exports:{}};return e[i](o,o.exports,s),o.exports}s.d=(e,t)=>{for(var i in t)s.o(t,i)&&!s.o(e,i)&&Object.defineProperty(e,i,{enumerable:!0,get:t[i]})},s.o=(e,t)=>Object.prototype.hasOwnProperty.call(e,t);var i=s(138);AccordionSearch=i})();