1(()=>{if(!customElements.get("theme-modal")){const Z_INDEX={MODAL_ABOVE_DRAWER:"1400",MODAL_DEFAULT:"1501"};class ThemeModal extends HTMLElement{constructor(){super(),this.modalId="ThemeModal",this.modalContentSelector="[data-modal-content] .theme-modal--inner",this.focusableSelector='a[href], button, textarea, input, select, [tabindex]:not([tabindex="-1"])',this.restoreFocusOnClose=this.getAttribute("data-focus-on-close"),this.cacheDOMElements(),this.bindEventHandlers(),window._myModalCache=window._myModalCache||{},this.bodyClassObserver=new MutationObserver(mutationsList=>{for(const mutation of mutationsList)mutation.type==="attributes"&&mutation.attributeName==="class"&&(document.body.className.includes("js-drawer-open")?this.overlay&&this.overlay.removeEventListener("click",this.hideModal):this.overlay&&this.overlay.addEventListener("click",this.hideModal))})}cacheDOMElements(){if(this.sectionId=this.getAttribute("data-section-id"),this.sectionFetchId=this.getAttribute("data-section-fetch-id"),this.productUrl=this.getAttribute("data-product-url"),this.contentSelector=this.getAttribute("data-content-selector"),this.shouldFetchSection=this.hasAttribute("data-fetch-section"),this.blockId=this.getAttribute("data-block-id"),this.modalButton=this.querySelector("[data-modal-button]"),this.modalTemplate=this.querySelector("template[data-theme-modal-content]"),this.overlay=document.querySelector("#DrawerOverlay"),this.modalContent=this.querySelector("[data-modal-content]"),this.isQuickView=this.hasAttribute("data-is-quick-view"),!this.modalButton||!this.modalTemplate){console.warn("Theme Modal: Required elements missing");return}}bindEventHandlers(){this.showModal=this.showModal.bind(this),this.hideModal=this.hideModal.bind(this),this.handleKeydown=this.handleKeydown.bind(this),this.handleDrawerOpened=this.handleDrawerOpened.bind(this),this.handleDrawerClosed=this.handleDrawerClosed.bind(this)}connectedCallback(){if(window.eventBus.on("theme:modal:hide",this.hideModal),this.modalButton.addEventListener("click",this.showModal),window.eventBus.on("drawer:opened",this.handleDrawerOpened),window.eventBus.on("drawer:closed",this.handleDrawerClosed),this.shouldFetchSection){const productCard=this.closest("product-card")||this.closest("[data-quick-view-fetch-target]");if(productCard){let hoverTimer;productCard.addEventListener("mouseenter",()=>{hoverTimer=setTimeout(()=>{this.prefetch()},250)}),productCard.addEventListener("mouseleave",()=>clearTimeout(hoverTimer)),productCard.addEventListener("touchstart",()=>{this.prefetch()},{once:!0})}}window.Shopify.designMode&&document.addEventListener("shopify:section:load",async()=>{this.hideModal()})}handleDrawerOpened(){const modal=document.querySelector("#ThemeModal");modal&&(modal.style.zIndex=Z_INDEX.MODAL_ABOVE_DRAWER)}handleDrawerClosed(){const modal=document.querySelector("#ThemeModal");modal&&setTimeout(()=>{modal.style.zIndex=Z_INDEX.MODAL_DEFAULT},600)}disconnectedCallback(){this.bodyClassObserver.disconnect(),this.modalButton.removeEventListener("click",this.showModal),this.overlay&&this.overlay.removeEventListener("click",this.hideModal),this.dismissButton&&this.dismissButton.removeEventListener("click",this.hideModal),window.eventBus.off("drawer:opened",this.handleDrawerOpened),window.eventBus.off("drawer:closed",this.handleDrawerClosed),window.eventBus.off("theme:modal:hide",this.hideModal)}prefetch(){const url=this.productUrl||`${window.Shopify.routes.root}?section_id=${this.sectionFetchId}`;if(url){if(window._myModalCache[url]){this._prefetchedModalHTML=window._myModalCache[url];return}this.fetchModalContentInBackground().then(()=>{window._myModalCache[url]=this._prefetchedModalHTML}).catch(err=>{console.error("Prefetch error:",err)})}}async fetchModalContentInBackground(){try{const url=this.productUrl||`${window.Shopify.routes.root}?section_id=${this.sectionFetchId}`,response=await fetch(url);if(!response.ok)throw new Error(`Failed to fetch modal content: ${response.status}`);const textContent=await response.text(),doc=new DOMParser().parseFromString(textContent,"text/html"),relevantContent=this.contentSelector?doc.querySelector(this.contentSelector)?.innerHTML:textContent;this._prefetchedModalHTML=relevantContent||""}catch(error){throw console.error("Theme Modal: Error prefetching content",error),error}}initScrollHandler(el){if(!el)return;let scrolling;el.addEventListener("scroll",()=>{clearTimeout(scrolling),el.classList.add("scrolling"),scrolling=setTimeout(()=>{el.classList.remove("scrolling")},800)})}async render(){try{const modalContent=document.querySelector(`#${this.modalId}`);if(!modalContent)return console.warn("Theme Modal: Modal content element not found"),!1;if(modalContent.innerHTML=this.modalTemplate.innerHTML,this.modalContent=modalContent,this.dismissButton=this.modalContent.querySelector("[data-close]"),this.dismissButton&&this.dismissButton.addEventListener("click",this.hideModal),this._prefetchedModalHTML){const targetElement=document.querySelector(`#${this.modalId} ${this.modalContentSelector}`);if(!targetElement)return console.error("Modal content target element not found"),!1;targetElement.innerHTML=this._prefetchedModalHTML,this.isQuickView?window.eventBus.emit("product:modal:ready",{detail:{sectionId:this.quickViewSectionId}}):window.eventBus.emit("product:modal:ready",{detail:{sectionId:this.sectionId}})}else this.shouldFetchSection&&(this.sectionFetchId||this.productUrl)&&await this.fetchModalContent();return!0}catch(error){return console.error("Theme Modal: Error rendering modal",error),!1}}async showModal(e){if(e.stopPropagation(),e.preventDefault(),this.isQuickView&&document.querySelector("#ThemeModal")?.classList.add("is-quick-view"),window.eventBus.emit("theme:modal:open",{details:{sectionId:this.sectionId}}),this.bodyClassObserver.observe(document.body,{attributes:!0,attributeFilter:["class"]}),this.previousActiveElement=e.currentTarget,await this.render()&&(document.body.classList.add("theme-modal-open"),this.modalContent)){this.quickViewProduct=this.modalContent.querySelector("[data-quick-view-product] [data-product-content-wrapper]"),this.quickViewSectionId=this.quickViewProduct?.getAttribute("data-section-id"),this.modalContent.classList.remove("hidden"),this.trapFocus();const scrollableInner=this.modalContent.querySelector("[data-modal-content]");scrollableInner&&this.initScrollHandler(scrollableInner)}}hideModal(){const modalIsOpen=document.body.classList.contains("theme-modal-open");if(document.body.classList.remove("theme-modal-open"),window.eventBus.emit("theme:modal:close",{details:{sectionId:this.sectionId}}),this.isQuickView?window.eventBus.emit("product:modal:close",{detail:{sectionId:this.quickViewSectionId,isQuickView:!0}}):window.eventBus.emit("product:modal:close",{detail:{sectionId:this.sectionId,isQuickView:!1}}),document.removeEventListener("keydown",this.handleKeydown),this.bodyClassObserver.disconnect(),this.overlay&&this.overlay.removeEventListener("click",this.hideModal),this.dismissButton&&this.dismissButton.removeEventListener("click",this.hideModal),this.modalContent){const timeoutId=setTimeout(()=>{this.modalContent.innerHTML=""},1e3);modalIsOpen&&this.modalContent.addEventListener("transitionend",()=>{clearTimeout(timeoutId),this.modalContent.innerHTML="",this.isQuickView&&document.querySelector("#ThemeModal")?.classList.remove("is-quick-view")},{once:!0})}this.restoreFocusOnClose==="true"&&this.previousActiveElement&&typeof this.previousActiveElement.focus=="function"&&this.previousActiveElement.focus()}trapFocus(){const firstElement=this.modalContent.querySelectorAll(this.focusableSelector)[0];firstElement&&(document.addEventListener("keydown",this.handleKeydown),requestAnimationFrame(()=>firstElement.focus()))}handleKeydown(event){const focusableElements=this.modalContent.querySelectorAll(this.focusableSelector),firstElement=focusableElements[0],lastElement=focusableElements[focusableElements.length-1];if(!firstElement||!lastElement)return;const isTabPressed=event.key==="Tab";if(event.key==="Escape"){this.hideModal();return}isTabPressed&&(event.shiftKey&&document.activeElement===firstElement?(lastElement.focus(),event.preventDefault()):!event.shiftKey&&document.activeElement===lastElement&&(firstElement.focus(),event.preventDefault()))}async fetchModalContent(){try{const url=this.productUrl||`${window.Shopify.routes.root}?section_id=${this.sectionFetchId}`,response=await fetch(url);if(!response.ok)throw new Error(`Failed to fetch modal content: ${response.status}`);const textContent=await response.text(),doc=new DOMParser().parseFromString(textContent,"text/html"),modalContent=this.contentSelector?doc.querySelector(this.contentSelector)?.innerHTML:textContent,targetElement=document.querySelector(`#${this.modalId} ${this.modalContentSelector}`);if(!targetElement)throw new Error("Modal content target element not found");targetElement.innerHTML=modalContent||"",this.isQuickView?window.eventBus.emit("product:modal:ready",{detail:{sectionId:this.quickViewSectionId}}):window.eventBus.emit("product:modal:ready",{detail:{sectionId:this.sectionId}})}catch(error){console.error("Theme Modal: Error fetching content",error);const targetElement=document.querySelector(`#${this.modalId} ${this.modalContentSelector}`);targetElement&&(targetElement.innerHTML="<p>Sorry, there was an error loading the content. Please try again.</p>")}}}customElements.define("theme-modal",ThemeModal)}})(); 2//# sourceMappingURL=/cdn/shop/t/14/assets/theme-modal-component.js.map?v=117215827302362821431782253620
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.