(function () { window.lbSelleasyUtils = { drawerRefresh: refreshDrawer } function refreshDrawer() { let functions = [ window.SLIDECART_UPDATE, window.SLIDECART_OPEN, window.theme?.ajaxCart?.update, window.theme?.Cart?.updateCart, window.updateMiniCartContents, window.loadEgCartDrawer, window.cart?.getCart, window.cart?.openCartDropdown, window.ajaxCart?.load, window.icartCartActivityEvent, window.HsCartDrawer?.updateSlideCart, window.HS_SLIDE_CART_OPEN, window.CartJS?.getCart, window.Shopify?.theme?.jsAjaxCart?.updateView, window.theme?.MiniCart?.update, window.STICKY_CART_UPDATE, window.Alpine?.store?.('xMiniCart')?.reLoad, window.Alpine?.store?.('xMiniCart')?.openCart, window.opusRefreshCart, window.opusOpen, window.EliteCart?.openDrawerWithDataRefresh, () => { window.emit !== undefined && window.emit?.(["quick-cart:updated", "quick-view:close", "quick-cart:open"]); }, () => { document.querySelector("cart-form")?.refresh?.(); }, window.openCartDrawer, window.theme?.cart?.updateTotals, window.theme?.cart?.updateAllHtml, window.getCart, window.openCart ] let events = ["cart:build", "cart:open", "cart:open", "obsidian:upsell:refresh", "obsidian:upsell:open", "update_cart", "updateCart", "theme:update:cart", "apps:product-added-to-cart", "baseline:modalcart:afteradditem", "product:added"] events.forEach(event => { try { let detail = { bubbles: true, } document.documentElement.dispatchEvent(new CustomEvent(event, detail)); document.dispatchEvent(new CustomEvent(event, detail)); document.body.dispatchEvent(new CustomEvent(event, detail)); } catch (e) { } }) functions.forEach(action => { try { action(); } catch (e) { } }) let formSections = ["cart-drawer", "cart-notification-product", "cart-notification-button", "cart-icon-bubble", "mini-cart"]; try { var cartNotification = document.querySelector("cart-notification"); if (cartNotification !== null) { fetch(`/cart?sections=${formSections.join(",")}`).then(function (response) { return response.clone().json().then(function (data) { fetch("/cart.js").then(function (response) { return response.json(); }).then(function (cartData) { if (cartData?.items?.length) { var cartContents = { sections: data, key: cartData?.items[0]?.key, id: cartData?.items[0]?.id }; "function" == typeof cartNotification.renderContents && cartNotification.renderContents(cartContents); cartNotification.classList[cartData?.items?.length === 0 ? 'add' : 'remove']('is-empty'); let count = document.querySelector('#CartCount'); if (count) count.innerText = cartData?.item_count; } else { document.querySelector(".cart-count-bubble")?.remove(); } }); }); }); } } catch (error) { console.error(error); } try { var o = document.querySelector("cart-drawer"); if (null !== o) fetch(`/cart?sections=${formSections.join(",")}`).then(function (e) { return e.clone().json().then(function (e) { fetch("/cart.js").then(function (e) { return e.json(); }).then(function (t) { if (t && t.item_count) { var n = { sections: e, ...t.items[0], }; "function" == typeof o.renderContents && o.renderContents(n); o.classList.contains("is-empty") && o.classList.remove("is-empty"); document.documentElement.dispatchEvent(new CustomEvent('cart:refresh', { 'bubbles': true, 'detail': { 'cart': n, 'openMiniCart': true } })); } else { document.querySelector(".cart-count-bubble")?.remove(); } }); }); }); } catch (e) { console.error(e); } const freeSections = ['ajax-cart']; const freeSectionsEvents = ['cart:refresh', 'cart-add', 'cart-change', 'product:added']; const freeFunctions = [ window.buildCart, window.DoublyGlobalCurrency?.convertAll ]; fetch(`/cart?sections=${freeSections.join(",")}`).then(function (e) { return e.clone().json().then(function (e) { fetch("/cart.js").then(function (e) { return e.json(); }).then(function (t) { if (t && t.item_count) { var n = { sections: e, ...t.items[0], item_count: t.item_count, }; freeFunctions.filter(f => f).forEach(function (func) { try { func(n); } catch (e) { console.error(e); } }); freeSectionsEvents.forEach(event => { document.dispatchEvent(new CustomEvent(event, { 'bubbles': true, 'detail': n })); }); } else { document.querySelector(".cart-count-bubble")?.remove(); } }); }); }); } function helpers() { typeof window.upcartOnAddToCart !== 'undefined' && ( window.upcartOnAddToCart = function () { window.lbHandlers.triggers(); } ) } helpers(); })()