/*! * @name autocomplete * @version 2.0.1 * @author Grzegorz Tomicki * @link https://github.com/tomickigrzegorz/autocomplete * @license MIT */ var Autocomplete=function(){"use strict";const t=(t,s)=>{for(let i in s)"addClass"===i?e(t,"add",s[i]):"removeClass"===i?e(t,"remove",s[i]):t.setAttribute(i,s[i])},s=t=>(t.firstElementChild||t).textContent.trim(),i=(t,s)=>{t.scrollTop=t.offsetTop-s.offsetHeight},h=function(t,s){void 0===t&&(t=!1),t&&(e(t,"remove","hidden"),o(t,"click",s))},e=(t,s,i)=>t.classList[s](i),a=(s,i)=>{t(s,{"aria-activedescendant":i||""})},n=(t,s,i,h)=>{const e=h.previousSibling,a=e?e.offsetHeight:0;if("0"==t.getAttribute("aria-posinset")&&(h.scrollTop=t.offsetTop-((t,s)=>{const i=document.querySelectorAll(`#${t} > li:not(.${s})`);let h=0;return[].slice.call(i).map((t=>h+=t.offsetHeight)),h})(s,i)),t.offsetTop-ah.scrollTop+h.offsetHeight&&(h.scrollTop=s-h.offsetHeight)}},l=t=>document.createElement(t),r=t=>document.querySelector(t),o=(t,s,i)=>{t.addEventListener(s,i)},c=(t,s,i)=>{t.removeEventListener(s,i)},d=t=>({"aria-owns":t,"aria-expanded":"false","aria-autocomplete":"list",role:"combobox",removeClass:"auto-expanded"}),u=27,m=13,p=38,$=40,v=9;return class{constructor(b,f){let{delay:x=500,clearButton:y=!0,clearButtonOnInitial:C=!1,howManyCharacters:k=1,selectFirst:g=!1,insertToInput:w=!1,showAllValues:j=!1,cache:I=!1,disableCloseOnSelect:S=!1,preventScrollUp:V=!1,removeResultsWhenInputIsEmpty:O=!1,regex:R={expression:/[|\\{}()[\]^$+*?]/g,replacement:"\\$&"},classGroup:A,classPreventClosing:B,classPrefix:P,ariaLabelClear:T,onSearch:E,onResults:G=(()=>{}),onSubmit:J=(()=>{}),onOpened:N=(()=>{}),onReset:q=(()=>{}),onRender:z=(()=>{}),onClose:F=(()=>{}),noResults:L=(()=>{}),onSelectedItem:M=(()=>{})}=f;var U;this.t=()=>{this.i();const s=d(this.h);var i,e,a,n,l;t(this.l,s),i=this.l,e=this.o,a=this.h,n=this.u,l=this.m,t(e,{id:a,tabIndex:"0",role:"listbox"}),t(n,{addClass:`${l}-results-wrapper`}),n.insertAdjacentElement("beforeend",e),i.parentNode.insertBefore(n,i.nextSibling),o(this.l,"input",this.p),this.$&&o(this.l,"click",this.p),this.v({element:this.l,results:this.o}),this.C&&h(this.k,this.destroy)},this.j=(t,s)=>{this.I&&("update"===t?this.l.setAttribute(this.S,s.value):"remove"===t?this.l.removeAttribute(this.S):this.l.value=this.l.getAttribute(this.S))},this.p=t=>{let{target:s,type:i}=t;if("true"===this.l.getAttribute("aria-expanded")&&"click"===i)return;const h=s.value.replace(this.V.expression,this.V.replacement);this.j("update",s);const e=this.$?0:this.O;clearTimeout(this.R),this.R=setTimeout((()=>{this.A&&0===s.value.length?this.destroy():this.B(h.trim())}),e)},this.P=()=>{e(this.u,"remove",this.T);const s=d(this.h),i=this.G?s:{...s,"aria-activedescendant":""};t(this.l,i),this.G||(this.J(r(`.${this.N}`)),this.q=this.F?0:-1),(0==this.L?.length&&!this.M||this.$)&&(this.o.textContent=""),this.U()},this.B=t=>{this.W=t,this.D(!0),h(this.k,this.destroy),0==t.length&&this.H&&e(this.k,"add","hidden"),this.K>t.length&&!this.$?this.D():this.X({currentValue:t,element:this.l}).then((s=>{const i=this.l.value.length,h=s.length;this.L=Array.isArray(s)?s:JSON.parse(JSON.stringify(s)),this.D(),this.Y(),0==h&&0==i&&e(this.k,"add","hidden"),0==h&&i?(e(this.l,"remove","auto-expanded"),this.P(),this.Z({element:this.l,currentValue:t,template:this._}),this.tt()):(h>0||(t=>t&&"object"==typeof t&&t.constructor===Object)(s))&&(this.q=this.F?0:-1,this._(),this.tt())})).catch((()=>{this.D(),this.P()}))},this.D=t=>this.l.parentNode.classList[t?"add":"remove"](this.st),this.Y=()=>e(this.l,"remove",this.it),this.tt=()=>{o(this.l,"keydown",this.ht),o(this.l,"click",this.et),o(document,"click",this.nt),["mousemove","click"].map((t=>{o(this.o,t,this.lt)}))},this._=s=>{t(this.l,{"aria-expanded":"true",addClass:`${this.m}-expanded`}),this.o.textContent="";const h=0===this.L.length?this.rt({currentValue:this.W,matches:0,template:s}):this.rt({currentValue:this.W,matches:this.L,classGroup:this.ot});this.o.insertAdjacentHTML("afterbegin",h),e(this.u,"add",this.T);const a=this.ot?`:not(.${this.ot})`:"";this.ct=document.querySelectorAll(`#${this.h} > li${a}`),(s=>{for(let i=0;i{let{target:s}=t,i=null;(s.closest("ul")&&this.$t||s.closest(`.${this.vt}`))&&(i=!0),s.id===this.bt||i||this.P()},this.ut=()=>{if(this.J(r(`.${this.N}`)),!this.F)return;const{firstElementChild:s}=this.o,i=this.ot&&this.L.length>0&&this.F?s.nextElementSibling:s;this.ft({index:this.q,element:this.l,object:this.L[this.q]}),t(i,{id:`${this.xt}-0`,addClass:this.N,"aria-selected":"true"}),a(this.l,`${this.xt}-0`)},this.et=()=>{if(this.o.textContent.length>0&&!e(this.u,"contains",this.T)){if(t(this.l,{"aria-expanded":"true",addClass:`${this.m}-expanded`}),e(this.u,"add",this.T),this.G||(i(this.o,this.u),this.ut()),this.dt({type:"showItems",element:this.l,results:this.o}),!this.I)return;this.j("update",this.l)}},this.lt=t=>{t.preventDefault();const{target:s,type:i}=t,h=s.closest("li"),a=h?.hasAttribute("role"),n=this.N,l=r(`.${n}`);h&&a&&!s.closest(`.${this.vt}`)&&("click"===i&&this.yt(h),"mousemove"!==i||e(h,"contains",n)||(this.J(l),this.Ct(h),this.q=this.kt(h),this.ft({index:this.q,element:this.l,object:this.L[this.q]})))},this.yt=t=>{t&&0!==this.L.length?(this.H&&e(this.k,"remove","hidden"),this.l.value=s(t),this.gt({index:this.q,element:this.l,object:this.L[this.q],results:this.o}),this.$t||(this.G||this.J(t),this.P()),this.j("remove")):!this.$t&&this.P()},this.kt=t=>Array.prototype.indexOf.call(this.ct,t),this.ht=t=>{const{keyCode:i}=t,h=e(this.u,"contains",this.T),n=this.L.length+1;switch(this.wt=r(`.${this.N}`),i){case p:case $:if(t.preventDefault(),n<=1&&this.F||!h)return;if(i===p?(this.q<0&&(this.q=n-1),this.q-=1):(this.q+=1,this.q>=n&&(this.q=0)),this.J(this.wt),this.q>=0&&this.q{const i=`${this.xt}-${this.kt(s)}`;t(s,{id:i,"aria-selected":"true",addClass:this.N}),a(this.l,i),n(s,this.h,this.ot,this.o)},this.J=s=>{s&&t(s,{id:"",removeClass:this.N,"aria-selected":"false"})},this.i=()=>{this.H&&(t(this.k,{class:`${this.m}-clear hidden`,type:"button",title:this.jt,"aria-label":this.jt}),this.l.insertAdjacentElement("afterend",this.k))},this.rerender=t=>{const s=t?.trim()?t.trim():this.l.value;t?.trim()&&(this.l.value=t.trim(),this.j("update",this.l));const i=s.replace(this.V.expression,this.V.replacement);this.B(i.trim())},this.destroy=()=>{this.H&&e(this.k,"add","hidden"),this.l.value="",this.l.focus(),this.o.textContent="",this.P(),this.Y(),this.It(this.l),this.D(),c(this.l,"keydown",this.ht),c(this.l,"click",this.et),c(document,"click",this.nt)},this.bt=b,this.l=document.getElementById(b),this.X=(U=E,Boolean(U&&"function"==typeof U.then)?E:t=>{let{currentValue:s,element:i}=t;return Promise.resolve(E({currentValue:s,element:i}))}),this.rt=G,this.v=z,this.gt=J,this.ft=M,this.dt=N,this.It=q,this.Z=L,this.U=F,this.O=x,this.K=k,this.H=y,this.C=C,this.F=g,this.M=w,this.$=j,this.ot=A,this.vt=B,this.jt=T||"clear the search query",this.m=P?`${P}-auto`:"auto",this.$t=S,this.G=V,this.A=O,this.I=I,this.R=null,this.h=`${this.m}-${this.bt}-results`,this.S=`data-cache-auto-${this.bt}`,this.st=`${this.m}-is-loading`,this.T=`${this.m}-is-active`,this.N=`${this.m}-selected`,this.xt=`${this.m}-selected-option`,this.it=`${this.m}-error`,this.u=l("div"),this.o=l("ul"),this.k=l("button"),this.V=R,this.St={expression:/[|\\{}()[\]^$+*?]/g,replacement:"\\$&"},this.V.replacement||(this.V.replacement=this.St.replacement),this.V.expression||(this.V.expression=this.St.expression),this.t()}}}(); window.addEventListener('DOMContentLoaded', () => { var auto = new Autocomplete('gmrsearch', { delay: 200, howManyCharacters: 3, onSearch: ({ currentValue }) => { var api = mvpro_ajaxsearch_params.ajax_url; return new Promise((resolve) => { fetch(api, { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/x-www-form-urlencoded' }, body: 'action=muvipro_core_ajax_search_movie&security=' + mvpro_ajaxsearch_params._wpnonce + '&query=' + currentValue.trim(), }) .then((response) => response.json()) .then((data) => { resolve(data.suggestions); }) .catch((error) => { console.error(error); }); }); }, onResults: ({ matches, template }) => { return matches === 0 ? template : matches .map( el => { return `
  • ${el.thumb}${el.value}
  • `; }).join(''); }, onSubmit: ({ index, element, object }) => { var { url } = object; window.open( url,"_self" ) }, }); });