PageSourceSearch

https://xavierderome.com/cdn/shop/t/66/assets/cart-discount.js?v=159203320276746735811788266116

js xavierderome.com collected 2026-09-27 03:48:13 UTC 4,448 bytes, 2 lines download raw bytes

1import{CartUpdatedEvent}from"@theme/events";class CartDiscount extends HTMLElement{constructor(){super(),this.applyButton=null,this.inputDiscount=null,this.removeDiscountButtons=null}connectedCallback(){this.applyButton=this.querySelector('[data-ref="apply-discount"]'),this.inputDiscount=this.querySelector('[data-ref="discount-input"]'),this.removeDiscountButtons=this.querySelectorAll('[data-ref="remove-discount"]'),this.applyButton.addEventListener("click",event=>this.submitDiscount(event)),this.removeDiscountButtons.forEach(button=>button.addEventListener("click",event=>this.removeDiscount(event)))}disconnectedCallback(){this.applyButton.removeEventListener("click",event=>this.submitDiscount(event)),this.removeDiscountButtons.forEach(button=>button.removeEventListener("click",event=>this.removeDiscount(event)))}submitDiscount(event){event.preventDefault(),event.stopPropagation(),this.setButtonLoading();const discountCode=this.inputDiscount.value;discountCode===""?this.setErrorMode(this.dataset.pleaseInsertACode):this.applyCode(discountCode)}removeDiscount=async event=>{event.preventDefault(),event.stopPropagation();const abortController=new AbortController,badge=event.target.closest('[data-ref="discount-badge"]');if(!(badge instanceof HTMLElement))return;const discountCode=badge.dataset.discountCode;if(!discountCode)return;const existingDiscounts=this.#existingDiscounts(),index=existingDiscounts.indexOf(discountCode);if(index===-1)return;existingDiscounts.splice(index,1);const sections=[];if(document.querySelector("cart-drawer")){const section_cart_drawer_id=document.querySelector("cart-drawer").dataset.sectionId;sections.push(section_cart_drawer_id)}try{const config={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:existingDiscounts.join(","),sections:sections.join(",")}),signal:abortController.signal},data=await(await fetch(Theme.routes.cart_update_url,config)).json();this.updateCart(data),this.setButtonLoaded()}catch(error){console.error(this.dataset.errorRemoveDiscount+": ",error),document.dispatchEvent(new CustomEvent("toast:open",{detail:{type:"error",message:this.dataset.errorRemoveDiscount}}))}};async applyCode(discountCode){const abortController=new AbortController;this.setButtonLoading();try{const existingDiscounts=this.#existingDiscounts();if(existingDiscounts.includes(discountCode)){this.setErrorMode(this.dataset.codeAlreadyApplied);return}const sections=[];if(document.querySelector("cart-drawer")){const section_cart_drawer_id=document.querySelector("cart-drawer").dataset.sectionId;sections.push(section_cart_drawer_id)}const config={method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body:JSON.stringify({discount:[...existingDiscounts,discountCode].join(","),sections:sections.join(",")}),signal:abortController.signal},data=await(await fetch(Theme.routes.cart_update_url,config)).json();if(data.discount_codes?.find(discount=>discount.code===discountCode&&discount.applicable===!1)){this.setErrorMode(this.dataset.codeNotApplicable);return}this.updateCart(data),this.setButtonLoaded()}catch(error){if(error.name==="AbortError")return;console.error(this.dataset.errorApplyDiscount+": ",error),this.setErrorMode(this.dataset.errorApplyDiscount)}}updateCart(data){window.location.pathname.includes("/cart")?window.location.reload():document.dispatchEvent(new CartUpdatedEvent({},{source:"cart-discount",sections:data.sections}))}#existingDiscounts(){const discountCodes=[],discountBadges=this.querySelectorAll('[data-ref="discount-badge"]');for(const badge of discountBadges)badge instanceof HTMLElement&&typeof badge.dataset.discountCode=="string"&&discountCodes.push(badge.dataset.discountCode);return discountCodes}setErrorMode(message){this.setButtonLoaded(),document.dispatchEvent(new CustomEvent("toast:open",{detail:{type:"error",message}})),this.inputDiscount.closest(".textfield").classList.add("textfield--error"),this.inputDiscount.value="",setTimeout(()=>{this.inputDiscount.closest(".textfield").classList.remove("textfield--error")},2e3)}setButtonLoading(){this.applyButton.disabled=!0,this.applyButton.classList.add("is-loading")}setButtonLoaded(){this.applyButton.disabled=!1,this.applyButton.classList.remove("is-loading")}}customElements.define("cart-discount",CartDiscount);
2//# sourceMappingURL=/cdn/shop/t/66/assets/cart-discount.js.map?v=159203320276746735811788266116

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.