1customElements.get("checkout-buy-button")||customElements.define("checkout-buy-button",class extends HTMLElement{constructor(){super(),this.loading=!1,this.onClick=this.onClick.bind(this),this.onPageShow=this.onPageShow.bind(this)}connectedCallback(){this.form=this.closest("form"),this.container=this.form&&this.form.closest(".product-form")||this.form,this.button=this.querySelector('button[type="submit"]'),!(!this.form||!this.button)&&(this.button.addEventListener("click",this.onClick),window.addEventListener("pageshow",this.onPageShow),this.keepLabel())}disconnectedCallback(){this.button&&this.button.removeEventListener("click",this.onClick),window.removeEventListener("pageshow",this.onPageShow),this.labelObserver&&this.labelObserver.disconnect()}keepLabel(){const span=this.button.querySelector("span");if(!span||!this.dataset.label)return;const reassert=()=>{if(this.button.hasAttribute("disabled"))return;const addToCart=window.FoxTheme&&FoxTheme.variantStrings&&FoxTheme.variantStrings.addToCart||"Add to cart";span.textContent.trim()===addToCart.trim()&&(span.textContent=this.dataset.label)};reassert(),this.labelObserver=new MutationObserver(reassert),this.labelObserver.observe(span,{childList:!0,characterData:!0,subtree:!0})}get routeRoot(){return window.Shopify&&window.Shopify.routes&&window.Shopify.routes.root||"/"}async onClick(event){if(event.preventDefault(),!this.loading){this.setLoading(!0),this.clearError();try{await fetch(`${this.routeRoot}cart/clear.js`,{method:"POST",headers:{"Content-Type":"application/json"}});const response=await fetch(`${this.routeRoot}cart/add.js`,{method:"POST",headers:{Accept:"application/javascript","X-Requested-With":"XMLHttpRequest"},body:new FormData(this.form)}),data=await response.json();if(!response.ok||data.status){this.handleAddError(data);return}const cart=await(await fetch(`${this.routeRoot}cart.js`)).json();if(!cart||cart.item_count<1){this.setLoading(!1),this.showError(this.genericError());return}window.location.href=`${this.routeRoot}checkout`}catch(error){console.error("[checkout-buy-button]",error),this.setLoading(!1),this.showError(this.genericError())}}}handleAddError(data){this.setLoading(!1);const pubsub=window.FoxTheme&&FoxTheme.pubsub;pubsub&&pubsub.PUB_SUB_EVENTS&&pubsub.publish(pubsub.PUB_SUB_EVENTS.cartError,{source:"product-form",productVariantId:new FormData(this.form).get("id"),errors:data.errors||data.description,message:data.message}),this.form.dataset.hideErrors!=="true"&&this.showError(data.description||data.message||this.genericError())}setLoading(isLoading){this.loading=isLoading,this.button.classList.toggle("btn--loading",isLoading),isLoading?this.button.setAttribute("disabled",""):this.button.removeAttribute("disabled")}showError(message){const wrapper=this.container.querySelector(".product-form__error-message-wrapper"),el=this.container.querySelector(".product-form__error-message");wrapper&&(wrapper.hidden=!1),el&&(el.hidden=!1,el.textContent=message)}clearError(){const wrapper=this.container.querySelector(".product-form__error-message-wrapper"),el=this.container.querySelector(".product-form__error-message");wrapper&&(wrapper.hidden=!0),el&&(el.hidden=!0,el.textContent="")}genericError(){return(window.FoxTheme&&FoxTheme.cartStrings||{}).error||"There was an error while updating your cart. Please try again."}onPageShow(event){event.persisted&&this.setLoading(!1)}}); 2//# sourceMappingURL=/cdn/shop/t/46/assets/checkout-buy-button.js.map?v=128020414440677128201791188776
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.