PageSourceSearch

https://fantech.id/cdn/shop/t/10/assets/cart.js?v=159899153119223957401767075967

js fantech.id collected 2026-10-05 10:36:25 UTC 18,126 bytes, 2 lines download raw bytes

1const CartPerformance={createStartingMarker:name=>({name,start:performance.now()}),measure:(name,callback)=>{callback&&callback()},measureFromMarker:(name,marker)=>{if(marker&&marker.start){const duration=performance.now()-marker.start;console.debug(`[Cart Performance] ${name}: ${duration.toFixed(2)}ms`)}},measureFromEvent:(name,event)=>{console.debug(`[Cart Performance] ${name}`)}};class 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,event)})}}customElements.define("cart-remove-button",CartRemoveButton);class CartDrawerClearAllButton extends HTMLElement{constructor(){super(),console.log("CartDrawerClearAllButton initialized - VERSION 2024-12-11-13:00"),this.actions={confirm:"confirm",remove:"remove",cancel:"cancel"},this.addEventListener("click",event=>{const button=event.target.closest("button");if(!button)return;event.preventDefault();const actionWrapper=button.closest("[data-action]");if(!actionWrapper){console.log("CartDrawer: No data-action wrapper found");return}const action=actionWrapper.dataset.action;console.log("CartDrawer clear all clicked, action:",action),action===this.actions.confirm?this.toggleConfirmation(!1,!0):action===this.actions.remove?this.clearAllItems():action===this.actions.cancel&&this.toggleConfirmation(!0,!1)})}toggleConfirmation(showButton,showConfirmation){const button=this.querySelector(".cart__clear-all-button"),confirmation=this.querySelector(".cart__clear-all-confirmation");console.log("CartDrawer toggle - showButton:",showButton,"showConfirmation:",showConfirmation),button&&button.classList.toggle("hidden",!showButton),confirmation&&confirmation.classList.toggle("hidden",!showConfirmation)}clearAllItems(){const cartDrawer=this.closest("cart-drawer"),cartDrawerItems=cartDrawer?cartDrawer.querySelector("cart-drawer-items"):null;if(!cartDrawerItems){console.error("cart-drawer-items not found");return}const cartItemsData=cartDrawerItems.dataset.cartItems,itemCount=parseInt(cartDrawerItems.dataset.itemCount||"0");if(!cartItemsData){console.error("Cart items data not found");return}let variantIds;try{variantIds=JSON.parse(cartItemsData)}catch(e){console.error("Failed to parse cart items data:",e);return}const updates={};variantIds.forEach(variantId=>{updates[variantId]=0});const checkoutButton=document.getElementById("CartDrawer-Checkout"),allClearButtons=this.querySelectorAll("button");allClearButtons.forEach(btn=>btn.disabled=!0),checkoutButton&&(checkoutButton.disabled=!0);const cartItemsContainer=document.getElementById("CartDrawer-CartItems");cartItemsContainer&&cartItemsContainer.classList.add("cart__items--disabled");const errorContainer=document.getElementById("CartDrawer-CartErrors");errorContainer&&(errorContainer.textContent="");const sectionsToRender=cartDrawerItems.getSectionsToRender().map(section=>section.section);sectionsToRender.includes("cart-icon-bubble")||sectionsToRender.push("cart-icon-bubble");const body=JSON.stringify({updates,sections:sectionsToRender,sections_url:window.location.pathname});fetch(`${routes.cart_update_url}`,{...fetchConfig(),body}).then(response=>response.text()).then(state=>{console.log("Cart cleared, response:",state);const parsedState=JSON.parse(state);if(parsedState.sections&&parsedState.sections["cart-icon-bubble"]){const doc=new DOMParser().parseFromString(parsedState.sections["cart-icon-bubble"],"text/html"),newCartIcon=doc.querySelector("#cart-icon-bubble"),currentCartIcon=document.getElementById("cart-icon-bubble");if(newCartIcon&&currentCartIcon)currentCartIcon.innerHTML=newCartIcon.innerHTML,console.log("Cart icon bubble updated (direct element)");else{const cartIconBubbleSection=document.getElementById("shopify-section-cart-icon-bubble"),newContent=doc.querySelector(".shopify-section");cartIconBubbleSection&&newContent&&(cartIconBubbleSection.innerHTML=newContent.innerHTML,console.log("Cart icon bubble updated (section wrapper)"))}}return console.log("Fetching cart-drawer section for refresh..."),fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{console.log("Got cart-drawer HTML, parsing...");const html=new DOMParser().parseFromString(responseText,"text/html"),currentDrawerInner=document.querySelector("cart-drawer .drawer__inner"),newDrawerInner=html.querySelector(".drawer__inner");console.log("Replacing drawer__inner:",{currentDrawerInner,newDrawerInner}),currentDrawerInner&&newDrawerInner&&(currentDrawerInner.innerHTML=newDrawerInner.innerHTML);const cartDrawerWrapper=document.querySelector("cart-drawer");cartDrawerWrapper&&cartDrawerWrapper.classList.add("is-empty");const liveRegion=document.getElementById("CartDrawer-LiveRegionText");if(liveRegion){const message=itemCount===1?window.cartStrings.cartCleared?.one||`Cart cleared. ${itemCount} item removed`:window.cartStrings.cartCleared?.other||`Cart cleared. ${itemCount} items removed`;liveRegion.textContent=message.replace("{{ quantity }}",itemCount)}setTimeout(()=>{const continueShoppingLink=document.querySelector(".cart-drawer__empty-content .button");continueShoppingLink&&continueShoppingLink.focus()},100),publish(PUB_SUB_EVENTS.cartUpdate,{source:"cart-drawer-clear-all",cartData:parsedState})})}).catch(error=>{console.error("Error clearing cart:",error),errorContainer&&(errorContainer.textContent=window.cartStrings.error||"There was an error clearing your cart."),allClearButtons.forEach(btn=>btn.disabled=!1),checkoutButton&&(checkoutButton.disabled=!1),this.toggleConfirmation(!0,!1)}).finally(()=>{cartItemsContainer&&cartItemsContainer.classList.remove("cart__items--disabled")})}}customElements.define("cart-drawer-clear-all-button",CartDrawerClearAllButton);class CartClearAllButton extends HTMLElement{constructor(){super(),this.actions={confirm:"confirm",remove:"remove",cancel:"cancel"},this.addEventListener("click",event=>{event.preventDefault();const button=event.target.closest("button");if(!button)return;const action=button.closest("[data-action]")?.dataset.action;action&&(action===this.actions.confirm?this.toggleConfirmation(!1,!0):action===this.actions.remove?this.clearAllItems():action===this.actions.cancel&&this.toggleConfirmation(!0,!1))})}toggleConfirmation(showButton,showConfirmation){const button=this.querySelector(".cart__clear-all-button"),confirmation=this.querySelector(".cart__clear-all-confirmation");button&&button.classList.toggle("hidden",!showButton),confirmation&&confirmation.classList.toggle("hidden",!showConfirmation)}clearAllItems(){const cartItems=document.querySelector("cart-items");if(!cartItems){console.error("cart-items not found");return}const cartItemsData=cartItems.dataset.cartItems,itemCount=parseInt(cartItems.dataset.itemCount||"0");if(!cartItemsData){console.error("Cart items data not found");return}let variantIds;try{variantIds=JSON.parse(cartItemsData)}catch(e){console.error("Failed to parse cart items data:",e);return}const updates={};variantIds.forEach(variantId=>{updates[variantId]=0});const checkoutButton=document.querySelector('.cart__footer [name="checkout"]'),allClearButtons=this.querySelectorAll("button");allClearButtons.forEach(btn=>btn.disabled=!0),checkoutButton&&(checkoutButton.disabled=!0);const cartItemsContainer=document.getElementById("main-cart-items");cartItemsContainer&&cartItemsContainer.classList.add("cart__items--disabled");const errorContainer=document.getElementById("cart-errors");errorContainer&&(errorContainer.textContent="");const body=JSON.stringify({updates,sections:cartItems.getSectionsToRender().map(section=>section.section),sections_url:window.location.pathname});fetch(`${routes.cart_update_url}`,{...fetchConfig(),body}).then(response=>response.text()).then(state=>{const parsedState=JSON.parse(state);window.location.reload()}).catch(error=>{console.error("Error clearing cart:",error),errorContainer&&(errorContainer.textContent=window.cartStrings.error||"There was an error clearing your cart."),allClearButtons.forEach(btn=>btn.disabled=!1),checkoutButton&&(checkoutButton.disabled=!1),this.toggleConfirmation(!0,!1)}).finally(()=>{cartItemsContainer&&cartItemsContainer.classList.remove("cart__items--disabled")})}}customElements.define("cart-clear-all-button",CartClearAllButton);class CartItems extends HTMLElement{constructor(){super(),this.lineItemStatusElement=document.getElementById("shopping-cart-line-item-status")||document.getElementById("CartDrawer-LineItemStatus");const debouncedOnChange=debounce(event=>{this.onChange(event)},ON_CHANGE_DEBOUNCE_TIMER);this.addEventListener("change",debouncedOnChange.bind(this))}
1cartUpdateUnsubscriber=void 0;connectedCallback(){this.cartUpdateUnsubscriber=subscribe(PUB_SUB_EVENTS.cartUpdate,event=>{if(event.source!=="cart-items")return this.onCartUpdate()})}disconnectedCallback(){this.cartUpdateUnsubscriber&&this.cartUpdateUnsubscriber()}resetQuantityInput(id){const input=this.querySelector(`#Quantity-${id}`);input.value=input.getAttribute("value"),this.isEnterPressed=!1}setValidity(event,index,message){event.target.setCustomValidity(message),event.target.reportValidity(),this.resetQuantityInput(index),event.target.select()}validateQuantity(event){const inputValue=parseInt(event.target.value),index=event.target.dataset.index;let message="";inputValue<event.target.dataset.min?message=window.quickOrderListStrings.min_error.replace("[min]",event.target.dataset.min):inputValue>parseInt(event.target.max)?message=window.quickOrderListStrings.max_error.replace("[max]",event.target.max):inputValue%parseInt(event.target.step)!==0&&(message=window.quickOrderListStrings.step_error.replace("[step]",event.target.step)),message?this.setValidity(event,index,message):(event.target.setCustomValidity(""),event.target.reportValidity(),this.updateQuantity(index,inputValue,event,document.activeElement.getAttribute("name"),event.target.dataset.quantityVariantId))}onChange(event){this.validateQuantity(event)}onCartUpdate(){return this.tagName==="CART-DRAWER-ITEMS"?fetch(`${routes.cart_url}?section_id=cart-drawer`).then(response=>response.text()).then(responseText=>{const html=new DOMParser().parseFromString(responseText,"text/html"),currentDrawerInner=document.querySelector("cart-drawer .drawer__inner"),newDrawerInner=html.querySelector(".drawer__inner");currentDrawerInner&&newDrawerInner&&(currentDrawerInner.innerHTML=newDrawerInner.innerHTML);const cartDrawerWrapper=document.querySelector("cart-drawer"),newCartDrawerItems=document.querySelector("cart-drawer-items"),itemCount=parseInt(newCartDrawerItems?.dataset.itemCount||"0");return cartDrawerWrapper&&(itemCount===0?cartDrawerWrapper.classList.add("is-empty"):cartDrawerWrapper.classList.remove("is-empty")),fetch(`${routes.cart_url}?section_id=cart-icon-bubble`).then(response=>response.text()).then(iconHtml=>{const iconDoc=new DOMParser().parseFromString(iconHtml,"text/html"),newCartIcon=iconDoc.querySelector("#cart-icon-bubble"),currentCartIcon=document.getElementById("cart-icon-bubble");if(newCartIcon&&currentCartIcon)currentCartIcon.innerHTML=newCartIcon.innerHTML;else{const newIconContent=iconDoc.querySelector(".shopify-section"),currentCartIconBubble=document.getElementById("shopify-section-cart-icon-bubble");newIconContent&&currentCartIconBubble&&(currentCartIconBubble.innerHTML=newIconContent.innerHTML)}})}).catch(e=>{console.error(e)}):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-cart-icon-bubble"},{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"}]}updateQuantity(line,quantity,event,name,variantId){const eventTarget=event.currentTarget instanceof CartRemoveButton?"clear":"change",cartPerformanceUpdateMarker=CartPerformance.createStartingMarker(`${eventTarget}:user-action`);this.enableLoading(line);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);CartPerformance.measure(`${eventTarget}:paint-updated-sections`,()=>{const 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);return}this.classList.toggle("is-empty",parsedState.item_count===0);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=>{if(section.id==="cart-icon-bubble"&&parsedState.sections[section.section]){const newCartIcon=new DOMParser().parseFromString(parsedState.sections[section.section],"text/html").querySelector("#cart-icon-bubble"),currentCartIcon=document.getElementById("cart-icon-bubble");newCartIcon&&currentCartIcon&&(currentCartIcon.innerHTML=newCartIcon.innerHTML,console.log("[updateQuantity] Cart icon bubble updated (direct element)"));return}const elementToReplace=document.querySelector(section.selector)||document.getElementById(section.id)?.querySelector(section.selector)||document.getElementById(section.id);if(elementToReplace&&parsedState.sections[section.section]){const newHTML=this.getSectionInnerHTML(parsedState.sections[section.section],section.selector);elementToReplace.innerHTML=newHTML}});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",cartData:parsedState,variantId})}).catch(()=>{this.querySelectorAll(".loading__spinner").forEach(overlay=>overlay.classList.add("hidden"));const errors=document.getElementById("cart-errors")||document.getElementById("CartDrawer-CartErrors");errors.textContent=window.cartStrings.error}).finally(()=>{this.disableLoading(line),CartPerformance.measureFromMarker(`${eventTarget}:user-action`,cartPerformanceUpdateMarker)})}updateLiveRegions(line,message){const lineItemError=document.getElementById(`Line-item-error-${line}`)||document.getElementById(`CartDrawer-LineItemError-${line}`);lineItemError&&(lineItemError.querySelector(".cart-item__error-text").textContent=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){const parsed=new DOMParser().parseFromString(html,"text/html");let element=parsed.querySelector(selector);if(!element&&selector!==".shopify-section"){const section=parsed.querySelector(".shopify-section");section&&(element=section.querySelector(selector))}return element||(element=parsed.querySelector(".shopify-section")),element?element.innerHTML:""}enableLoading(line){(document.getElementById("main-cart-items")||document.getElementById("CartDrawer-CartItems")).classList.add("cart__items--disabled");const cartItemElements=this.querySelectorAll(`#CartItem-${line} .loading__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);
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__spinner`),cartDrawerItemElements=this.querySelectorAll(`#CartDrawer-Item-${line} .loading__spinner`);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}).then(()=>CartPerformance.measureFromEvent("note-update:user-action",event))},ON_CHANGE_DEBOUNCE_TIMER))}});
2//# sourceMappingURL=/cdn/shop/t/10/assets/cart.js.map?v=159899153119223957401767075967

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.