1(function(){class QuickBuyDrawer extends HTMLElement{constructor(){super(),this.variants=[],this.selectedOptions={},this.matchedVariant=null,this.escHandler=e=>{e.key==="Escape"&&!this.hasAttribute("hidden")&&this.close()}}connectedCallback(){if(!this._initialized){this._initialized=!0;try{const raw=this.dataset.variants||"[]";this.variants=JSON.parse(raw),this.variants=this.variants.map(v=>({...v,options:Array.isArray(v.options)?v.options.map(String):[v.option1,v.option2,v.option3].filter(Boolean).map(String)}))}catch(e){console.error("[QuickBuyDrawer] variants parse error:",e),this.variants=[]}this.panel=this.querySelector(".quick-buy-drawer__panel"),this.atcBtn=this.querySelector("[data-quick-buy-add]"),this.priceEl=this.querySelector("[data-quick-buy-price]"),this.priceCurrentEl=this.querySelector("[data-quick-buy-price-current]"),this.priceCompareEl=this.querySelector("[data-quick-buy-price-compare]"),this.optionGroups=this.querySelectorAll(".quick-buy-drawer__option"),this.optionGroups.forEach(group=>{const idx=parseInt(group.dataset.optionIndex,10);group.querySelectorAll(".quick-buy-drawer__chip").forEach(chip=>{chip.addEventListener("click",()=>this.selectOption(idx,chip))})}),this.querySelectorAll("[data-quick-buy-close]").forEach(el=>el.addEventListener("click",()=>this.close())),this.atcBtn&&this.atcBtn.addEventListener("click",()=>this.addToCart()),this.initDefaults()}}isMobileViewport(){return window.matchMedia("(max-width: 749px)").matches}ensurePortalPlaceholder(){this._portalPlaceholder||(this._portalPlaceholder=document.createComment("quick-buy-drawer"),this._homeParent=this.parentNode,this._homeParent.insertBefore(this._portalPlaceholder,this))}moveToBody(){this.ensurePortalPlaceholder(),this.parentNode!==document.body&&document.body.appendChild(this)}restoreToHome(){this._portalPlaceholder&&this._portalPlaceholder.parentNode&&this._portalPlaceholder.parentNode.insertBefore(this,this._portalPlaceholder)}initDefaults(){this.optionGroups.forEach((group,idx)=>{const chips=group.querySelectorAll(".quick-buy-drawer__chip");if(chips.length===1){const chip=chips[0];chip.setAttribute("aria-checked","true"),chip.classList.add("quick-buy-drawer__chip--selected"),this.selectedOptions[idx]=String(chip.dataset.optionValue),group.hidden=!0}}),this.optionGroups.forEach((group,idx)=>{if(group.hidden||this.selectedOptions[idx]!==void 0)return;const labelEl=group.querySelector(".quick-buy-drawer__option-label");if(!(labelEl?labelEl.textContent.toLowerCase():"").includes("size"))return;const firstAvailable=Array.from(group.querySelectorAll(".quick-buy-drawer__chip")).find(chip=>{const value=String(chip.dataset.optionValue);return this.variants.some(v=>v.options[idx]===value&&v.available)});firstAvailable&&(firstAvailable.setAttribute("aria-checked","true"),firstAvailable.classList.add("quick-buy-drawer__chip--selected"),this.selectedOptions[idx]=String(firstAvailable.dataset.optionValue))}),this.updateAvailable()}open(){document.querySelectorAll("quick-buy-drawer:not([hidden])").forEach(drawer=>{drawer!==this&&typeof drawer.close=="function"&&drawer.close()}),this._cardWrapper=this.closest(".card-wrapper"),this._cardWrapper?.classList.add("quick-buy-drawer-host--open"),this._portaled=this.isMobileViewport(),this._portaled&&this.moveToBody(),this.removeAttribute("hidden"),this._portaled&&(document.body.style.overflow="hidden"),document.addEventListener("keydown",this.escHandler),requestAnimationFrame(()=>{this.classList.add("quick-buy-drawer--open")})}close(){this.classList.remove("quick-buy-drawer--open"),this._portaled&&(document.body.style.overflow=""),document.removeEventListener("keydown",this.escHandler),setTimeout(()=>{this.setAttribute("hidden",""),this._portaled&&(this.restoreToHome(),this._portaled=!1),this._cardWrapper?.classList.remove("quick-buy-drawer-host--open"),this._cardWrapper=null},280)}selectOption(optionIndex,chip){chip.closest(".quick-buy-drawer__option").querySelectorAll(".quick-buy-drawer__chip").forEach(c=>{c.setAttribute("aria-checked","false"),c.classList.remove("quick-buy-drawer__chip--selected")}),chip.setAttribute("aria-checked","true"),chip.classList.add("quick-buy-drawer__chip--selected"),this.selectedOptions[optionIndex]=String(chip.dataset.optionValue),this.updateAvailable()}markUnavailable(optionIndex){const group=this.optionGroups[optionIndex];if(!group)return;group.querySelectorAll(".quick-buy-drawer__chip").forEach(chip=>{const value=String(chip.dataset.optionValue),anyAvailable=this.variants.some(v=>{if(!Array.isArray(v.options)||v.options[optionIndex]!==value||!v.available)return!1;for(const[idx,val]of Object.entries(this.selectedOptions)){const i=parseInt(idx,10);if(i!==optionIndex&&v.options[i]!==val)return!1}return!0});chip.classList.toggle("quick-buy-drawer__chip--soldout",!anyAvailable)})}updateAvailable(){const totalOptions=this.optionGroups.length,selectedCount=Object.keys(this.selectedOptions).length;if(this.optionGroups.forEach((_,idx)=>
1this.markUnavailable(idx)),!!this.atcBtn){if(selectedCount<totalOptions){this.matchedVariant=null,this.atcBtn.disabled=!0,this.atcBtn.textContent=this.atcBtn.dataset.defaultLabel||"Add to cart";return}if(this.matchedVariant=this.variants.find(v=>Object.entries(this.selectedOptions).every(([idx,val])=>v.options[parseInt(idx,10)]===val)),!this.matchedVariant){this.atcBtn.disabled=!0,this.atcBtn.textContent="Unavailable";return}if(!this.matchedVariant.available){this.atcBtn.disabled=!0,this.atcBtn.textContent="Sold out";return}this.atcBtn.disabled=!1,this.atcBtn.textContent=this.atcBtn.dataset.defaultLabel||"Add to cart",this.priceCurrentEl&&this.matchedVariant.price_formatted&&(this.priceCurrentEl.textContent=this.matchedVariant.price_formatted),this.priceCompareEl&&(this.matchedVariant.compare_at_price&&this.matchedVariant.compare_at_price>this.matchedVariant.price?(this.priceCompareEl.textContent=this.matchedVariant.compare_at_price_formatted,this.priceCompareEl.removeAttribute("hidden"),this.priceEl?.classList.add("quick-buy-drawer__price--on-sale")):(this.priceCompareEl.setAttribute("hidden",""),this.priceEl?.classList.remove("quick-buy-drawer__price--on-sale")))}}async refreshFromProductJson(handle){try{const res=await fetch(`/products/${handle}.js`);if(!res.ok)throw new Error(`Product fetch failed: ${res.status}`);const product=await res.json(),variants=product.variants.map(v=>({id:v.id,available:v.available,price:v.price,price_formatted:this.#formatMoney(v.price),compare_at_price:v.compare_at_price??0,compare_at_price_formatted:this.#formatMoney(v.compare_at_price??0),options:[v.option1,v.option2,v.option3].filter(Boolean).map(String)})),optionsHtml=product.options.map((option,idx)=>{const optionName=option.name??option,chipsHtml=[...new Set(product.variants.map(v=>v[`option${idx+1}`]))].map(val=>`<button type="button" class="quick-buy-drawer__chip" role="radio" aria-checked="false" data-option-value="${this.#escHtml(val)}"> 2 <span class="quick-buy-drawer__chip-text">${this.#escHtml(val)}</span> 3 </button>`).join("");return` 4 <div class="quick-buy-drawer__option" data-option-index="${idx}"> 5 <p class="quick-buy-drawer__option-label">${this.#escHtml(optionName)}</p> 6 <div class="quick-buy-drawer__chips" role="radiogroup" aria-label="${this.#escHtml(optionName)}"> 7 ${chipsHtml} 8 </div> 9 </div>`}).join(""),thumbHtml=product.images?.[0]?`<img class="quick-buy-drawer__thumb" src="${product.featured_image}" alt="" width="80" height="80" loading="lazy">`:"",price=product.variants[0]?.price??0,compareAtPrice=product.variants[0]?.compare_at_price??0,onSale=compareAtPrice>price,innerHTML=` 10 <div class="quick-buy-drawer__scrim" data-quick-buy-close></div> 11 <div class="quick-buy-drawer__panel" role="dialog" aria-modal="true" aria-labelledby="quick-buy-title-${product.id}"> 12 <button class="quick-buy-drawer__close" type="button" data-quick-buy-close aria-label="Close"> 13 <svg viewBox="0 0 24 24" width="22" height="22" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round" aria-hidden="true"> 14 <path d="M6 6l12 12M18 6L6 18"/> 15 </svg> 16 </button> 17 <div class="quick-buy-drawer__head"> 18 ${thumbHtml} 19 <div class="quick-buy-drawer__meta"> 20 <h2 id="quick-buy-title-${product.id}" class="quick-buy-drawer__title">${this.#escHtml(product.title)}</h2> 21 <p class="quick-buy-drawer__price${onSale?" quick-buy-drawer__price--on-sale":""}" data-quick-buy-price> 22 <span class="quick-buy-drawer__price-current" data-quick-buy-price-current>${this.#formatMoney(price)}</span> 23 <s class="quick-buy-drawer__price-compare" data-quick-buy-price-compare${onSale?"":" hidden"}>${this.#formatMoney(compareAtPrice)}</s> 24 </p> 25 </div> 26 </div> 27 ${optionsHtml} 28 <button class="quick-buy-drawer__atc" type="button" data-quick-buy-add data-default-label="Add to cart" disabled> 29 Add to cart 30 </button> 31 </div>`,replacement=document.createElement("quick-buy-drawer");replacement.className=this.className,this.hasAttribute("hidden")&&replacement.setAttribute("hidden",""),replacement.setAttribute("data-product-id",product.id),replacement.setAttribute("data-variants",JSON.stringify(variants)
31),replacement.innerHTML=innerHTML;const placeholder=this._portalPlaceholder;return placeholder?.parentNode?(placeholder.parentNode.insertBefore(replacement,placeholder),placeholder.remove()):this.parentNode?this.parentNode.insertBefore(replacement,this):document.body.appendChild(replacement),this.remove(),replacement}catch(err){return console.error("[QuickBuyDrawer] refreshFromProductJson:",err),null}}#formatMoney(cents){return typeof Shopify<"u"&&Shopify.formatMoney?Shopify.formatMoney(cents,window.theme?.moneyFormat??"${{amount}}"):"$"+(cents/100).toFixed(2)}#escHtml(str){return String(str).replace(/&/g,"&").replace(/"/g,""").replace(/</g,"<").replace(/>/g,">")}async addToCart(){if(!this.matchedVariant||!this.matchedVariant.available)return;const miniCart=document.querySelector("mini-cart"),sections=miniCart?miniCart.getSectionsToRender().map(s=>s.id):[];this.atcBtn.classList.add("loading"),this.atcBtn.disabled=!0;try{const data=await(await fetch(window.theme.routes.cart_add_url,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/javascript","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({id:this.matchedVariant.id,quantity:1,sections,sections_url:window.location.pathname})})).json();data.status===422?document.dispatchEvent(new CustomEvent("ajaxProduct:error",{detail:{errorMessage:data.description}})):(miniCart&&miniCart.renderContents(data),document.dispatchEvent(new CustomEvent("ajaxProduct:added",{detail:{product:data}})),this.close())}catch(e){console.error(e),this.atcBtn.textContent="Try again"}finally{this.atcBtn.classList.remove("loading"),this.atcBtn.disabled=!1}}}customElements.define("quick-buy-drawer",QuickBuyDrawer);class QuickBuyButton extends HTMLElement{constructor(){super(),this.addEventListener("click",event=>{const wrapper=this.closest(".card-wrapper")||this.closest(".images_variant_container");if(!wrapper)return;const drawer=wrapper.querySelector("quick-buy-drawer");drawer&&typeof drawer.open=="function"&&drawer.open()})}}customElements.define("quick-buy-button",QuickBuyButton)})(); 32//# sourceMappingURL=/cdn/shop/t/172/assets/quick-buy-drawer.js.map?v=57292487813900537041788816988
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.