1customElements.get("cart-discount-component")||customElements.define("cart-discount-component",class extends HTMLElement{constructor(){super(),this.form=this.querySelector("form"),this.onSubmitHandler=this.applyDiscount.bind(this),this.form.addEventListener("submit",this.onSubmitHandler),this.submitButton=this.querySelector('[type="submit"]'),this.cart=document.querySelector("cart-drawer")||document.querySelector("cart-notification")||document.querySelector("cart-items"),this.codesTag=this.querySelector(".cart-discount__codes")}connectedCallback(){this.initRequireRefs()}disconnectedCallback(){this.form.removeEventListener("submit",this.onSubmitHandler)}initRequireRefs(){this.cartDiscountError=document.getElementById("cartDiscountError"),this.cartDiscountErrorDiscountCode=document.getElementById("cartDiscountErrorDiscountCode"),this.cartDiscountErrorShipping=document.getElementById("cartDiscountErrorShipping")}#activeFetch=null;#createAbortController(){this.#activeFetch&&this.#activeFetch.abort();const abortController=new AbortController;return this.#activeFetch=abortController,abortController}applyDiscount=async event=>{event.preventDefault(),event.stopPropagation();const form=event.target;if(!(form instanceof HTMLFormElement))return;const discountCode=form.querySelector('input[name="discount"]');if(!(discountCode instanceof HTMLInputElement)||typeof this.dataset.sectionId!="string")return;const discountCodeValue=discountCode.value,abortController=this.#createAbortController();try{const existingDiscounts=this.#existingDiscounts();if(existingDiscounts.includes(discountCodeValue))return;this.cartDiscountError.classList.add("hidden"),this.cartDiscountErrorDiscountCode.classList.add("hidden"),this.cartDiscountErrorShipping.classList.add("hidden");const config=fetchConfig("json");config.body=JSON.stringify({discount:[...existingDiscounts,discountCodeValue].join(","),sections:this.cart.getSectionsToRender().map(section2=>section2.id),sections_url:window.location.pathname}),this.submitButton.classList.add("loading"),this.submitButton.querySelector(".loading-overlay__spinner").classList.remove("hidden");const data=await(await fetch(routes.cart_update_url,{...config,signal:abortController.signal})).json();if(data.discount_codes.find(discount=>discount.code===discountCodeValue&&discount.applicable===!1)){discountCode.value="",this.#handleDiscountError("discount_code");return}const section=this.#parseSection(data),discountCodes=section?.querySelectorAll(".cart-discount__pill")||[];if(section){const codes=Array.from(discountCodes).map(element=>element instanceof HTMLLIElement?element.dataset.discountCode:null).filter(Boolean);if(codes.length===existingDiscounts.length&&codes.every(code=>existingDiscounts.includes(code))&&data.discount_codes.find(discount=>discount.code===discountCodeValue&&discount.applicable===!0)){this.#handleDiscountError("shipping"),discountCode.value="";return}}this.#completeApiCalling(data,section)}catch{}finally{this.#activeFetch=null,this.submitButton.classList.remove("loading"),this.submitButton.querySelector(".loading-overlay__spinner").classList.add("hidden")}};removeDiscount=async discountCode=>{const existingDiscounts=this.#existingDiscounts(),index=existingDiscounts.indexOf(discountCode);if(index===-1)return;existingDiscounts.splice(index,1);const abortController=this.#createAbortController();try{const config=fetchConfig("json");config.body=JSON.stringify({discount:existingDiscounts.join(","),sections:this.cart.getSectionsToRender().map(section2=>section2.id),sections_url:window.location.pathname});const data=await(await fetch(routes.cart_update_url,{...config,signal:abortController.signal})).json(),section=this.#parseSection(data);this.#completeApiCalling(data,section)}catch{this.querySelectorAll("cart-discount-remove").forEach(e=>e.disableLoading())}finally{this.#activeFetch=null}};#handleDiscountError(type){const target=type==="discount_code"?this.cartDiscountErrorDiscountCode:this.cartDiscountErrorShipping;this.cartDiscountError.classList.remove("hidden"),target.classList.remove("hidden")}#existingDiscounts(){const discountCodes=[],discountPills=this.querySelectorAll(".cart-discount__pill");for(const pill of discountPills)pill instanceof HTMLLIElement&&typeof pill.dataset.discountCode=="string"&&discountCodes.push(pill.dataset.discountCode);return discountCodes}#parseSection(data){const newHtml=data.sections[this.dataset.sectionId];return new DOMParser().parseFromString(newHtml,"text/html").getElementById(`shopify-section-${this.dataset.sectionId}`)}#completeApiCalling(data,section){this.cart.renderContents(data),section&&(this.codesTag.innerHTML=section.querySelector(".cart-discount__codes").innerHTML),document.dispatchEvent(new CustomEvent("afterDiscountUpdate",{detail:{data,id:this.id}}))}}),customElements.get("cart-discount-remove")||customElements.define("cart-discount-remove",class extends HTMLElement{constructor(){super(),this.button=this.querySelector("button"),this.onButtonClickHandler=this.onClickButton.bind(this),this.button.addEventListener("click",this.onButtonClickHandler)}disconnectedCallback(){this.button.removeEventListener("click",this.onButtonClickHandler)}onClickButton(event){if(event.preventDefault(),event.stopPropagation(),event instanceof KeyboardEvent&&event.key!=="Enter"||!(event instanceof MouseEvent)||!(event.currentTarget instanceof HTMLElement))return;const pill=event.currentTarget.closest(".cart-discount__pill");
1if(!(pill instanceof HTMLLIElement))return;const discountCode=pill.dataset.discountCode;discountCode&&(this.enableLoading(),this.closest("cart-discount-component").removeDiscount(discountCode))}enableLoading(){this.button.setAttribute("disabled","disabled"),this.button.classList.add("loading"),this.button.querySelector(".icon-close").classList.add("hidden"),this.button.querySelector(".cart-discount__pill-remove__loading").classList.remove("hidden")}disableLoading(){this.button.removeAttribute("disabled"),this.button.classList.remove("loading"),this.button.querySelector(".icon-close").classList.remove("hidden"),this.button.querySelector(".cart-discount__pill-remove__loading").classList.add("hidden")}}); 2//# sourceMappingURL=/cdn/shop/t/42/assets/cart-discount.js.map?v=60859117362967328681763648221
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.