1import{gtcScrollLock,gtcScrollUnlock,getPageContentHtml,getSectionHtml,getTemplateHtml,gtcSetPreviousFocus,gtcTrapFocus,gtcRemoveTrapFocus}from"gtcUtils";let gOverlayLoaded=!1;const createGOverlay=async()=>{const overlay=document.createElement("div");overlay.innerHTML=" ",overlay.classList.add("gtc:overlay"),document.body.append(overlay),gOverlayLoaded=!0};class GTCOpener extends HTMLElement{static observedAttributes=["open"];constructor(){super(),this.class={open:"open",close:"close",overlayOpen:"gtc:overlay-open",scrollLock:"gtc:scroll-lock"},this.Click=this.Click.bind(this),this.Keydown=this.Keydown.bind(this)}attributeChangedCallback(name,oldValue,newValue){name==="open"&&(newValue!==null?(this.Open(),this.setAttribute("aria-hidden","false")):(this.Close(),this.setAttribute("aria-hidden","true")))}get isOpen(){return this.getAttribute("open")==="true"}set isOpen(value){this.setAttribute("open",value?"true":"false")}connectedCallback(){if(this.setAttribute("role","dialog"),this.setAttribute("aria-modal","true"),this.setAttribute("aria-hidden",!this.isOpen),this.setAttribute("tabindex","0"),this.settings={rendered:!1,...JSON.parse(this.getAttribute("settings"))},this.settings.type==="modal"){const modalContent=document.getElementById("gtc-modal-template").content.children[0];modalContent&&(this.render=modalContent)}else{const drawerContent=document.getElementById("gtc-drawer-template").content.children[0];drawerContent&&(this.render=drawerContent)}}disconnectedCallback(){this.Close(),this.RemoveOpenerEventListeners(),this.settings.rendered=!1,document.getElementById(`Trigger-${this.settings.id}`)&&document.getElementById(`Trigger-${this.settings.id}`).removeAttribute("loaded")}async Init(){this.settings.rendered===!0?this.Open():(await this.Create(),gtcTrapFocus(this))}AddOpenerEventListeners(){document.addEventListener("click",this.Click,!1),document.addEventListener("keydown",this.Keydown,!1)}RemoveOpenerEventListeners(){document.removeEventListener("click",this.Click,!1),document.removeEventListener("keydown",this.Keydown,!1)}Click(event){if(!this.hasAttribute(this.class.open))return;const target=event.target;(target.classList.contains("gtc:overlay")||!target.closest("nested")&&this.contains(target))&&(!this.contains(target)||target.hasAttribute("data-gtc-close"))&&this.Close()}Keydown(event){event.keyCode===27&&this.Close()}Open(){gtcScrollLock([this.class.scrollLock,this.class.overlayOpen]),this.tabIndex=0,setTimeout(()=>{this.AddOpenerEventListeners(),gtcTrapFocus(this)},0)}Close(){this.removeAttribute(this.class.open),this.tabIndex=-1,this.classList.contains("nested")||gtcScrollUnlock([this.class.scrollLock,this.class.overlayOpen]),setTimeout(()=>{this.RemoveOpenerEventListeners()},0),gtcRemoveTrapFocus(this)}async GetData(){this.data={};const keys=Object.keys(this.settings?.slots);for(const key of keys){const content=await this.GetContent(this.settings.slots[key]);content&&(this.data={...this.data,[key]:content})}}async GetContent(contentArray){if(contentArray)switch(contentArray[0]){case"string":return contentArray[1];case"template":return await getTemplateHtml(contentArray[1]);case"url":return await getPageContentHtml(contentArray[1]);case"section":const canonicalUrl=this.settings.canonicalUrl?this.settings.canonicalUrl:null;return await getSectionHtml(contentArray[1],canonicalUrl);case"tabs":return await this.GetContentTabs(contentArray[1]);case"extraLink":return await this.GetContentExtraLink(contentArray[1]);default:return""}}async Create(){if(await this.GetData(),this.render.querySelectorAll("[slot]").forEach(slot=>{const slotName=slot.getAttribute("slot");this.data[slotName]?slot.innerHTML=this.data[slotName]||"":slot.remove()}),!this.render.innerHTML)return console.warn("No HTML IN GTC-OPENER!");if(gOverlayLoaded||createGOverlay(),this.settings?.class){const classes=this.settings.class.split(" ").filter(letter=>letter!=="");this.classList.add(...classes)}this.settings?.id&&this.setAttribute("id",`Opener-${this.settings.id}`),this.insertAdjacentHTML("beforeend",this.render.innerHTML),this.offsetHeight,this.settings.rendered=!0,this.setAttribute(this.class.open,""),document.addEventListener(`gtc:opener:open.${this.settings.id}`,()=>{this.setAttribute(this.class.open,"")})}}class GTCModal extends GTCOpener{constructor(){super()}connectedCallback(){super.connectedCallback(),this.Init()}}customElements.define("gtc-modal",GTCModal);class GTCDrawer extends GTCOpener{constructor(){super()}connectedCallback(){super.connectedCallback(),this.Init()}}customElements.define("gtc-drawer",GTCDrawer);class GTCTrigger extends HTMLElement{constructor(){super()}connectedCallback(){this.hasAttribute("tabindex")||this.setAttribute("tabindex",0),this.Init()}disconnectedCallback(){this.RremoveEventListeners()}AddEventListeners(){this.Click=this.Click.bind(this),this.addEventListener("click",this.Click),this.addEventListener("keydown",event=>{(event.key==="Enter"||event.key===" ")&&this.Click()},!1)}RremoveEventListeners(){this.removeEventListener("click",this.Click),this.removeEventListener("keydown",event=>{(event.key==="Enter"||event.key===" ")&&this.Click()},!1)}Init(){const settings=this.hasAttribute("settings")?{...JSON.parse(this.getAttribute("settings"))}:null;if(!settings){console.error("No settings found on gtc-trigger id: "+this.id
1);return}this.settings={...settings},this.AddEventListeners()}Click(){if(gtcSetPreviousFocus(this),this.hasAttribute("loaded"))document.dispatchEvent(new CustomEvent(`gtc:opener:open.${this.settings.id}`));else{switch(this.settings.type){case"modal":this.CreateCustomElement(this.settings.type);break;case"drawer":this.CreateCustomElement(this.settings.type);break;default:console.warn('No opener "type" is matching.'),this.setAttribute("disabled","");break}this.setAttribute("loaded","")}}CreateCustomElement(type){const openerElement=document.createElement(`gtc-${type}`);openerElement.setAttribute("settings",JSON.stringify(this.settings)),openerElement.classList.add(`gtc:${type}`),this.settings.append==="after"?this.after(openerElement):document.body.append(openerElement)}}customElements.get("gtc-trigger")||customElements.define("gtc-trigger",GTCTrigger); 2//# sourceMappingURL=/cdn/shop/t/13/assets/gtc-opener.js.map?v=98484729040124925891738735529
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.