1import{executeJSmodules}from"@archetype-themes/scripts/helpers/utils";import{EVENTS,publish}from"@archetype-themes/utils/pubsub";class QuickAdd extends HTMLElement{constructor(){super(),this.selectors={quickAddBtn:"[data-single-variant-quick-add]",quickAddHolder:"[data-tool-tip-content]"},this.init()}init(){const quickAddBtn=this.querySelector(this.selectors.quickAddBtn);quickAddBtn?quickAddBtn.addEventListener("click",this.addToCart.bind(this)):(this.addEventListener("tooltip:interact",async e=>{e.detail.context==="QuickAdd"&&(this.quickAddData||(this.quickAddData=await this.loadQuickAddForm(e)))}),this.addEventListener("tooltip:open",async e=>{if(e.detail.context==="QuickAdd"){this.quickAddData||(this.quickAddData=await this.loadQuickAddForm(e));const quickAddContainer=document.querySelector(this.selectors.quickAddHolder);quickAddContainer.innerHTML=this.quickAddData.outerHTML,document.dispatchEvent(new CustomEvent("quickshop:opened")),Shopify&&Shopify.PaymentButton&&Shopify.PaymentButton.init();const scripts=document.querySelectorAll(`tool-tip [data-product-id="${this.prodId}"] script[type="module"]`);executeJSmodules(scripts)}}))}addToCart(evt){const btn=evt.currentTarget,visibleBtn=btn.querySelector(".btn"),id=btn.dataset.id;visibleBtn.classList.add("btn--loading");const data={items:[{id,quantity:1}]};fetch(window.Shopify.routes.root+"cart/add.js",{method:"POST",body:JSON.stringify(data),credentials:"same-origin",headers:{"Content-Type":"application/json"}}).then(response=>response.json()).then(data2=>{data2.status===422||data2.status==="bad_request"?data2.description&&alert(data2.description):publish(EVENTS.ajaxProductAdded,{detail:{product:data2,addToCartBtn:btn}}),visibleBtn.classList.remove("btn--loading")})}async loadQuickAddForm(evt){const gridItem=evt.currentTarget.closest(".grid-product"),handle=gridItem.firstElementChild.getAttribute("data-product-handle");this.prodId=gridItem.firstElementChild.getAttribute("data-product-id");let url=`${window.Shopify.routes.root}/products/${handle}?view=form`;url=url.replace("//","/");try{const html=await(await fetch(url)).text(),div=new DOMParser().parseFromString(html,"text/html").querySelector(`.page-content[data-product-id="${this.prodId}"]`);return this.processHTML(div),window.dispatchEvent(new CustomEvent(`quickadd:loaded:-${this.prodId}`)),document.dispatchEvent(new CustomEvent("quickadd:loaded",{detail:{productId:this.prodId,handle}})),div}catch(error){console.error("Error:",error)}}processHTML(productElement){this.removeBreadcrumbs(productElement),this.preventVariantURLSwitching(productElement)}removeBreadcrumbs(productElement){const breadcrumbs=productElement.querySelector(".breadcrumb");breadcrumbs&&breadcrumbs.remove()}preventVariantURLSwitching(productElement){const variantPicker=productElement.querySelector("block-variant-picker");variantPicker&&variantPicker.removeAttribute("data-update-url")}}customElements.define("quick-add",QuickAdd); 2//# sourceMappingURL=/cdn/shop/t/69/assets/quick-add.js.map?v=153468363738513771401728897735
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.