1import{EVENTS,publish,subscribe}from"@archetype-themes/utils/pubsub";class BlockBuyButtons extends HTMLElement{connectedCallback(){this.addEventListener("submit",this.handleSubmit.bind(this)),this.variantChangeUnsubscriber=subscribe(`${EVENTS.variantChange}:${this.dataset.sectionId}:${this.dataset.productId}`,this.handleVariantChange.bind(this)),this.cartType=this.dataset.cartType}disconnectedCallback(){this.variantChangeUnsubscriber()}handleVariantChange({detail}){const{html,variant}=detail;if(!variant){this.toggleAddButton(!0,this.getLocales().unavailable);return}this.updateVariantInput(variant),this.renderProductInfo(html)}renderProductInfo(html){const addButtonUpdated=html.getElementById(`ProductSubmitButton-${this.dataset.sectionId}`);addButtonUpdated&&this.toggleAddButton(addButtonUpdated.hasAttribute("disabled"),this.getLocales().soldOut)}getLocales(){return this.locales=this.locales||JSON.parse(this.querySelector('[type="application/json"]').textContent),this.locales}toggleAddButton(disable=!0,text){const productForm=this.querySelector(`#product-form-${this.dataset.sectionId}`);if(!productForm)return;const addButton=productForm.querySelector('[name="add"]'),addButtonText=productForm.querySelector('[name="add"] > span');addButton&&(disable?(addButton.setAttribute("disabled","disabled"),text&&(addButtonText.textContent=text)):(addButton.removeAttribute("disabled"),addButtonText.textContent=this.dataset.template!=="preorder"?this.getLocales().addToCart:this.getLocales().preOrder))}updateVariantInput(variant){this.querySelectorAll(`#product-form-${this.dataset.sectionId}, #product-form-installment-${this.dataset.sectionId}`).forEach(productForm=>{const input=productForm.querySelector('input[name="id"]');input.value=variant.id,input.dispatchEvent(new Event("change",{bubbles:!0}))})}async handleSubmit(event){if(this.cartType!="page"){event.preventDefault(),this.disableAddToCartButton();try{const responseJson=await this.addVariantToCart();publish(EVENTS.ajaxProductAdded,{detail:{product:responseJson,addToCartBtn:this.querySelector(`#ProductSubmitButton-${this.dataset.sectionId}`)}}),window.location.href=="https://www.antiqueroseemporium.com/cart"&&setTimeout(function(){window.location.reload()},1e3)}catch(error){this.handleError(error)}finally{this.enableAddToCartButton()}}}handleError(error){if(!error.description){console.warn(error);return}let form=this.querySelector("form"),errors=this.querySelector("form .errors");errors&&errors.remove();let errorDiv=document.createElement("div");errorDiv.classList.add("errors","text-center"),typeof error.description=="object"?errorDiv.textContent=error.message:errorDiv.textContent=error.description,form.append(errorDiv),publish(EVENTS.ajaxProductError,{detail:{errorMessage:error.description}})}async addVariantToCart(){const formData=this.getFormDataWithSections(),response=await fetch(`${window.Shopify.routes.root}cart/add.js`,{method:"POST",headers:{"X-Requested-With":"XMLHttpRequest"},body:formData});if(!response.ok)throw await response.json();return response.json()}async fetchCart(){return(await fetch(`${window.Shopify.routes.root}cart.js`)).json()}getFormDataWithSections(){const productForm=this.querySelector(`#product-form-${this.dataset.sectionId}`),formData=new FormData(productForm);return formData.set("sections_url",`${window.Shopify.routes.root}variants/${productForm.id.value}`),formData}enableAddToCartButton(){const productForm=this.querySelector(`#product-form-${this.dataset.sectionId}`);if(!productForm)return;const addButton=productForm.querySelector('[name="add"]');addButton.removeAttribute("aria-busy"),addButton.classList.remove("btn--loading")}disableAddToCartButton(){const productForm=this.querySelector(`#product-form-${this.dataset.sectionId}`),errors=this.querySelector("form .errors");if(errors&&errors.remove(),!productForm)return;const addButton=productForm.querySelector('[name="add"]');addButton.setAttribute("aria-busy","true"),addButton.classList.add("btn--loading")}}customElements.define("block-buy-buttons",BlockBuyButtons); 2//# sourceMappingURL=/cdn/shop/t/169/assets/block-buy-buttons.js.map?v=86031328441672129101789593020
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.