PageSourceSearch

https://wildlike.com/cdn/shop/t/94/assets/product-form.js?v=90434516846900511261727814895

js wildlike.com collected 2026-10-04 04:08:07 UTC 6,659 bytes, 7 lines download raw bytes

1customElements.get("product-form")||customElements.define("product-form",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.form.querySelector("[name=id]").disabled=!1,this.form.addEventListener("submit",this.onSubmitHandler.bind(this)),this.sidecart=document.querySelector("side-cart"),this.termsCheckbox=this.querySelector("input#so-terms-checkbox"),this.specialTermsCheckbox=this.querySelector("input#special-order-terms-checkbox"),this.errors=[],this.customFields=null,this.lineProps={},(this.termsCheckbox||this.specialTermsCheckbox)&&(this.termsCheckbox?.addEventListener("change",this.toggleATC.bind(this)),this.specialTermsCheckbox?.addEventListener("change",this.toggleATC.bind(this)),this.toggleATC())}getCustomFields(){return this.customFields=this.customFields||this.querySelector("#customFields")?.textContent?JSON.parse(this.querySelector("#customFields").textContent):null,JSON.parse(this.customFields)}validateCustomizationFields(){if(this.customFields=this.getCustomFields(),!(this.customFields?.personalization_fields&&this.customFields?.personalization_fields?.split(",")?.length))return this.errors=[],[];const helpTexts=(this.customFields.personalization_help_text||"").split("|###|"),labels=(this.customFields.personalization_label||"").split("|###|"),maxLengths=(this.customFields.personalization_max_length||"").split("|###|"),options=(this.customFields.personalization_options||"").split("|###|"),placeholders=(this.customFields.personalization_placeholder||"").split("|###|"),requiredFlags=(this.customFields.personalization_required||"").split("|###|"),types=(this.customFields.personalization_type||"").split("|###|");for(let i=0;i<labels.length;i++)this.lineProps[`${labels[i]}`]="";const customizationFields=this.customFields.personalization_fields.split(",").map(index=>({helpText:helpTexts[index],label:labels[index],maxLength:maxLengths[index],options:options[index]?options[index].split(",").map(opt=>({label:opt,value:opt})):[],placeholder:placeholders[index],required:requiredFlags[index],type:types[index]}));if(this.errors=[],customizationFields.length===0)return!0;for(let i=0;i<customizationFields.length;i++)this.querySelectorAll("[data-line-prop]")?.forEach(el=>{customizationFields[i].required==="1"&&(el?.value?.length===0||el?.selectedOptions?.length===0)&&this.errors.push(`${customizationFields[i].label} is required.`)})}toggleATC(){this.termsCheckbox.checked?this.querySelector('[type="submit"]').removeAttribute("disabled"):this.querySelector('[type="submit"]').setAttribute("disabled","disabled")}async addGiftToCart(){fetch("/cart.js").then(response=>response.json()).then(async data=>{let formData,applicableGif=!1;if(window.gift_by==="cart_amount")data.total_price>=Number(window.gift_price*100)&&(applicableGif=!0);else if(window.gift_by==="adding_product_with_tags"){const productTags=await Promise.all(data.items.map(async el=>{let productInfo=await fetch(`/products/${el.handle}.js`);return productInfo=await productInfo.json(),productInfo.tags})),applicableTags=window.gift_tags.split(",");productTags.forEach(pt=>{applicableGif||applicableTags.forEach(at=>{if(pt.includes(at)){applicableGif=!0;return}})})}if(!applicableGif)return;let isExist=!1;data.items.forEach((value,index,array)=>{value.id===+window.gift_variant_id&&(isExist=!0)}),!isExist&&(formData={items:[{id:parseInt(window.gift_variant_id),quantity:1}],sections:this.sidecart?.getSectionsToRender().map(section=>section.id).join()},fetch(`${routes.cart_add_url}.js`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(formData)}).then(response=>response.json()).then(response=>(this.sidecart?.renderContents(response),response)).catch(error2=>{console.error("Error:",error2);const toast=document.querySelector("toast-alert");toast&&toast.addMessage({type:"error",text:error2})}))}).catch(error2=>{console.error("Error:",error2);const toast=document.querySelector("toast-alert");toast&&toast.addMessage({type:"error",text:error2})})}onSubmitHandler(evt){evt.preventDefault();const submitButton=this.querySelector('[type="submit"]');if(this.validateCustomizationFields(),!submitButton||submitButton?.classList.contains("loading"))return;if(this.handleErrorMessage(this.errors),this.errors.length)return!1;this.sidecart?.setActiveElement(document.activeElement),submitButton.setAttribute("aria-disabled",!0),submitButton.setAttribute("disabled",!0),submitButton.classList.add("button--state-loading");const config=fetchConfig("json"),sections=this.sidecart?.getSectionsToRender().map(section=>section.section),formData=new FormData(this.form),id=parseInt(formData.get("id")),quantity=parseInt(formData.get("quantity"));config.body=JSON.stringify({id,quantity,sections:sections.filter((item,index)=>sections.indexOf(item)===index),sections_url:window.location.pathname}),fetch(`${routes.cart_add_url}.js`,config).then(response=>response.json()).then(response=>{if(response.status){this.handleErrorMessage([response.description]);return}this.sidecart.renderContents(response),submitButton.classList.remove("button--state-loading"),submitButton.classList.add("button--state-success"),window.gift_available&&!window.gift_variant_id.trim()==""&&this.addGiftToCart(),document.querySelector(".sidecart__contents")?.classList.toggle("is-empty",response.item_count===0),document.querySelector("body")?.classList.add("overflow-hidden");const cartUpdatedEvent=new CustomEvent("cartUpdated");document.dispatchEvent(cartUpdatedEvent)}).catch(e=>{console.error(e);const toast=document.querySelector("toast-alert");toast&&toast.addMessage({type:"error",text:error})}).finally(()=>{submitButton.removeAttribute("aria-disabled"),submitButton.removeAttribute("disabled"),submitButton.classList.remove("button--state-loading"),submitButton.classList.remove("button--state-success")})}handleErrorMessage(errorMessage=!1){if(this.errorMessageWrapper=this.errorMessageWrapper||this.querySelector(".product-form__errors"),!!this.errorMessageWrapper)if(!errorMessage||errorMessage?.length===0?(this.errorMessageWrapper.textContent="",this.errorMessageWrapper.setAttribute("hidden",!0)):this.errorMessageWrapper.removeAttribute("hidden"),errorMessage?.length>1){let errorsList="";errorMessage.forEach(error2=>{errorsList+=`<li>${error2}</li>`}),this.errorMessageWrapper.innerHTML=`
2        <strong>Please correct the following error(s):</strong>
3        <ul class="product-form__errors-list">
4          ${errorsList}
5        </ul>
6        `}else this.errorMessageWrapper.textContent=errorMessage[0]}});
7//# sourceMappingURL=/cdn/shop/t/94/assets/product-form.js.map?v=90434516846900511261727814895

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.