PageSourceSearch

https://badnbare.com/cdn/shop/t/113/assets/cart.js?v=42378732938931990071785245511

js badnbare.com collected 2026-10-09 22:40:52 UTC 15,301 bytes, 2 lines download raw bytes

1class CartRemoveButton extends HTMLElement{constructor(){super(),this.addEventListener("click",event=>{event.preventDefault(),(this.closest("cart-items")||this.closest("cart-drawer-items")).updateQuantity(this.dataset.index,0)})}}customElements.define("cart-remove-button",CartRemoveButton);class CartItems extends HTMLElement{constructor(){super(),this.lineItemStatusElement=document.getElementById("shopping-cart-line-item-status")||document.getElementById("CartDrawer-LineItemStatus"),document.querySelector(".cart-shipping")&&(this.minSpend=document.querySelector(".cart-shipping").dataset.minSpend,this.minTotal=Math.round(this.minSpend*(Shopify.currency.rate||1)),this.cartShipping());const debouncedOnChange=debounce(event=>{this.onChange(event)},ON_CHANGE_DEBOUNCE_TIMER);this.addEventListener("change",debouncedOnChange.bind(this))}cartUpdateUnsubscriber=void 0;cartShipping(){let progressPrev=getComputedStyle(document.querySelector(".cart-shipping__progress-current")).getPropertyValue("width");if(document.documentElement.style.setProperty("--progress-prev",progressPrev),this.total=document.querySelector(".cart-shipping").dataset.total,this.progress=this.total/this.minTotal*100,this.progress>100&&(this.progress=100),this.minTotal>this.total){let amount=this.minTotal-this.total,message=document.querySelector(".cart-shipping").dataset.message.replace("||amount||",formatMoney(amount));document.querySelector(".cart-shipping__message_default").innerHTML=message,document.querySelector(".cart-shipping__message_success").classList.remove("active"),document.querySelector(".cart-shipping__message_default").classList.add("active")}else document.querySelector(".cart-shipping__message_default").classList.remove("active"),document.querySelector(".cart-shipping__message_success").classList.add("active");document.querySelector(".cart-shipping__progress-current").style.width=this.progress+"%"}connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{event.source!=="cart-items"&&this.onCartUpdate()})}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}onChange(event){this.updateQuantity(event.target.dataset.index,event.target.value,document.activeElement.getAttribute("name"))}onCartUpdate(){fetch(`${routes.cart_url}?section_id=main-cart-items`).then(response=>response.text()).then(responseText=>{const sourceQty=new DOMParser().parseFromString(responseText,"text/html").querySelector("cart-items");this.innerHTML=sourceQty.innerHTML}).catch(e=>{console.error(e)})}getSectionsToRender(){return[{id:"main-cart-items",section:document.getElementById("main-cart-items").dataset.id,selector:".js-contents"},{id:"cart-icon-bubble",section:"cart-icon-bubble",selector:".shopify-section"},{id:"cart-live-region-text",section:"cart-live-region-text",selector:".shopify-section"},{id:"main-cart-footer",section:document.getElementById("main-cart-footer").dataset.id,selector:".js-contents-totals"},{id:"main-cart-shipping",section:document.getElementById("main-cart-shipping").dataset.id||null,selector:".js-contents-shipping"}]}updateQuantity(line,quantity,name){if(this.enableLoading(line),this.querySelectorAll(".quantity__button").forEach(button=>button.classList.add("disabled")),document.querySelectorAll('.card--product card__add-to-cart button[name="add"]')&&document.querySelectorAll('.card--product .card__add-to-cart button[name="add"]').forEach(button=>{button.setAttribute("aria-disabled",!1),button.querySelector("span")&&(button.querySelector("span").classList.remove("hidden"),button.querySelector(".sold-out-message").classList.add("hidden"))}),document.querySelector(".cart-shipping")){let progressPrev=getComputedStyle(document.querySelector(".cart-shipping__progress-current")).getPropertyValue("width");document.documentElement.style.setProperty("--progress-prev",progressPrev)}const body=JSON.stringify({line,quantity,sections:this.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname});fetch(`${routes.cart_change_url}`,{...fetchConfig(),body}).then(response=>response.text()).then(state=>{const parsedState=JSON.parse(state),quantityElement=document.getElementById(`Quantity-${line}`)||document.getElementById(`Drawer-quantity-${line}`),items=document.querySelectorAll(".cart-item");if(parsedState.errors){quantityElement.value=quantityElement.getAttribute("value"),this.updateLiveRegions(line,parsedState.errors),document.dispatchEvent(new CustomEvent("cart:error",{detail:{source:this.dataset.source,productVariantId:items[line-1].dataset.variantId||line,errors:parsedState.errors,message:parsedState.errors}}));return}document.dispatchEvent(new CustomEvent("line-item:change",{detail:{lineItem:parsedState.items[line-1]||null,cart:parsedState,sectionId:this.dataset.source}})),this.classList.toggle("is-empty",parsedState.item_count===0),document.dispatchEvent(new CustomEvent("cart:change",{detail:{cart:parsedState,sectionId:this.dataset.source}}));const cartDrawerWrapper=document.querySelector("cart-drawer"),cartFooter=document.getElementById("main-cart-footer");cartFooter&&cartFooter.classList.toggle("is-empty",parsedState.item_count===0),c
1artDrawerWrapper&&cartDrawerWrapper.classList.toggle("is-empty",parsedState.item_count===0),this.getSectionsToRender().forEach(section=>{const elementToReplace=document.getElementById(section.id).querySelector(section.selector)||document.getElementById(section.id);elementToReplace.innerHTML=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector)});const updatedValue=parsedState.items[line-1]?parsedState.items[line-1].quantity:void 0;let message="";items.length===parsedState.items.length&&updatedValue!==parseInt(quantityElement.value)&&(typeof updatedValue>"u"?message=window.cartStrings.error:message=window.cartStrings.quantityError.replace("[quantity]",updatedValue)),this.updateLiveRegions(line,message);const lineItem=document.getElementById(`CartItem-${line}`)||document.getElementById(`CartDrawer-Item-${line}`);lineItem&&lineItem.querySelector(`[name="${name}"]`)?cartDrawerWrapper?trapFocus(cartDrawerWrapper,lineItem.querySelector(`[name="${name}"]`)):lineItem.querySelector(`[name="${name}"]`).focus():parsedState.item_count===0&&cartDrawerWrapper?trapFocus(cartDrawerWrapper.querySelector(".drawer__inner-empty"),cartDrawerWrapper.querySelector("a")):document.querySelector(".cart-item")&&cartDrawerWrapper&&trapFocus(cartDrawerWrapper,document.querySelector(".cart-item__name")),publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-items"})}).catch(()=>{const items=document.querySelectorAll(".cart-item");this.querySelectorAll(".loading-overlay").forEach(overlay=>overlay.classList.add("hidden")),this.querySelectorAll(".quantity__button").forEach(button=>button.classList.remove("disabled"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors.textContent=window.cartStrings.error,document.dispatchEvent(new CustomEvent("cart:error",{detail:{source:this.dataset.source,productVariantId:items[line-1]?.dataset?.variantId||line,errors:window.cartStrings.error,message:window.cartStrings.error}}))}).finally(()=>{this.querySelectorAll(".quantity__button").forEach(button=>button.classList.remove("disabled")),document.querySelector(".cart-shipping")&&this.cartShipping(),this.disableLoading(line)})}updateLiveRegions(line,message){const lineItemError=document.getElementById(`Line-item-error-${line}`)||document.getElementById(`CartDrawer-LineItemError-${line}`);lineItemError&&(lineItemError.querySelector(".cart-item__error-text").innerHTML=message),this.lineItemStatusElement.setAttribute("aria-hidden",!0);const cartStatus=document.getElementById("cart-live-region-text")||document.getElementById("CartDrawer-LiveRegionText");cartStatus.setAttribute("aria-hidden",!1),setTimeout(()=>{cartStatus.setAttribute("aria-hidden",!0)},1e3)}getSectionInnerHTML(html,selector){return new DOMParser().parseFromString(html,"text/html").querySelector(selector).innerHTML}enableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.add("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading-overlay`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading-overlay`);
1[...cartItemElements,...cartDrawerItemElements].forEach(overlay=>overlay.classList.remove("hidden")),document.activeElement.blur(),this.lineItemStatusElement.setAttribute("aria-hidden",!1)}disableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.remove("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading-overlay`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading-overlay`);cartItemElements.forEach(overlay=>overlay.classList.add("hidden")),cartDrawerItemElements.forEach(overlay=>overlay.classList.add("hidden"))}}customElements.define("cart-items",CartItems),customElements.get("cart-note")||customElements.define("cart-note",class extends HTMLElement{constructor(){super(),this.addEventListener("input",debounce(event=>{const body=JSON.stringify({note:event.target.value});fetch(`${routes.cart_update_url}`,{...fetchConfig(),body})},ON_CHANGE_DEBOUNCE_TIMER))}});class CartDiscountCode extends HTMLElement{constructor(){super(),this.activeFetch=null}connectedCallback(){this.#initRefs(),this.form=this.querySelector("form"),this.input=this.querySelector('input[name="discount"]'),this.submitBtn=this.querySelector('button[type="submit"]'),this.form?.addEventListener("submit",this.applyDiscount),this.addEventListener("click",this.removeDiscount)}disconnectedCallback(){this.form?.removeEventListener("submit",this.applyDiscount),this.removeEventListener("click",this.removeDiscount),this.activeFetch&&(this.activeFetch.abort(),this.activeFetch=null)}#initRefs(){this.refs={};for(const el of this.querySelectorAll("[ref]")){const name=el.getAttribute("ref");name&&el instanceof HTMLElement&&(this.refs[name]=el)}}#createAbortController(){this.activeFetch&&this.activeFetch.abort();const abortController=new AbortController;return this.activeFetch=abortController,abortController}applyDiscount=async event=>{const{cartDiscountError,cartDiscountErrorDiscountCode,cartDiscountErrorShipping}=this.refs;if(event.preventDefault(),event.stopPropagation(),!(event.target instanceof HTMLFormElement)||!(this.input instanceof HTMLInputElement)||typeof this.dataset.sectionId!="string")return;const discountCodeValue=this.input.value.trim();if(!discountCodeValue)return;const abortController=this.#createAbortController();this.submitBtn&&this.submitBtn.classList.add("loading");const btnLoader=this.submitBtn.querySelector(".button-loader");btnLoader&&btnLoader.classList.remove("hidden");try{const existingDiscounts=this.#existingDiscounts();if(existingDiscounts.includes(discountCodeValue))return;cartDiscountError.classList.add("hidden"),cartDiscountErrorDiscountCode.classList.add("hidden"),cartDiscountErrorShipping.classList.add("hidden");const body=JSON.stringify({discount:[...existingDiscounts,discountCodeValue].join(","),sections:[this.dataset.sectionId]}),data=await(await fetch(routes.cart_update_url,{...fetchConfig(),body,signal:abortController.signal})).json();if(!this.#checkApplicableCode(data.discount_codes,discountCodeValue))return;const sourceSection=this.#getNewSectionHtml(data.sections);if(sourceSection){if(!this.#checkShippingDiscountCode(data.discount_codes,discountCodeValue,sourceSection))return;this.#updateSectionHtml(sourceSection)}}catch(error){console.error("Failed to apply discount:",error)}finally{this.activeFetch=null,this.submitBtn&&this.submitBtn.classList.remove("loading"),btnLoader&&btnLoader.classList.add("hidden")}};removeDiscount=async event=>{if(!(event.target instanceof HTMLElement||event.target instanceof SVGElement)||typeof this.dataset.sectionId!="string")return;const pill=event.target.closest(".cart-discount-code__pill");
1if(!(pill instanceof HTMLLIElement))return;event.preventDefault(),event.stopPropagation();const discountCode=pill.dataset.discountCode;if(!discountCode)return;const existingDiscounts=this.#existingDiscounts(),index=existingDiscounts.indexOf(discountCode);if(index===-1)return;existingDiscounts.splice(index,1);const abortController=this.#createAbortController();this.submitBtn&&this.submitBtn.classList.add("loading");const btnLoader=this.submitBtn.querySelector(".button-loader");btnLoader&&btnLoader.classList.remove("hidden");try{const body=JSON.stringify({discount:existingDiscounts.join(","),sections:[this.dataset.sectionId]}),data=await(await fetch(routes.cart_update_url,{...fetchConfig(),body,signal:abortController.signal})).json(),sourceSection=this.#getNewSectionHtml(data.sections);this.#updateSectionHtml(sourceSection)}catch(error){console.error("Failed to remove discount:",error)}finally{this.activeFetch=null,this.submitBtn&&this.submitBtn.classList.remove("loading"),btnLoader&&btnLoader.classList.add("hidden")}};#handleDiscountError(type){const{cartDiscountError,cartDiscountErrorDiscountCode,cartDiscountErrorShipping}=this.refs,target=type==="discount_code"?cartDiscountErrorDiscountCode:cartDiscountErrorShipping;cartDiscountError.classList.remove("hidden"),target.classList.remove("hidden")}#existingDiscounts(){const discountCodes=[],discountPills=this.querySelectorAll(".cart-discount-code__pill");for(const pill of discountPills)pill instanceof HTMLLIElement&&typeof pill.dataset.discountCode=="string"&&discountCodes.push(pill.dataset.discountCode);return discountCodes}#checkApplicableCode(cartDiscountCodes,discountCodeValue){return cartDiscountCodes.find(discount=>discount.code===discountCodeValue&&discount.applicable===!1)?(this.input.value="",this.#handleDiscountError("discount_code"),!1):!0}#checkShippingDiscountCode(cartDiscountCodes,discountCodeValue,sourceSection){const discountCodes=sourceSection?.querySelectorAll(".cart-discount-code__pill")||[],existingDiscounts=this.#existingDiscounts(),codes=Array.from(discountCodes).map(element=>element instanceof HTMLLIElement?element.dataset.discountCode:null).filter(Boolean);return codes.length===existingDiscounts.length&&codes.every(code=>existingDiscounts.includes(code))&&cartDiscountCodes.find(discount=>discount.code===discountCodeValue&&discount.applicable===!0)?(this.#handleDiscountError("shipping"),this.input.value="",!1):!0}#getNewSectionHtml(cartSections){const newHtml=cartSections[this.dataset.sectionId],parsedHtml=new DOMParser().parseFromString(newHtml,"text/html"),sectionId=this.dataset.sectionId==="cart-drawer"?"CartDrawer":`shopify-section-${this.dataset.sectionId}`;return parsedHtml.getElementById(sectionId)}#updateSectionHtml(sourceSection){const sectionId=`shopify-section-${this.dataset.sectionId}`,targetSection=this.dataset.sectionId==="cart-drawer"?document.getElementById("CartDrawer"):document.getElementById(sectionId);sourceSection&&targetSection&&(targetSection.innerHTML=sourceSection.innerHTML)}}customElements.get("cart-discount-code")||customElements.define("cart-discount-code",CartDiscountCode);
2//# sourceMappingURL=/cdn/shop/t/113/assets/cart.js.map?v=42378732938931990071785245511

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.