1class ProductForm extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.qtyBtns=this.querySelectorAll("[data-qty-btn]"),this.cartElement=document.querySelector("cart-form"),this.variantMetafieldElement=this.form?this.form.querySelector("[data-variantJSON-metafields]"):null,this.defaultUpsellMultiplier=3,this.moneyFormat=window?.globalVariables?.money_format,this.productContainer=this.closest("[data-product-container]")||document,this.submitButton=null,this.qtyInputField=null,this.upsellManager=null}connectedCallback(){if(this.form.addEventListener("submit",this.onSubmitHandler.bind(this)),this.querySelector("[data-qty-container]")&&this.qtyBtns.forEach(qtyBtn=>qtyBtn.addEventListener("click",this.manageQtyBtn.bind(this))),window.BubsUpsellModalManager){const modalEl=this.productContainer?.querySelector("[data-upsell-modal]")||document.querySelector("[data-upsell-modal]");this.upsellManager=new window.BubsUpsellModalManager({productForm:this,formElement:this.form,modalElement:modalEl,variantMetafieldJSON:this.variantMetafieldElement?this.variantMetafieldElement.textContent:null,defaultMultiplier:this.defaultUpsellMultiplier,moneyFormat:this.moneyFormat,productId:this.form?.dataset?.productId,productTitle:window?.globalVariables?.product?.title||document?.querySelector("[data-product-title]")?.textContent?.trim(),currency:window?.Shopify?.currency?.active||window?.globalVariables?.currency||"USD",modalVariant:"default",onSubmit:payload=>this.sendAddToCartRequest(payload)})}}onSubmitHandler(evt){evt.preventDefault();const submitButton=this.querySelector('[type="submit"]'),qtyInput=this.querySelector("[data-qty-input]");this.submitButton=submitButton,this.qtyInputField=qtyInput;let itemPayload={};try{itemPayload=JSON.parse(Utility.serializeForm(this.form))}catch(error){console.error("[Product form] Unable to serialize form for submission",error),window.notificationEle&&window.notificationEle.updateNotification("Add to Cart","Something went wrong. Please try again.",{type:"error",timeout:5e3});return}this.form.dataset.format!=="quantity-block"&&(this.form.querySelector("[data-purchase_type] input:checked")?.closest("[data-purchase_type]")?.getAttribute("data-purchase_type")||"onetime")==="onetime"&&(delete itemPayload.selling_plan,delete itemPayload.selling_plan_group),(itemPayload.selling_plan===""||itemPayload.selling_plan===null)&&delete itemPayload.selling_plan,!(this.upsellManager&&this.upsellManager.handleSubmit(itemPayload))&&this.sendAddToCartRequest(itemPayload)}setLoadingState(isLoading){const submitButton=this.submitButton||this.querySelector('[type="submit"]');submitButton&&(isLoading?(submitButton.classList.add("loading"),submitButton.setAttribute("disabled",!0)):(submitButton.classList.remove("loading"),submitButton.removeAttribute("disabled"))),document.querySelectorAll("[data-atc-out]")?.forEach(ele=>{isLoading?(ele.classList.add("loading"),ele.setAttribute("aria-disabled","true"),ele.setAttribute("disabled","disabled")):(ele.classList.remove("loading"),ele.removeAttribute("disabled"),ele.setAttribute("aria-disabled","false"))})}getSectionsToRender(){return`${window.globalVariables?.template=="cart"?"template-cart":"component-cart-drawer"},header`}sendAddToCartRequest(payload){if(!payload)return;const body=JSON.stringify({items:[payload],sections:this.getSectionsToRender()});this.setLoadingState(!0);const cartAddUrl=window.routes?.cart_add_url||"/cart/add.js",normalizedCartAddUrl=cartAddUrl.endsWith(".js")?cartAddUrl:`${cartAddUrl}.js`;fetch(normalizedCartAddUrl,{...Utility.fetchConfig(),body}).then(response=>response.ok?response.json().catch(()=>{throw new Error("Invalid response from server. Please try again.")}):response.text().then(text=>{const isLocalPreview=/^(localhost|127\.0\.0\.1)$/.test(window.location.hostname),message=response.status===502&&isLocalPreview?"Add to cart isn't working in local preview (502). Try again or test on your live store.":text||`Add to cart failed (${response.status})`;throw new Error(message)})).then(res=>{let dataJSON=typeof res=="object"?res:JSON.parse(res);if(dataJSON.errors){console.error("[Product form] Add to cart error",dataJSON.errors),window.notificationEle?.updateNotification("Add to Cart",dataJSON.errors,{type:"error",timeout:5e3});return}this.qtyInputField&&(this.qtyInputField.value=1),window.posthog&&posthog.capture("add_to_cart",{variant_id:String(payload.id),product_id:this.form?.dataset?.productId,product_name:window.globalVariables?.product?.title||null,quantity:payload.quantity||1,purchase_type:payload.selling_plan?"subscription":"one_time",selling_plan_id:payload.selling_plan?String(payload.selling_plan):null}),fetch("/cart.js").then(cartRes=>cartRes.ok?cartRes.json():Promise.reject(new Error("Cart unavailable"))).then(cart=>{document.dispatchEvent(new CustomEvent("cart:updated",{detail:cart})),document.dispatchEvent(new CustomEvent("recharge:cart:updated",{detail:cart}))}).catch(()=>{}),this.cartElement&&typeof this.cartElement._updateCart=="function"?this.cartElement._updateCart(d
1ataJSON.sections,"open_drawer"):this.cartElement&&typeof this.cartElement.getCartData=="function"&&this.cartElement.getCartData("open_drawer")}).catch(e=>{console.error("[Product form] Add to cart request failed",e);const message=e&&e.message?e.message:"Something went wrong. Please try again.";window.notificationEle?.updateNotification("Error",message,{type:"error",timeout:5e3})}).finally(()=>{this.setLoadingState(!1)})}manageQtyBtn(event){event.preventDefault();let currentTarget=event.currentTarget,action=currentTarget.dataset.for||"increase",$qtyInput=currentTarget.closest("[data-qty-container]").querySelector("[data-qty-input]"),currentQty=parseInt($qtyInput.value)||1,finalQty=1,decreaseQtyBtn=currentTarget.closest("[data-qty-container]").querySelector('[data-for="decrease"]');if(action=="decrease"&¤tQty<=1)return decreaseQtyBtn&&decreaseQtyBtn.classList.add("disabled"),!1;action=="decrease"?(finalQty=currentQty-1,finalQty==1?decreaseQtyBtn.classList.add("disabled"):decreaseQtyBtn.classList.remove("disabled")):(decreaseQtyBtn&&decreaseQtyBtn.classList.remove("disabled"),finalQty=currentQty+1),$qtyInput.value=finalQty}}customElements.define("product-form",ProductForm); 2//# sourceMappingURL=/cdn/shop/t/123/assets/product-form-main.js.map?v=78948274984563624201784065346
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.