1(()=>{var __webpack_exports__={};class ProductForm extends HTMLElement{constructor(){super(),this.cacheDOMElements(),this.onSubmitBound=this.onSubmit.bind(this),Array.from(this.noscriptElements).forEach(element=>element.remove())}cacheDOMElements(){this.form=this.querySelector("form"),this.noscriptElements=this.querySelectorAll("noscript"),this.sectionId=this.getAttribute("data-section-id"),this.productInformation=this.closest("product-information"),this.cartAction=document.getElementById("PageContainer").dataset.cartAction,this.cartType=document.getElementById("PageContainer").dataset.cartType,this.cartCountIndicator=document.querySelector("[data-cart-count-indicator]"),this.giftWrapProductId=this.getAttribute("data-gift-wrap-product-id"),this.wethemeGlobal=document.querySelector("script#wetheme-global"),this.translationsObject=JSON.parse(this.wethemeGlobal.textContent),this.qtyErrorMessage=this.querySelector("[data-qty-error-message]")}connectedCallback(){this.form&&this.attachEventListeners()}attachEventListeners(){this.form.addEventListener("submit",this.onSubmitBound)}onSubmit(event){event.preventDefault(),this.prepareForSubmission()}prepareForSubmission(){this.cacheSubmissionElements(),this.checkRequiredInputs()&&(this.showLoadingState(),this.appendPropertiesAsHiddenInputs(),this.addItemsToCart())}cacheSubmissionElements(){this.loadingIcon=this.form.querySelector("[data-loading-icon]"),this.addToCartText=this.form.querySelector("[data-add-to-cart-text]"),this.addedText=this.form.querySelector("[data-cart-added-text]"),this.quantityInput=this.form.querySelector('[name="quantity"]'),this.quantity=this.quantityInput&&parseInt(this.quantityInput.value,10)||1}fetchConfig(type="json"){return{method:"POST",headers:{"Content-Type":"application/json",Accept:`application/${type}`}}}checkRequiredInputs(){const requiredInputs=Array.from(this.form.querySelectorAll("[required]:not(:disabled)"));this.clearErrorMessages();const invalidInputs=requiredInputs.filter(input=>!input.value.trim());return invalidInputs.forEach(input=>this.applyErrorMessage(input)),invalidInputs.length===0}clearErrorMessages(){this.form.querySelectorAll(".required-field-error").forEach(error=>error.remove())}applyErrorMessage(input){const errorElement=`<span class="required-field-error" style="color:var(--error-color);">${this.translationsObject.translations.required_input_error}</span>`;input.insertAdjacentHTML("afterend",errorElement),input.classList.contains("input-error")||(input.classList.add("input-error"),input.focus())}appendPropertiesAsHiddenInputs(){this.productInformation&&(this.removeAllDynamicHiddenInputs(),this.addPropertyInput
1s(),this.disableEmptyInputs())}disableEmptyInputs(){this.form.querySelectorAll("input, textarea").forEach(input=>{input.value||(input.disabled=!0)})}removeAllDynamicHiddenInputs(){this.form.querySelectorAll(".dynamic-hidden-input").forEach(input=>input.remove())}addPropertyInputs(){this.productInformation.querySelectorAll('[data-custom-property][name^="properties["]').forEach(element=>this.constructHiddenInput(element))}constructHiddenInput(element){if(this.shouldElementBeIgnored(element))return;const hiddenInput=document.createElement("input");hiddenInput.type="hidden",hiddenInput.name=element.name,hiddenInput.value=element.value,hiddenInput.classList.add("dynamic-hidden-input"),this.form.appendChild(hiddenInput)}shouldElementBeIgnored(element){return element.type==="file"?this.handleFileInput(element):(element.type==="checkbox"||element.type==="radio")&&!element.checked||element.type!=="checkbox"&&element.type!=="radio"&&!element.value}handleFileInput(element){return element.style.display="none",this.form.appendChild(element),!0}giftWrapEnabled(){return!!this.form.querySelector('[name="properties[Gift wrap]"]')&&this.giftWrapProductId!==""}async addItemsToCart(){try{const mainProductAdded=await this.addProductToCart(routes.cart_add_url,this.fetchConfigWithBody());mainProductAdded&&this.giftWrapEnabled()&&await this.addProductToCart(routes.cart_add_url,this.additionalProductConfig(this.giftWrapProductId,this.quantity)),this.processResponse(mainProductAdded)}catch(error){console.error(`Error adding item(s) to cart: ${error.description||error.message}`)}}async addProductToCart(url,config){const response=await fetch(url,config);return response.ok||console.error(`Error adding item to cart: ${response.description||response.statusText}`),response}additionalProductConfig(productId,quantity){return{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({items:[{id:productId,quantity}]})}}async getCart(){try{return await(await fetch(`${routes.cart_url}?view=compare`)).json()}catch(error){console.error(`Error fetching cart: ${error.description||error.message}`)}}updateCartCountIndicator(){this.cartCountIndicator&&(this.getCart().then(cart=>this.cartCountIndicator.textContent=cart.item_count),this.cartCountIndicator.classList.contains("hide")&&this.cartCountIndicator.classList.remove("hide"))}fetchConfigWithBody(){const config=this.fetchConfig("javascript");return config.headers["X-Requested-With"]="XMLHttpRequest",delete config.headers["Content-Type"],config.body=new FormData(this.form),config}processResponse(response){response.ok&&this.hideLoadingState(),response.status===422&&(this.hideLoadingState(),this.qtyErrorMessage&&this.qtyErrorMessage.classList.remove("hidden")),eventBus.emit("cart:added",{sectionId:this.sectionId})}toggleCartDrawer(){this.getCart().then(cart=>{eventBus.emit("toggle:right:drawer",{type:"cart",forceOpen:!0,params:{cart}})}).catch(error=>{console.error(`Error fetching cart: ${error}`)})}showLoadingState(){this.toggleElements(this.addToCartText,!1),this.toggleElements(this.loadingIcon,!0,"hidden"),this.toggleAddButton(!0)}hideLoadingState(){this.toggleElements(this.loadingIcon,!1,"hidden"),this.toggleCartActionDisplay()}toggleCartActionDisplay(){this.cartAction==="show_added_message"&&this.addedText?(this.addedText.style.display="block",setTimeout(()=>{this.toggleAddToCartText(!0),this.toggleAddButton(!1),this.updateCartCountIndicator()},2e3)):this.cartType==="drawer"&&this.cartAction==="go_to_or_open_cart"?(this.toggleAddToCartText(!0),this.toggleCartDrawer(),this.toggleAddButton(!1)):(this.toggleAddToCartText(!0),this.toggleAddButton(!1),window.location=window.routes.cart_url)}toggleAddToCartText(show){this.addedText&&(this.addedText.style.display=show?"none":"block"),this.addToCartText&&(this.addToCartText.style.display=show?"block":"none")}toggleElements(element,show,className){element&&(className?show?element.classList.remove(className):element.classList.add(className):element.style.display=show?"block":"none")}toggleAddButton(disable=!0){const addButton=this.querySelector('[name="add"]');addButton&&(addButton.disabled=disable)}disconnectedCallback(){this.form.removeEventListener("submit",this.onSubmitBound)}}customElements.get("product-form")||customElements.define("product-form",ProductForm)})(); 2//# sourceMappingURL=/cdn/shop/t/33/assets/component-product-form.js.map?v=77862887852674110531759876212
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.