PageSourceSearch

https://www.paperplane.shop/cdn/shop/t/1106/assets/custom-embroidery.js?v=52430602325528203431790351838

js paperplane.shop collected 2026-09-27 21:33:23 UTC 12,263 bytes, 2 lines download raw bytes

1if(!customElements.get("custom-embroidery")){class CustomEmbroidery extends HTMLElement{constructor(){super(),this.textInputs=this.querySelectorAll(".custom-embroidery__text"),this.body=this.querySelector(".custom-embroidery__body"),this.tabButtons=this.querySelectorAll(".custom-embroidery__preview-nav a"),this.tabContents=this.querySelectorAll(".custom-embroidery__preview-tab"),this.ctaTriggers=this.querySelectorAll(".custom-embroidery__triggers a"),this.ctaOpen=this.querySelector("[data-js-embroidery-show]"),this.ctaClose=this.querySelector("[data-js-embroidery-hide]"),this.addButtons=this.querySelectorAll("[data-add-btn]"),this.editButtons=this.querySelectorAll("[data-edit-btn]"),this.addAnotherPlacementBtn=this.querySelector("[data-add-another-placement-btn]"),this.addedMessages=this.querySelectorAll(".custom-embroidery__added-message"),this.ctaOpen.addEventListener("click",this.showEmbroidery.bind(this)),this.ctaClose.addEventListener("click",this.hideEmbroidery.bind(this)),this.querySelectorAll("[data-js-embroidery-color]").forEach(element=>{element.addEventListener("change",event=>{const targetInput=event.target,currentTab=targetInput.closest(".custom-embroidery__preview-tab"),color=targetInput.value;this.updateProperty("embroidery_color",color,currentTab),this.changePreviewColor(event)})}),this.querySelectorAll("[data-js-embroidery-style]").forEach(element=>{element.addEventListener("change",event=>{const targetInput=event.target,currentTab=targetInput.closest(".custom-embroidery__preview-tab"),style=targetInput.value;this.updateProperty("embroidery_style",style,currentTab),this.changePreviewStyle(event)})});let firstBtn=document.querySelector(".custom-embroidery__cta");const addBtn=document.querySelector("[data-add-btn][disabled]");let secondBtn=document.querySelector(".custom-embroidery__cta.another-btn");function checkProductAdded(){firstBtn.textContent.trim()==="ADDED!"&&(firstBtn.style.display="none",addBtn.style.display="none",secondBtn.style.display="inline-block")}function refreshPage(){location.reload(),ignoreCheck=!0}secondBtn.addEventListener("click",refreshPage),this.textInputs.forEach(textInput=>{const input=textInput.querySelector("input"),inputValue=input.value;this.updateRemainingLimit(input,inputValue),input.addEventListener("input",event=>{const currentTab=input.closest(".custom-embroidery__preview-tab");this.updatePreviewText(event),this.updateProperty("embroidery_message",input.value,currentTab),this.updateAddBtnState(input,currentTab)})}),this.restrictedWords=window.restrictions||[],this.tabButtons.forEach(btn=>{btn.addEventListener("click",event=>{this.showTab(event)})}),this.addButtons.forEach(btn=>{btn.addEventListener("click",event=>{const currentTab=event.target.closest(".custom-embroidery__preview-tab");this.addEmbroideryToCart(currentTab,event.target.dataset.mainProductId),setTimeout(checkProductAdded,2e3),event.preventDefault()})}),this.editButtons.forEach(btn=>{btn.addEventListener("click",event=>{const currentTab=event.target.closest(".custom-embroidery__preview-tab"),embroideryInfo=currentTab.querySelector("[data-embroidery-content]"),propertyFields=embroideryInfo.querySelectorAll(".property");let item={},properties={};for(const propertyField of propertyFields){const propName=propertyField.dataset.propertyName,propValue=propertyField.value;properties[propName]=propValue}item.id=currentTab.dataset.cartKey,item.quantity=parseInt(embroideryInfo.querySelector("[data-cart-quantity]").value,10)||1,item.properties=properties,btn.setAttribute("disabled",!0),this.updateItemCart(item,currentTab),event.preventDefault()})}),this.addAnotherPlacementBtn.addEventListener("click",event=>{event.preventDefault();const unAddedPlacementTab=this.querySelector(".custom-embroidery__preview-tab:not(.added):not(.active)");if(!unAddedPlacementTab)return;const targetNavTrigger=this.querySelector(`.custom-embroidery__preview-nav [data-tab="${unAddedPlacementTab.dataset.navTrigger}"]`);targetNavTrigger&&targetNavTrigger.click()}),this.addedMessages.forEach(addedMessage=>{const targetNavTrigger=this.querySelector(`.custom-embroidery__preview-nav [data-tab="${addedMessage.dataset.navTrigger}"]`),targetTab=this.querySelector(`.custom-embroidery__preview-tab[data-${addedMessage.dataset.navTrigger}]`),viewBtn=addedMessage.querySelector("[data-tab-view]"),editBtn=addedMessage.querySelector("[data-tab-edit]");viewBtn.addEventListener("click",event=>{targetNavTrigger.click(),event.preventDefault()}),editBtn.addEventListener("click",event=>{targetNavTrigger.click(),targetTab.classList.add("edit"),event.preventDefault()})}
1),document.addEventListener("CartUpdated",this.checkCartItemsForEmbroideryProduct.bind(this)),this.checkCartItemsForEmbroideryProduct()}showTab(event){event.preventDefault();const targetTab=document.querySelector(`[data-${event.target.dataset.tab}]`);this.tabContents.forEach(content=>{content.classList.remove("active","edit")}),this.tabButtons.forEach(btn=>{btn.classList.remove("active")}),targetTab.classList.add("active"),event.target.classList.add("active"),this.toggleAnotherPlacementBtn(),this.toggleAddedMessages()}showEmbroidery(event){event.preventDefault();const sizeInputs=document.querySelector(".product-form__input-inner--size");if(sizeInputs){const sizeName=sizeInputs.querySelector("input")?.getAttribute("name");sizeName&&(document.querySelector(`input[name="${sizeName}"]:checked`)||sizeInputs?.querySelector("label")?.click())}this.ctaTriggers.forEach(button=>button.classList.remove("active")),event.target.classList.add("active"),this.body.classList.add("active")}hideEmbroidery(event){event.preventDefault(),this.ctaTriggers.forEach(button=>button.classList.remove("active")),event.target.classList.add("active"),this.body.classList.remove("active")}updatePreviewText(event){const inputElement=event.target;let text=inputElement.value.trim();text=text.replace(/[^a-zA-Z0-9]/g,"");const words=text.split(/\s+/),previewContainer=document.querySelector(`[data-${inputElement.dataset.target}]`),sanitizedText=words.filter(word=>!this.restrictedWords.some(restricted=>word.toLowerCase().includes(restricted))).join(" ");inputElement.value=text,previewContainer.textContent=sanitizedText,this.updateRemainingLimit(inputElement,sanitizedText)}updateRemainingLimit(input,text){const limit=input.closest(".custom-embroidery__text").querySelector("[data-limit]").dataset.limit,remaining=input.closest(".custom-embroidery__text").querySelector("[data-remaining]"),remainingChar=limit-text.length;remaining.textContent=remainingChar}changePreviewColor(event){const color=event.target.dataset.color,svgTarget=event.target.dataset.target,previewImage=document.querySelector(`[${svgTarget}]`);previewImage&&(previewImage.style.fill=color)}changePreviewStyle(event){const fontClass=event.target.dataset.font,target=event.target.dataset.target;document.querySelector(`[${target}]`).setAttribute("class",fontClass)}updateAddBtnState(input,currentTab){const addBtn=currentTab.querySelector("[data-add-btn]");if(input.value.length>0){addBtn.removeAttribute("disabled");return}addBtn.setAttribute("disabled",!0)}updateProperty(propertyName,value,currentTab){const propertyTag=currentTab.querySelector(`[data-
1property-name="${propertyName}"]`);propertyTag.value=value}async addEmbroideryToCart(currentTab,mainProductId){const embroideryInfo=currentTab.querySelector("[data-embroidery-content]"),propertyFields=embroideryInfo.querySelectorAll(".property"),addBtn=currentTab.querySelector("[data-add-btn]"),products=[];let product={},properties={},randomNumber=Math.floor(Math.random()*1e9+1);properties.grpid="grp_"+randomNumber,addBtn.setAttribute("disabled",!0);const mainProductInfo=this.getMainProductInfo();product.id=embroideryInfo.querySelector('input[name="id"]').value,product.quantity=parseInt(embroideryInfo.querySelector("[data-cart-quantity]").value,10)||1;for(const propertyField of propertyFields){const propName=propertyField.dataset.propertyName,propValue=propertyField.value;properties[propName]=propValue}const matchingBarcode=embroideryInfo.querySelector('.embroidery-variant-barcode-match[data-variant-id="'+mainProductInfo.id+'"]');matchingBarcode&&(properties.embroidery_barcode=matchingBarcode.dataset.barcode),product.properties=properties,products.push(product),product.properties.embroidery_message&&(mainProductInfo.properties||(mainProductInfo.properties={}),mainProductInfo.properties.Embroidery=product.properties.embroidery_message),mainProductInfo.properties.grpid="grp_"+randomNumber,products.push(mainProductInfo),this.addItemsToCart(products,currentTab)}async getCartInfo(){return await(await fetch("/cart.json")).json()}getMainProductInfo(){const productForm=document.querySelector(".product-form"),variantId=productForm.querySelector(".product-variant-id").value,quantity=parseInt(productForm.querySelector("[data-cart-quantity]").value,10)||1;return{id:variantId,quantity}}addItemsToCart(items,currentTab){const addBtn=currentTab.querySelector("[data-add-btn]");let formData={items};console.log(formData),fetch("/cart/add.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(formData)}).then(response=>(window.theme.updateCart(),addBtn.removeAttribute("disabled"),currentTab?.classList.remove("edit"),this.toggleAnotherPlacementBtn(),this.checkCartItemsForEmbroideryProduct(),response.json())).catch(error=>{console.error("Error:",error)})}toggleAnotherPlacementBtn(){const unAddedPlacementTab=this.querySelector(".custom-embroidery__preview-tab:not(.added):not(.active):not(.edit)"),currentTab=this.querySelector(".custom-embroidery__preview-tab.active");if(unAddedPlacementTab&&currentTab.classList.contains("added")&&!currentTab.classList.contains("edit")){this.addAnotherPlacementBtn.classList.remove("hidden");return}this.addAnotherPlacementBtn.classList.add("hidden")}toggleAddedMessages(){this.addedMessages.forEach(addedMessage=>{const targetTab=this.querySelector(`.custom-embroidery__preview-tab[data-${addedMessage.dataset.navTrigger}]`);if(targetTab.classList.contains("added")&&!targetTab.classList.contains("active")){addedMessage.classList.remove("hidden");return}addedMessage.classList.add("hidden")})}async checkCartItemsForEmbroideryProduct(){const cartInfo=await this.getCartInfo();this.tabContents.forEach(tabContent=>{const embroideryEntry=tabContent.querySelector(".embroidery-entry"),variantId=embroideryEntry.querySelector('input[name="id"]').value,placement=embroideryEntry.querySelector('input[data-property-name="embroidery_placement"]').value;let cardEmbroideryProduct=cartInfo.items.filter(item=>item.variant_id==variantId&&item.properties.embroidery_placement==placement);if(cardEmbroideryProduct.length>0){this.updateEmbroideryStates(tabContent,cardEmbroideryProduct[0]);return}this.updateEmbroideryStates(tabContent,null)}),this.toggleAnotherPlacementBtn(),this.toggleAddedMessages()}updateEmbroideryStates(targetTab,cartProduct){const textField=targetTab.querySelector(".custom-embroidery__text input"),textValue=cartProduct?cartProduct.properties.embroidery_message:"",colorInput=cartProduct?`[value="${cartProduct.properties.embroidery_color}"]`:"",styleInput=cartProduct?`[value="${cartProduct.properties.embroidery_style}"]`:"",colorField=targetTab.querySelector(`.custom-embroidery__color input${colorInput}`),styleField=targetTab.querySelector(`.custom-embroidery__style input${styleInput}`);textField.value=textValue,textField.dispatchEvent(new Event("input",{bubbles:!0})),colorField.click(),styleField.click(),cartProduct?targetTab.setAttribute("data-cart-key",cartProduct.key):(targetTab.classList.remove("added","edit"),targetTab.removeAttribute("data-cart-key"))}updateItemCart(item,currentTab){const editBtn=currentTab.querySelector("[data-edit-btn]");fetch("/cart/change.js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(item)}).then(response=>(window.theme.updateCart(),editBtn.removeAttribute("disabled"),currentTab.classList.remove("edit"),this.toggleAnotherPlacementBtn(),response.json())).catch(error=>{console.error("Error:",error)})}}customElements.define("custom-embroidery",CustomEmbroidery)}
2//# sourceMappingURL=/cdn/shop/t/1106/assets/custom-embroidery.js.map?v=52430602325528203431790351838

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.