1class SlideCart extends HTMLElement{constructor(){super(),this.modal=this.querySelector("#SlideCart"),this.debounceTimer=null,this.giftUpdating=!1,this.refreshPromise=null,this.bindEvents(),this.bindCartIcon(),this.subscribeToCartUpdates(),this.initScrollShadows()}initScrollShadows(){const wrapper=this.modal.querySelector(".slide-cart__body-wrapper"),body=this.modal.querySelector(".slide-cart__body");if(!wrapper||!body)return;const update=()=>{const{scrollTop,scrollHeight,clientHeight}=body;wrapper.classList.toggle("slide-cart__body-wrapper--shadow-top",scrollTop>0),wrapper.classList.toggle("slide-cart__body-wrapper--shadow-bottom",scrollTop+clientHeight<scrollHeight-1)};body.addEventListener("scroll",update,{passive:!0}),new MutationObserver(update).observe(body,{childList:!0,subtree:!0}),update()}bindEvents(){this.addEventListener("click",event=>{const target=event.target;if(target.closest("#SlideCart-Checkout")&&!this.isConsentGiven()){event.preventDefault(),this.showConsentError();return}const removeBtn=target.closest('[data-action="remove"]');if(removeBtn){event.preventDefault();const item=removeBtn.closest(".slide-cart__item"),line=parseInt(item.dataset.line,10);this.updateQuantity(line,0);return}const decreaseBtn=target.closest('[data-action="decrease"]');if(decreaseBtn){event.preventDefault();const input=decreaseBtn.closest(".slide-cart__item-quantity").querySelector(".slide-cart__item-quantity-input"),newVal=Math.max(0,parseInt(input.value,10)-1);input.value=newVal,this.debouncedUpdate(parseInt(input.dataset.line,10),newVal);return}const increaseBtn=target.closest('[data-action="increase"]');if(increaseBtn){event.preventDefault();const input=increaseBtn.closest(".slide-cart__item-quantity").querySelector(".slide-cart__item-quantity-input"),newVal=parseInt(input.value,10)+1;input.value=newVal,this.debouncedUpdate(parseInt(input.dataset.line,10),newVal);return}if(target.closest("#SlideCart-DiscountToggle")){event.preventDefault();const section=this.querySelector("#SlideCart-DiscountSection");if(section&&!section.classList.contains("is-expanded")){this.openDiscountForm();const input=section.querySelector(".slide-cart__discount-input");input&&input.focus()}return}if(target.closest("#SlideCart-DiscountClose")){event.preventDefault(),this.closeDiscountForm();return}if(target.closest("#SlideCart-DiscountBtn")){event.preventDefault(),this.applyDiscount();return}const removeDiscountBtn=target.closest('[data-action="remove-discount"]');if(removeDiscountBtn){event.preventDefault(),this.removeDiscount(removeDiscountBtn.dataset.discountCode);return}}),this.addEventListener("keydown",event=>{event.key==="Enter"&&event.target.closest("#SlideCart-DiscountInput")&&(event.preventDefault(),this.applyDiscount())}),this.addEventListener("change",event=>{const consentCheckbox=event.target.closest("#SlideCart-ConsentCheckbox");if(consentCheckbox){consentCheckbox.checked&&this.hideConsentError();return}const input=event.target.closest(".slide-cart__item-quantity-input");if(!input)return;const line=parseInt(input.dataset.line,10),quantity=parseInt(input.value,10);this.debouncedUpdate(line,Math.max(0,quantity))})}isConsentGiven(){if(!this.hasAttribute("data-consent-required"))return!0;const checkbox=this.querySelector("#SlideCart-ConsentCheckbox");return!checkbox||checkbox.checked}showConsentError(){const consent=this.querySelector("#SlideCart-Consent");consent&&consent.classList.add("slide-cart__consent--error");const checkbox=this.querySelector("#SlideCart-ConsentCheckbox");checkbox&&checkbox.focus()}hideConsentError(){const consent=this.querySelector("#SlideCart-Consent");consent&&consent.classList.remove("slide-cart__consent--error")}bindCartIcon(){const cartLink=document.querySelector("#cart-icon-bubble");cartLink&&(cartLink.setAttribute("role","button"),cartLink.setAttribute("aria-haspopup","dialog"),cartLink.addEventListener("click",event=>{event.preventDefault(),this.open()}),cartLink.addEventListener("keydown",event=>{event.code.toUpperCase()==="SPACE"&&(event.preventDefault(),this.open())}))}open(){this.refreshPromise&&(this.setGlobalLoading(!0),this.refreshPromise.finally(()=>this.setGlobalLoading(!1))),window.modalHandler&&window.modalHandler.showModal("SlideCart")}close(){window.modalHandler&&window.modalHandler.hideModal("SlideCart")}subscribeToCartUpdates(){typeof subscribe=="function"&&typeof PUB_SUB_EVENTS<"u"&&subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{if(event.source==="slide-cart"){this.showNotification(event.cartAction);return}event.cartData?.sections?(this.renderSections(event.cartData),this.scrollToTop(),this.showNotification(event.cartAction)):this.refreshCart().finally(()=>{this.showNotification(event.cartAction)}),event.source==="product-form"&&this.open()})}debouncedUpdate(line,quantity){clearTimeout(this.debounceTimer),this.debounceTimer=setTimeout(()=>{this.updateQuantity(line,quantity)},300)}updateQuantity(line,quantity){this.setItemsLoading(!0);const body=JSON.stringify({line,quantity,sections:["slide-cart","cart
1-icon-bubble"],sections_url:window.location.pathname});fetch(window.routes.cart_change_url+".js",{...fetchConfig(),body}).then(response=>response.json()).then(state=>{const errorMessage=state.errors||state.status===422&&state.description;if(errorMessage){this.showItemError(line,errorMessage),this.resetQuantityInput(line),this.setItemsLoading(!1);return}this.clearItemErrors(),this.renderSections(state,{refreshRebuy:quantity===0}),this.syncGift(state),typeof publish=="function"&&typeof PUB_SUB_EVENTS<"u"&&publish(PUB_SUB_EVENTS.cartUpdate,{source:"slide-cart",cartAction:quantity===0?"remove":"update",cartData:state})}).catch(error=>{console.error("SlideCart update error:",error)}).finally(()=>{this.setItemsLoading(!1)})}refreshCart(){return this.refreshPromise=fetch(window.routes.cart_update_url+".js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sections:["slide-cart","cart-icon-bubble"],sections_url:window.location.pathname})}).then(r=>r.json()).then(state=>{this.renderSections(state),this.syncGift(state),this.scrollToTop()}).catch(error=>{console.error("SlideCart refresh error:",error)}).finally(()=>{this.refreshPromise=null}),this.refreshPromise}scrollToTop(){const body=this.modal.querySelector(".slide-cart__body");body&&body.scrollTo({top:0,behavior:"smooth"})}renderHTML(html,{refreshRebuy=!0}={}){const parsed=new DOMParser().parseFromString(html,"text/html"),snippets=parsed.querySelectorAll("[data-cart-snippet]");if(snippets.length===0){const newModal=parsed.getElementById("SlideCart");newModal&&(this.modal.innerHTML=newModal.innerHTML);return}snippets.forEach(newSnippet=>{const key=newSnippet.getAttribute("data-cart-snippet"),current=this.modal.querySelector(`[data-cart-snippet="${key}"]`);current&¤t.replaceWith(newSnippet.cloneNode(!0))});const newCartData=parsed.getElementById("SlideCart-Rebuy-CartData");if(newCartData){const currentCartData=document.getElementById("SlideCart-Rebuy-CartData");currentCartData&&(currentCartData.textContent=newCartData.textContent)}refreshRebuy&&typeof window.refreshSlideCartRebuy=="function"&&window.refreshSlideCartRebuy()}renderSections(state,options){if(state.sections&&state.sections["slide-cart"]&&this.renderHTML(state.sections["slide-cart"],options),state.sections&&state.sections["cart-icon-bubble"]){const iconBubble=document.getElementById("cart-icon-bubble");if(iconBubble){const newIcon=new DOMParser().parseFromString(state.sections["cart-icon-bubble"],"text/html").querySelector(".shopify-section");newIcon&&(iconBubble.innerHTML=newIcon.innerHTML)}}}openDiscountForm(){const section=this.querySelector("#SlideCart-DiscountSection"),toggle=this.querySelector("#SlideCart-DiscountToggle");section&§ion.classList.add("is-expanded"),toggle&&toggle.setAttribute("aria-expanded","true")}closeDiscountForm(){const section=this.querySelector("#SlideCart-DiscountSection"),toggle=this.querySelector("#SlideCart-DiscountToggle");section&§ion.classList.remove("is-expanded"),toggle&&toggle.setAttribute("aria-expanded","false")}applyDiscount(){const input=this.querySelector("#SlideCart-DiscountInput"),code=input?input.value.trim():"";if(!code)return;const existingCodes=Array.from(this.querySelectorAll("[data-discount-code]")).map(btn=>btn.dataset.discountCode),allCodes=[code,...existingCodes].join(",");fetch(window.routes.cart_update_url+".js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({discount:allCodes,sections:["slide-cart","cart
1-icon-bubble"],sections_url:window.location.pathname})}).then(response=>{if(!response.ok)throw new Error(response.status);return response.json()}).then(cart=>{if(this.renderSections(cart),cart.discount_codes?.some(d=>!d.applicable)){this.openDiscountForm();const msg=this.querySelector("#SlideCart-DiscountMessage");msg&&(msg.textContent=msg.dataset.invalid,msg.classList.add("slide-cart__discount-message--error"))}}).catch(error=>{console.error("SlideCart discount error:",error)})}removeDiscount(code){const allCodes=Array.from(this.querySelectorAll("[data-discount-code]")).map(btn=>btn.dataset.discountCode).filter(c=>c!==code);fetch(window.routes.cart_update_url+".js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({discount:allCodes.join(","),sections:["slide-cart","cart-icon-bubble"],sections_url:window.location.pathname})}).then(response=>{if(!response.ok)throw new Error(response.status);return response.json()}).then(cart=>{this.renderSections(cart)}).catch(error=>{console.error("SlideCart remove discount error:",error)})}renderContents(parsedState){this.renderSections(parsedState),this.open()}getSectionsToRender(){return[{id:"slide-cart"},{id:"cart-icon-bubble"}]}setActiveElement(element){this.activeElement=element}showNotification(action){this.modal.querySelectorAll(".slide-cart__notification").forEach(n=>n.classList.remove("show"));const el=this.modal.querySelector(`#SlideCartNotification-${action}`);el&&(el.classList.add("show"),clearTimeout(this._notificationTimer),this._notificationTimer=setTimeout(()=>el.classList.remove("show"),5e3))}setItemsLoading(isLoading){const body=this.modal.querySelector('[data-cart-snippet="items"]');body&&(isLoading?body.classList.add("slide-cart__body--loading"):body.classList.remove("slide-cart__body--loading"))}setGlobalLoading(isLoading){const overlay=this.modal.querySelector("#SlideCart-Loading");overlay&&(isLoading?overlay.classList.add("show"):overlay.classList.remove("show"))}showItemError(line,message){const errorEl=this.querySelector(`#SlideCart-ItemError-${line}`);errorEl&&(errorEl.querySelector(".slide-cart__item-error-text").textContent=message,errorEl.classList.add("is-visible"))}clearItemErrors(){this.querySelectorAll(".slide-cart__item-error.is-visible").forEach(el=>{el.classList.remove("is-visible"),el.querySelector(".slide-cart__item-error-text").textContent=""})}resetQuantityInput(line){const input=this.querySelector(`.slide-cart__item-quantity-input[data-line="${line}"]`);input&&fetch(window.routes.cart_url+".js").then(r=>r.json()).then(cart=>{const item=cart.items[line-1];item&&(input.value=item.quantity)})}syncGift(cartData){console.log("Syncing gift with cart data:",cartData);const giftVariantId=this.dataset.giftVariantId,giftThreshold=parseInt(this.dataset.giftThreshold||"0",10);if(console.log("Gift sync config:",{giftVariantId,giftThreshold}),!giftVariantId||!giftThreshold||this.giftUpdating)return;const giftInCart=cartData.items.find(item=>String(item.variant_id)===giftVariantId&&item.properties&&item.properties._gift==="true");console.log("Gift sync:",{giftInCart,total:cartData.total_price,shouldHaveGift:cartData.total_price>=giftThreshold});const shouldHaveGift=cartData.total_price>=giftThreshold;if(shouldHaveGift&&!giftInCart)this.giftUpdating=!0,fetch(window.routes.cart_add_url+".js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({items:[{id:parseInt(giftVariantId,10),quantity:1,properties:{_gift:"true"}}
1],sections:["slide-cart","cart-icon-bubble"],sections_url:window.location.pathname})}).then(r=>r.json()).then(state=>{this.renderSections(state)}).catch(e=>console.error("SlideCart gift add error:",e)).finally(()=>{this.giftUpdating=!1});else if(!shouldHaveGift&&giftInCart){this.giftUpdating=!0;const line=cartData.items.indexOf(giftInCart)+1;fetch(window.routes.cart_change_url+".js",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({line,quantity:0,sections:["slide-cart","cart-icon-bubble"],sections_url:window.location.pathname})}).then(r=>r.json()).then(state=>{this.renderSections(state)}).catch(e=>console.error("SlideCart gift remove error:",e)).finally(()=>{this.giftUpdating=!1})}}}customElements.define("slide-cart",SlideCart); 2//# sourceMappingURL=/cdn/shop/t/100/assets/slide-cart.js.map?v=133888307022543884001781183084
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.