function loadScript(src){return new Promise((resolve,reject)=>{const s=document.createElement("script");s.src=src,s.onload=resolve,s.onerror=reject,document.body.appendChild(s)})}if(!customElements.get("cart-drawer-disclosure")){class CartDrawerDisclosure extends DetailsDisclosure{constructor(){super(),this.openBtn=this.querySelector("summary"),this.closeBtn=this.querySelector(".js-close"),this.overlay=document.getElementById("cart-drawer").querySelector(".overlay")}handleClick(evt){evt.target.matches(".js-close")&&this.close()}open(){this.overlay.classList.add("is-visible"),super.open(),trapFocus(this),this.clickHandler=this.clickHandler||this.handleClick.bind(this),this.keyupHandler=evt=>evt.key==="Escape"&&this.close(),this.addEventListener("click",this.clickHandler),this.addEventListener("keyup",this.keyupHandler),this.overlay.addEventListener("click",this.clickHandler)}close(){this.overlay.classList.remove("is-visible"),super.close(),removeTrapFocus(this.openBtn),this.removeEventListener("click",this.clickHandler),this.removeEventListener("keyup",this.keyupHandler),this.overlay.removeEventListener("click",this.clickHandler)}}customElements.define("cart-drawer-disclosure",CartDrawerDisclosure)}if(!customElements.get("cart-drawer")){class CartDrawer extends SideDrawer{constructor(){super(),this.cartSummary=this.querySelector(".cart-drawer__summary"),this.init(),this.bindEvents()}disconnectedCallback(){document.removeEventListener("dispatch:cart-drawer:refresh",this.refreshHandler),document.removeEventListener("dispatch:cart-drawer:open",this.openDrawerViaEventHandler),document.removeEventListener("dispatch:cart-drawer:close",this.closeDrawerViaEventHandler),Shopify.designMode&&(document.removeEventListener("shopify:section:select",this.sectionSelectHandler),document.removeEventListener("shopify:section:deselect",this.sectionDeselectHandler)),this.dcbLoadedHandler&&document.removeEventListener("shopify:payment_button:loaded",this.dcbLoadedHandler)}init(){const cartIcon=document.getElementById("cart-icon");cartIcon&&(cartIcon.setAttribute("role","button"),cartIcon.setAttribute("aria-haspopup","dialog"),cartIcon.addEventListener("click",evt=>{evt.preventDefault(),this.open(cartIcon)}),cartIcon.addEventListener("keydown",evt=>{evt.key===" "&&(evt.preventDefault(),this.open(cartIcon))}))}bindEvents(){Shopify.designMode&&(this.sectionSelectHandler=this.handleSectionSelect.bind(this),this.sectionDeselectHandler=this.handleSectionDeselect.bind(this),document.addEventListener("shopify:section:select",this.sectionSelectHandler),document.addEventListener("shopify:section:deselect",this.sectionDeselectHandler)),this.openDrawerViaEventHandler=this.handleDrawerOpenViaEvent.bind(this),this.closeDrawerViaEventHandler=this.close.bind(this,null),document.addEventListener("dispatch:cart-drawer:open",this.openDrawerViaEventHandler),document.addEventListener("dispatch:cart-drawer:close",this.closeDrawerViaEventHandler),this.cartSummary.classList.contains("cart-drawer--checkout--sticky-true")&&(this.dcbLoadedHandler=this.dcbLoadedHandler||CartDrawer.recalculateCssVarHeights,document.addEventListener("shopify:payment_button:loaded",this.dcbLoadedHandler)),this.refreshHandler=this.refresh.bind(this),document.addEventListener("dispatch:cart-drawer:refresh",this.refreshHandler)}handleSectionSelect(evt){evt.target===this.closest(".shopify-section")&&this.open()}handleSectionDeselect(evt){evt.target===this.closest(".shopify-section")&&this.close()}handleDrawerOpenViaEvent(evt){this.open(evt.detail?evt.detail.opener:null)}open(opener,elementToFocus){const quickAddDrawer=document.querySelector('quick-add-drawer[aria-hidden="false"]'),overlay=document.querySelector(".js-overlay.is-visible");quickAddDrawer&&(overlay&&(overlay.style.transitionDelay="200ms"),quickAddDrawer.close()),setTimeout(()=>{super.open(opener,elementToFocus,()=>{this.cartSummary.classList.contains("cart-drawer--checkout--sticky-true")&&CartDrawer.recalculateCssVarHeights()}),this.cartSummary.classList.contains("cart-drawer--checkout--sticky-true")&&CartDrawer.recalculateCssVarHeights(),overlay&&(overlay.style.transitionDelay="")},quickAddDrawer?200:0),window.initLazyImages()}async refresh(dontRefreshCartItems){try{const cartItems=this.querySelector("cart-items");if(cartItems&&!dontRefreshCartItems)cartItems.refresh();else{const response=this.getSectionsToRender().map(section=>section.section),sections=await(await fetch(`?sections=${response.join(",")}`)).json();this.renderContents({sections},!1)}}catch(error){console.log(error),this.dispatchEvent(new CustomEvent("on:cart:error",{bubbles:!0,detail:{error:this.errorMsg.textContent}}))}}async renderContents(data,openDrawer=!0){this.scriptsLoaded||(document.querySelector(`script[src="${theme.scripts.cartItems}"]`)||await loadScript(theme.scripts.cartItems),!document.querySelector(`script[src="${theme.scripts.shippingCalculator}"]`)&&this.dataset.shippingCalculator&&(await loadScript(theme.scripts.countryProvinceSelector),await loadScript(theme.scripts.shippingCalculator)),this.scriptsLoaded=!0),this.getSectionsToRender().forEach(section=>{const el=document.getElementById(section.id);el&&(el.innerHTML=CartDrawer.getElementHTML(data.sections[section.section],section.selector))}),openDrawer&&this.getAttribute("open")===null&&setTimeout(()=>this.open()),window.initLazyImages()}getSectionsToRender(){return[{id:"cart-drawer",section:this.closest(".shopify-section").id.replace("shopify-section-",""),selector:"cart-drawer"},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"}]}static recalculateCssVarHeights(){window.requestAnimationFrame(()=>{document.dispatchEvent(new CustomEvent("on:css-var-height:update"))})}static getElementHTML(html,selector){const tmpl=document.createElement("template");return tmpl.innerHTML=html,tmpl.content.querySelector(selector).innerHTML}}customElements.define("cart-drawer",CartDrawer)} //# sourceMappingURL=/cdn/shop/t/58/assets/cart-drawer.js.map?v=166125276811576869981721413947