1customElements.get("product-form")||customElements.define("product-form",class extends HTMLElement{constructor(){super(),this.observer=null}connectedCallback(){this.form=this.querySelector("form"),this.form.querySelector("[name=id]").disabled=!1,this.form.addEventListener("submit",this.onSubmitHandler.bind(this)),this.preOrderAvailable=this.dataset.preOrder,this.cart=document.querySelector("cart-notification")||document.querySelector("cart-drawer"),this.cartItems=this.cart?this.cart.querySelector("cart-items"):null,this.submitButton=this.querySelector('[type="submit"]'),document.querySelector("cart-drawer")&&this.submitButton.setAttribute("aria-haspopup","dialog"),document.addEventListener("addToCartError",e=>{this.errorMessageDisplay(e)});const setupIcons=()=>{this.setupMessageOnly(this),this.setupGiftWrap(this)};this.observer=new MutationObserver(mutations=>{mutations.forEach(mutation=>{mutation.type==="attributes"&&mutation.target.nodeName==="WRAPPED-PRODUCT-PROVIDER"&&setupIcons()})}),this.observer.observe(this,{childList:!0,subtree:!0,attributes:!0})}disconnectedCallback(){this.observer&&this.observer.disconnect()}createMessageIcon=()=>{const messageSvg=document.createElementNS("http://www.w3.org/2000/svg","svg");messageSvg.setAttribute("width","16"),messageSvg.setAttribute("height","15"),messageSvg.setAttribute("viewBox","0 0 16 15"),messageSvg.setAttribute("fill","none"),messageSvg.style.marginRight="10px",messageSvg.style.marginLeft="1px";const path=document.createElementNS("http://www.w3.org/2000/svg","path");return path.setAttribute("d","M8 3.92832C8 3.15168 7.705 2.40685 7.1799 1.85769C6.6548 1.30852 5.94261 1 5.2 1H1V11.9812H5.9C6.45695 11.9812 6.9911 12.2126 7.38492 12.6245C7.77875 13.0363 8 13.595 8 14.1774M8 3.92832V14.1774M8 3.92832C8 3.15168 8.295 2.40685 8.8201 1.85769C9.3452 1.30852 10.0574 1 10.8 1H15V11.9812H10.1C9.54305 11.9812 9.0089 12.2126 8.61508 12.6245C8.22125 13.0363 8 13.595 8 14.1774"),path.setAttribute("stroke","#1E1E1E"),path.setAttribute("stroke-width","1.46416"),path.setAttribute("stroke-linecap","round"),path.setAttribute("stroke-linejoin","round"),messageSvg.appendChild(path),messageSvg};createGiftWrapImage=()=>{const img=new Image;return img.src="https://cdn.shopify.com/s/files/1/0770/2878/6454/files/Screenshot_2024-09-09_at_2.46.52_PM_3_2.png?v=1727308999",img.style.width="18px",img.style.height="18px",img.style.marginRight="10px",img};setupMessageOnly=wrappedCartItem=>{let shopUrl=window.location.href,disableGiftMessage="49919364825380";shopUrl.includes("dev")&&(disableGiftMessage="49141998190870");const messageOnly=wrappedCartItem.querySelector(`[data-variant-id="${disableGiftMessage}"]`);if(messageOnly&&!messageOnly.querySelector("svg")){const title=messageOnly.querySelector('span[part="title"]');if(title){const messageSvg=this.createMessageIcon();title.prepend(messageSvg)}}};setupGiftWrap=wrappedCartItem=>{let shopUrl=window.location.href,disableGiftWrap="49919347261732";shopUrl.includes("dev")&&(disableGiftWrap="46392720195862");const giftWrap=wrappedCartItem.querySelector(`[data-variant-id="${disableGiftWrap}"]`);if(giftWrap){const giftTitle=giftWrap.querySelector('span[part="title"]');if(!giftTitle.querySelector("img")){const img=this.createGiftWrapImage();giftTitle.prepend(img)}}};onSubmitHandler(evt){async function fetchCartData(){return await(await fetch("/cart.js")).json()}const mattressFee=this.getAttribute("data-mattress-fee");if(evt.preventDefault(),this.submitButton.getAttribute("aria-disabled")==="true")return;this.handleErrorMessage(),this.submitButton.setAttribute("aria-disabled",!0),this.submitButton.classList.add("animate-pulse");const config=fetchConfig("javascript");config.headers["X-Requested-With"]="XMLHttpRequest",delete config.headers["Content-Type"];const formData=new FormData(this.form),updateCartSections=()=>{const sectionIds=[{id:"CartDrawer__Dialog",section:"cart-drawer",selector:"data-cart-inner"},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"}].map(section=>section.section);return fetch(`/?sections=${sectionIds}`,{headers:{Accept:"application/json"}}).then(response=>{if(response.ok)return response.json()}).then(sectionUpdateData=>{if(sectionUpdateData)return this.cart.renderContents({sections:sectionUpdateData})})};this.cart&&(formData.append("sections",this.cart.getSectionsToRender().map(section=>section.id)),formData.append("sections_url",window.location.pathname),this.cart.setActiveElement(document.activeElement)),config.body=formData,fetch(`${routes.cart_add_url}`,config).then(response=>response.json()).then(data=>{if(data.status&&!this.preOrderAvailable){this.handleErrorMessage(data.description);const soldOutMessage=this.submitButton.querySelector("[data-product-form-error-message]");if(data.status===422&&data.description.includes("due to availability")&&setTimeout(()=>{updateCartSections()},2e3),!soldOutMessage)return;this.submitButton.setAttribute("aria-disabled",!0),this.submitButton.querySelector("span").classList.add("hidden"),soldOutMessage.classList.remove("hidden"),this.error=!0;return}if(!this.cart){window.location=window.routes.cart_url;return}if(mattressFee===null){this.cart.renderContents(data),this.error=!1;return}this.cart.renderContents(data);const maxQuantity=1,productFees=getProductFees();return(async()=>{let cart;try{cart=await fetchCartData()}catch(error){console.error("Error resolving cart data:",error),this.error=!0;return}const feeCartItem=variantId=>cart.items.find(item=>String(item.variant_id)===String(variantId)||String(item.id)===String(variantId)),nonFeeItems=cart.items.filter(item=>!isProductFeeCartItem(item,productFees));
1let mattressFeeArray=mattressFee.split(",").filter(Boolean);mattressFeeArray=mattressFeeArray.filter(fee=>{const feeConfig=getProductFeeByVariantId(fee,productFees);return feeCartItem(fee)?productFeeMatchesQuantity(feeConfig):!0});const canBatchSimpleAdds=mattressFeeArray.length>=2&&mattressFeeArray.every(fee=>{const feeConfig=getProductFeeByVariantId(fee,productFees);return!feeCartItem(fee)&&applicableProductQty(nonFeeItems,feeConfig)<=1}),handleFeeError=mattressData=>{if(!mattressData?.status||this.preOrderAvailable)return!1;this.handleErrorMessage(mattressData.description||mattressData.message);const soldOutMessage=this.submitButton.querySelector("[data-product-form-error-message]");return soldOutMessage?(this.submitButton.setAttribute("aria-disabled",!0),this.submitButton.querySelector("span").classList.add("hidden"),soldOutMessage.classList.remove("hidden"),this.error=!0,!0):(this.error=!0,!0)};if(canBatchSimpleAdds){const batchResponse=await fetch(`${routes.cart_add_url}`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json","X-Requested-With":"XMLHttpRequest"},body:JSON.stringify({items:mattressFeeArray.map(fee=>({id:parseInt(fee,10),quantity:1}))})}),mattressData=await batchResponse.json(),batchFeeError=handleFeeError(mattressData);if(!batchResponse.ok&&!this.error&&(this.error=!0,this.handleErrorMessage(mattressData?.description||mattressData?.message||batchResponse.statusText)),!batchResponse.ok||batchFeeError){this.cart||(window.location=window.routes.cart_url);return}}else{const addMattressFee=async fee=>{const feeConfig=getProductFeeByVariantId(fee,productFees),existingFee=feeCartItem(fee),matchesQuantity=productFeeMatchesQuantity(feeConfig),targetQty=matchesQuantity?applicableProductQty(nonFeeItems,feeConfig):1;let mattressData=null;const mattressFeeFormData=new FormData;mattressFeeFormData.append("id",fee),matchesQuantity||(mattressFeeFormData.append("quantity",1),mattressFeeFormData.append("quantity_rule","max"),mattressFeeFormData.append("quantity_rule_value",1)),mattressFeeFormData.append("sections_url",window.location.pathname);const mattressFeeConfig={...config,body:mattressFeeFormData};if(existingFee&&matchesQuantity){const maxQty=existingFee.quantity_rule?.max??null,nextQty=maxQty===null?targetQty:Math.min(targetQty,maxQty),updates={[existingFee.key]:nextQty},response=await fetch(`${routes.cart_update_url}`,{...fetchConfig(),body:JSON.stringify({updates})});if(mattressData=await response.json(),!response.ok){this.error=!0,this.handleErrorMessage(mattressData?.description||mattressData?.message||response.statusText);return}}else{matchesQuantity&&targetQty>1&&mattressFeeFormData.set("quantity",String(targetQty));const response=await fetch(`${routes.cart_add_url}`,mattressFeeConfig);if(mattressData=await response.json(),!response.ok){this.error=!0,this.handleErrorMessage(mattressData?.description||mattressData?.message||response.statusText);return}}handleFeeError(mattressData)||this.cart||(window.location=window.routes.cart_url)};for(const fee of mattressFeeArray){if(this.error)break;await addMattressFee(fee)}if(this.error)return}if(this.error=!1,await updateCartSections(),mattressFee.split(",").filter(Boolean).some(fee=>{const feeConfig=getProductFeeByVariantId(fee,productFees),existingFee=feeCartItem(fee);return existingFee&&!productFeeMatchesQuantity(feeConfig)&&existingFee.quantity>=maxQuantity})){const cartItemError=document.querySelector('[data-mattress-fee="removal"]')?.querySelector("[data-cart-item-error-text]");if(cartItemError){const showError=cartItemError.closest("div");cartItemError.textContent=`You can only add up to ${maxQuantity} of this item.`,showError.setAttribute("data-show","true"),showError.classList.remove("hidden")}}})()}).catch(e=>{console.error(e),this.error=!0}).finally(()=>{this.submitButton.classList.remove("animate-pulse"),this.cart&&this.cart.getAttribute("data-empty")==="true"&&this.cart.setAttribute("data-empty",!1),this.error||this.submitButton.removeAttribute("aria-disabled")})}handleErrorMessage(errorMessage=!1){errorMessage&&this.dispatchEvent(new CustomEvent("addToCartError",{detail:{errors:errorMessage},bubbles:!0}))}errorMessageDisplay(e){let errorMessage=e.detail.errors&&typeof e.detail.errors!="object";this.errorMessageWrapper=this.errorMessageWrapper||this.querySelector("[data-product-form-error]"),this.errorMessageWrapper&&(this.errorMessage=this.errorMessage||this.errorMessageWrapper.querySelector("[data-product-form-error-message]"),this.errorMessageWrapper.toggleAttribute("aria-hidden",!errorMessage),this.errorMessage.innerText=e.detail.errors,setTimeout(()=>{this.errorMessageWrapper.setAttribute("aria-hidden",!0),this.errorMessage.innerText=""},3e3))}}); 2//# sourceMappingURL=/cdn/shop/t/491/assets/product-form.js.map?v=168931300965299851601790367354
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.