PageSourceSearch

https://www.personalwine.com/cdn/shop/t/65/assets/cart-discount.js?v=124152053630583417991788214101

js personalwine.com collected 2026-09-26 01:43:07 UTC 5,255 bytes, 2 lines download raw bytes

1if(!customElements.get("cart-discount")){class CartDiscount extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.input=this.querySelector('input[name="discount"]'),this.button=this.form?.querySelector('button[type="submit"]'),this.errorWrap=this.querySelector(".cart-discount__error"),this.errorDiscount=this.querySelector(".cart-discount__error--discount"),this.errorShipping=this.querySelector(".cart-discount__error--shipping"),this.onApply=this.applyDiscount.bind(this),this.onRemove=this.removeDiscount.bind(this)}connectedCallback(){this.form&&this.form.addEventListener("submit",this.onApply),this.addEventListener("click",this.onRemove)}disconnectedCallback(){this.form&&this.form.removeEventListener("submit",this.onApply),this.removeEventListener("click",this.onRemove)}getCurrentCodes(){return Array.from(document.querySelectorAll("[data-discount-code]")).map(el=>el.dataset.discountCode).filter(Boolean)}getSectionsToRender(){const mainSectionId=document.getElementById("main-cart-items")?.dataset.id,sections=[];return mainSectionId&&sections.push({id:"main-cart-items",section:mainSectionId,selector:".js-contents"},{id:"main-cart-total",section:mainSectionId,selector:".js-contents-total"},{id:"main-cart-shipping",section:mainSectionId,selector:".js-contents-shipping"},{id:"main-cart-discount",section:mainSectionId,selector:".js-contents-discount"}),sections.push({id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"},{id:"cart-live-region-text",section:"cart-live-region-text",selector:".shopify-section"}),sections.push({id:"cart-drawer",section:"cart-drawer",selector:null}),sections}async applyDiscount(e){e.preventDefault();const code=this.input?.value.trim();if(!code)return;this.toggleError(!1),this.setLoading(!0);const existing=this.getCurrentCodes();existing.includes(code)||existing.push(code),await this.updateDiscounts(existing),this.input&&(this.input.value="")}async removeDiscount(e){const pill=e.target.closest("[data-remove-discount]");if(!pill)return;e.preventDefault(),this.toggleError(!1),this.setLoading(!0);const codeToRemove=pill.dataset.removeDiscount,keep=this.getCurrentCodes().filter(c=>c!==codeToRemove);await this.updateDiscounts(keep)}async updateDiscounts(codes){try{const wasChecked=document.querySelector("#cart-upsell-checkbox")?.checked,sectionsMeta=this.getSectionsToRender(),sections=sectionsMeta.map(s=>s.section),body=JSON.stringify({discount:codes&&codes.length?codes.join(","):"",sections,sections_url:window.location.pathname}),res=await fetch(`${window.routes.cart_update_url}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body});if(!res.ok)throw new Error("Failed to update discounts");const data=await res.json(),lastCode=codes[codes.length-1];if(this.checkShippingDiscount(data,codes,lastCode)){this.toggleError(!0,"shipping");return}if(Array.isArray(data.discount_codes)&&data.discount_codes.length){const last=data.discount_codes[data.discount_codes.length-1];if(last&&last.applicable===!1){this.toggleError(!0,"discount_code");return}}const cartDrawer=document.querySelector("cart-drawer");cartDrawer&&cartDrawer.renderContents(data),sectionsMeta.forEach(({id,section,selector})=>{if(section==="cart-drawer")return;const container=document.getElementById(id),htmlStr=data.sections?.[section];if(!container||!htmlStr)return;const doc=new DOMParser().parseFromString(htmlStr,"text/html"),fragment=selector?doc.querySelector(selector):doc.body;if(!fragment)return;const target=selector&&container.querySelector(selector)||container;target.innerHTML=fragment.innerHTML}),setTimeout(()=>{const newCheckbox=document.querySelector("#cart-upsell-checkbox");if(newCheckbox){const variantId=newCheckbox.getAttribute("data-variant-id");if(data.items&&variantId){const hasUpsellInCart=data.items.some(item=>item.variant_id.toString()===variantId);newCheckbox.checked=hasUpsellInCart}}document.dispatchEvent(new CustomEvent("cartUpdated"))},100)}catch(err){console.error("[CartDiscount] updateDiscounts error:",err),this.toggleError(!0,"discount_code")}finally{this.setLoading(!1)}}
1checkShippingDiscount(data,codes,lastCode){const existing=this.getCurrentCodes(),htmlStr=data.sections?.["cart-drawer"];if(!htmlStr)return!1;const doc=new DOMParser().parseFromString(htmlStr,"text/html"),newCodes=Array.from(doc.querySelectorAll("[data-discount-code]")).map(el=>el.dataset.discountCode).filter(Boolean);return newCodes.length===existing.length&&newCodes.every(c=>existing.includes(c))&&data.discount_codes.find(d=>d.code===lastCode&&d.applicable===!0)}toggleError(show,type="discount_code"){if(this.errorWrap){if(!show){this.errorWrap.classList.add("hidden"),this.errorDiscount?.classList.add("hidden"),this.errorShipping?.classList.add("hidden");return}this.errorWrap.classList.remove("hidden"),type==="discount_code"&&this.errorDiscount?.classList.remove("hidden"),type==="shipping"&&this.errorShipping?.classList.remove("hidden")}}setLoading(isLoading){this.button&&(this.button.disabled=isLoading,this.button.classList.toggle("loading",isLoading))}}customElements.define("cart-discount",CartDiscount)}
2//# sourceMappingURL=/cdn/shop/t/65/assets/cart-discount.js.map?v=124152053630583417991788214101

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.