PageSourceSearch

https://jessejamesbeads.com/cdn/shop/t/81/assets/cart-discounts.js?v=62247830773882427441786120402

js jessejamesbeads.com collected 2026-09-25 20:14:49 UTC 3,464 bytes, 2 lines download raw bytes

1if(!customElements.get("cart-discounts")){class CartDiscounts extends HTMLElement{constructor(){super()}connectedCallback(){this.discounts()}getSectionsToRender(){return[{id:"Cart",section:"main-cart",selector:".thb-cart-form"},{id:"Cart-Drawer",section:"cart-drawer",selector:".cart-drawer"},{id:"cart-drawer-toggle",section:"cart-bubble",selector:".thb-item-count"}]}getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}discounts(){const button=this.querySelector(".cart-discounts--button"),remove_discount_buttons=this.querySelectorAll(".cart-discounts--remove");button&&(button.addEventListener("click",event=>{this.updateDiscount(),event.preventDefault(),button.classList.add("loading")}),remove_discount_buttons.forEach(remove_discount_button=>{remove_discount_button.addEventListener("click",this.removeDiscount.bind(this))}))}updateDiscount(){const discountCodeValue=this.querySelector(".cart-discounts--input").value,existingDiscounts=this.existingDiscounts();existingDiscounts.includes(discountCodeValue)||(existingDiscounts.push(discountCodeValue),this.renderDiscounts(existingDiscounts,discountCodeValue))}removeDiscount(event){const discountCode=event.target.previousElementSibling.innerHTML,existingDiscounts=this.existingDiscounts(),index=existingDiscounts.indexOf(discountCode);index!==-1&&(existingDiscounts.splice(index,1),this.renderDiscounts(existingDiscounts))}existingDiscounts(){const discountCodes=[],discountPills=this.querySelectorAll(".cart-discounts--name");for(const pill of discountPills)discountCodes.push(pill.innerHTML);return discountCodes}renderDiscounts(existingDiscounts,discountCodeValue){const body=JSON.stringify({discount:existingDiscounts.join(","),sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname});this.querySelector(".cart-discounts--error").setAttribute("hidden","");let resolveCartUpdate;publishStandardEvent("CartDiscountUpdateEvent",{discountCodes:existingDiscounts,promise:new Promise(resolve=>{resolveCartUpdate=resolve})}),fetch(`${theme.routes.cart_update_url}.js`,{method:"POST",headers:{"Content-Type":"application/json",Accept:"application/json"},body}).then(response=>response.text()).then(state=>{const parsedState=JSON.parse(state);resolveCartUpdate&&resolveCartUpdate({cart:standardEventCartFromAjax(parsedState)});const wasDiscountOpen=!!this.closest("details[open]");this.getSectionsToRender().forEach((section=>{const elementToReplace=document.getElementById(section.id)?.querySelector(section.selector)||document.getElementById(section.id);parsedState.sections&&elementToReplace&&(elementToReplace.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector))})),wasDiscountOpen&&document.querySelectorAll(".cart-discounts--title").forEach(el=>{el.closest("details").setAttribute("open","")}),discountCodeValue&&parsedState.discount_codes.find(discount=>discount.code===discountCodeValue&&discount.applicable===!1)&&(setTimeout(()=>{document.querySelectorAll(".cart-discounts--error").forEach(el=>{el.removeAttribute("hidden")})},300),publishStandardEvent("CartErrorEvent",{source:"cart-discount-update",error:{message:this.querySelector(".cart-discounts--error").textContent.trim()}}))})}}customElements.define("cart-discounts",CartDiscounts)}
2//# sourceMappingURL=/cdn/shop/t/81/assets/cart-discounts.js.map?v=62247830773882427441786120402

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.