PageSourceSearch

https://sprinkle-th.com/js/pages/cart/vue/drawer.js?id=9cf368cb3b8ba65c650c98afd7dcdea6

js sprinkle-th.com collected 2026-09-25 07:11:47 UTC 6,646 bytes, 1 lines download raw bytes

1const{createApp:createCartDrawerApp}=Vue,CART_DRAWER_SYNC_DELAY=500,cartDrawer=createCartDrawerApp({data(){const e=window.cartDrawerData||{};return{isOpen:!1,items:e.items||[],priceTotal:e.priceTotal||"",labels:e.labels||{},alsoLikeProducts:[],isSynced:!1,isBusy:!1,desiredQty:new Map,headerCompensated:!1,isAlsoLikeExpanded:"expanded"===localStorage.getItem("cartDrawerAlsoLike"),isAlsoLikeHovered:!1,alsoLikeHoverBlocked:!1}},computed:{isEmpty(){return 0===this.items.length},isLoading(){return!this.isSynced&&this.isEmpty},totalQty(){return this.items.reduce(((e,t)=>e+Number(t.qty)),0)},isTotalUpdating(){return this.desiredQty.size>0},countLabel(){return(1===this.totalQty?this.labels.countOne||":number":this.labels.countMany||":number").replace(":number",this.totalQty)},detailLabel(){return this.labels.detail||""},isAlsoLikeOpen(){return this.isAlsoLikeExpanded||this.isAlsoLikeHovered}},watch:{totalQty(){this.syncHeaderBadge()}},created(){this.alsoLikeHoverTimer=null,this.syncTimer=null,this.isSyncing=!1,this.syncRun=Promise.resolve(),this.cartVersion=0,this.syncedQty=new Map,this.items.forEach((e=>this.syncedQty.set(e.rowid,Number(e.qty))))},mounted(){this.syncHeaderBadge(),document.addEventListener("keydown",this.handleKeydown),window.cartDrawer={open:this.open,close:this.close,toggle:this.toggle,refresh:this.refresh}},beforeUnmount(){document.removeEventListener("keydown",this.handleKeydown),clearTimeout(this.alsoLikeHoverTimer),clearTimeout(this.syncTimer)},methods:{open(){this.isOpen||(this.isOpen=!0,this.lockScroll(),this.refresh(),this.$nextTick((()=>{this.$refs.closeButton?.focus()})))},close(){this.isOpen&&(this.isOpen=!1,this.unlockScroll())},lockScroll(){const e=window.innerWidth-document.documentElement.clientWidth,t=document.getElementById("header");document.body.style.overflow="hidden",e<=0||(document.body.style.paddingRight=`${e}px`,t&&"fixed"===window.getComputedStyle(t).position&&(this.setHeaderPadding(t,`${e}px`),this.headerCompensated=!0))},unlockScroll(){const e=document.getElementById("header");document.body.style.overflow="",document.body.style.paddingRight="",this.headerCompensated&&e&&(this.setHeaderPadding(e,""),this.headerCompensated=!1)},setHeaderPadding(e,t){const s=e.style.transition;e.style.transition="none",e.style.paddingRight=t,e.offsetWidth,e.style.transition=s},toggle(){this.isOpen?this.close():this.open()},handleKeydown(e){"Escape"===e.key&&this.isOpen&&this.close()},async refresh(){const e=this.cartVersion;try{const{data:t}=await window.cart.fetchCartData();return this.isSynced=!0,e!==this.cartVersion?t:(this.items=this.keepDesiredQty(t.productCarts||[]),this.alsoLikeProducts=t.alsoLikeProducts||[],this.priceTotal=t.priceTotal,t)}catch(e){console.error("Cart drawer: failed to load cart",e)}},handleCheckout(e){this.isTotalUpdating&&e.preventDefault()},handleIncrease(e){this.setQty(e,Number(e.qty)+1)},handleDecrease(e){const t=Number(e.minimumQuantity||e.minimum_quantity||1);Number(e.qty)<=t||this.setQty(e,Number(e.qty)-1)},setQty(e,t){e.qty=t,this.desiredQty.set(e.rowid,t),this.scheduleSync()},scheduleSync(){clearTimeout(this.syncTimer),this.syncTimer=setTimeout((()=>{this.syncTimer=null,this.flushSync()}),500)},flushSync(){return this.isSyncing||(this.syncRun=this.runSync()),this.syncRun},async settleSync(){clearTimeout(this.syncTimer),this.syncTimer=null,await this.flushSync()},async runSync(){this.isSyncing=!0;try{for(;;){const e=[...this.desiredQty].find((([e,t])=>this.syncedQty.get(e)!==t));if(!e)break;await this.updateCartOnServer(e[0],e[1])}this.desiredQty.clear()}finally{this.isSyncing=!1}},cancelSync(e){this.desiredQty.delete(e),this.syncedQty.delete(e)},keepDesiredQty(e){const t=new Map,s=e.map((e=>{t.set(e.rowid,Number(e.qty));const s=this.desiredQty.get(e.rowid);return void 0===s?e:{...e,qty:s}}));return this.syncedQty=t,s},async updateCartOnServer(e,t){try{const{data:s}=await window.cart.updateCartItemQty(e,t);this.cartVersion++,this.syncedQty.set(e,t),s.cart_total&&(this.priceTotal=s.cart_total);const i=this.items.find((t=>t.rowid===e)),r=(s.items||[]).find((t=>t.rowid===e));i&&r&&(i.optionPrice=r.formatted_price)}catch(t){console.error("Cart drawer: failed to update quantity",t),this.desiredQty.delete(e),this.syncedQty.delete(e),await this.refresh()}},async handleRemove(e){const t=0!==Number(e.promotion);this.isBusy=!0,this.cancelSync(e.rowid),await this.settleSync();try{await window.cart.removeCartItem(e.rowid),t&&(sessionStorage.removeItem("inCartPromotion"),window.dispatchEvent(new CustomEvent("promotion-cart-deleted"))),this.items=this.items.filter((t=>t.rowid!==e.rowid)),this.isBusy=!1,await this.refresh()}catch(e){console.error("Cart drawer: failed to remove item",e),this.isBusy=!1,await this.refresh()}}
1,async clearAll(){this.isBusy=!0,this.items.forEach((e=>this.cancelSync(e.rowid))),await this.settleSync();try{const e=this.items.some((e=>0!==Number(e.promotion)));await window.cart.clearFullCart(),e&&(sessionStorage.removeItem("inCartPromotion"),window.dispatchEvent(new CustomEvent("promotion-cart-deleted"))),this.items=[],this.priceTotal="",this.alsoLikeProducts=[],this.isBusy=!1,await this.refresh()}catch(e){console.error("Cart drawer: failed to clear cart",e),this.isBusy=!1,await this.refresh()}},async handleAlsoLikeAdd(e){const t=new FormData,s={pro_id:e?.id,qty:e?.minimumQuantity||1};Object.entries(s).forEach((([e,s])=>{t.append(`items[0][${e}]`,s)})),this.isBusy=!0;try{await window.checkout.setProductToCart(t),await this.refresh(),this.$nextTick((()=>{const e=this.$refs.cartBody;e&&e.scrollTo({top:e.scrollHeight,behavior:"smooth"})}))}catch(e){console.error("Cart drawer: failed to add product",e)}this.isBusy=!1},onAlsoLikeEnter(){this.alsoLikeHoverBlocked||this.isAlsoLikeExpanded||(clearTimeout(this.alsoLikeHoverTimer),this.alsoLikeHoverTimer=setTimeout((()=>{this.isAlsoLikeHovered=!0}),140))},onAlsoLikeLeave(){clearTimeout(this.alsoLikeHoverTimer),this.isAlsoLikeHovered=!1,this.alsoLikeHoverBlocked=!1},toggleAlsoLike(){const e=this.isAlsoLikeOpen;clearTimeout(this.alsoLikeHoverTimer),this.isAlsoLikeExpanded=!e,this.isAlsoLikeHovered=!1,this.alsoLikeHoverBlocked=e,localStorage.setItem("cartDrawerAlsoLike",this.isAlsoLikeExpanded?"expanded":"collapsed")},scrollAlsoLike(e){const t=this.$refs.alsoLikeList;t&&t.scrollBy({left:220*e,behavior:"smooth"})},syncHeaderBadge(){document.querySelectorAll(".noti").forEach((e=>{e.setAttribute("s-show",this.totalQty>0?1:"")}))}}});cartDrawer.component("cart-drawer-item",CartDrawerItem),cartDrawer.component("cart-drawer-also-like",CartDrawerAlsoLike),document.getElementById("cartDrawerApp")&&cartDrawer.mount("#cartDrawerApp");

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.