Purpose#
This page documents Assets/js/theme.js.theme.js is the theme’s main client-side boot file. It is responsible for:Global initialization on DOMContentLoaded
Defining shared utilities (cookies, IntersectionObserver helpers, etc.)
Defining Google Analytics (GA4) helpers and mappings
Wiring or supporting global Alpine stores by providing shared helpers/services
It is loaded once (from the layout) and is expected to be safe to run on every page.What theme.js contains#
Global initialization (DOMContentLoaded)#
theme.js registers a DOMContentLoaded handler that performs page-level bootstrapping.Main min-height calculation#
It calculates a CSS variable --min-height on <main> so the footer is pushed to the bottom.Sets main.style.setProperty('--min-height', '<px>')
Recalculates on window.resize
Cart token initialization#
If localStorage.cartToken does not exist, it is created.Calls GET /api/cart/user and stores the returned token.
Generates a token using servicesreusabledefault.uuidv4().
Writes localStorage.cartToken
Writes cookie cartToken via setCookie('cartToken', ...)
userAuthenticated global flag (provided by the rendered page/layout)
servicesreusabledefault.getAxiosResponse(...)
servicesreusabledefault.uuidv4()
When window.showProductComparison is enabled, theme.js updates the floating compare button.It reads comparison state from the cookie:comparisonData (JSON array)
storage events with key comparisonSync
Custom event comparisonListUpdated
Sets button display to flex when there are items
Updates the numeric count element
Cookie management helpers#
theme.js defines small cookie helpers:setCookie(name, value, days = 31)sets a cookie with an expiry
setSessionCookie(name, value)returns a cookie value as string
These helpers are widely reused by other scripts and services.Google Analytics 4 (GA4) helpers#
theme.js contains a large GA4 helper section.GoogleAnalyticsActions constants
ga4Mapping mapping object
getCurrencyCode() utility (reads _currency cookie; defaults to eur)
IntersectionObserver helper: elementInView(...)#
elementInView(targets, onInView, options) wraps an IntersectionObserver.targets: element, selector string, or array of elements
root, rootMargin, threshold
Falls back to calling onInView() immediately when IntersectionObserver is not supported.
Item mapping helpers#
Helpers prepare items for GA events:mapItemsToGAFormat(items)
preparePropertiesForGA(items, listName, listIndex)
calculateTotalValue(items)
Convert internal item shapes into GA4 item properties
Support batching with GOOGLE_ANALYTICS_BATCH_SIZE
Alpine stores initialized in theme.js#
theme.js initializes multiple global Alpine stores during document.addEventListener('alpine:init', ...).These stores are part of the theme’s shared runtime “contract” and are referenced from Liquid templates via $store.<name>.profile#
Holds lightweight state related to Profile tabs.
sharedAddresses#
Shared state for addresses/invoices forms across different areas.
updateShippingAddresses (boolean)
updateValidAddress(index, isValid)
updateAddress(index, updatedAddress, isB2bCustomer = false)
updateInvoice(index, updatedInvoice)
cart#
Client-side mirror of cart summary data, backed by localStorage.cartData.
Optional “added to cart” popup behavior.
netValueText, vatValueText, finalPriceText
init() (loads from storage and listens to storage events)
update(cartData, addedProductsArray = [], showPopUp = false)
setPopupHovering(isHovering)
showPopup(...) closes $store.productModal before showing the popup.
toast#
Central toast queue used across the entire theme.
add(message, iconClass = null, type = 'info', keepAlive = false, extraHtml = null, extraHtmlIndex = null)
Auto-dismisses messages after 5000ms when keepAlive is false.
modal#
Central modal state (used by prompt/invite/manage flows).
close() also clears toasts if any exist.
viewedAnnouncements#
Tracks which announcements have been viewed.
Guests: session cookie viewed_announcements
Authenticated users: localStorage.viewedAnnouncements
announcementModal#
Manages the single announcement modal state and interactions with the announcements list.
announcements#
Controls visibility of the announcements list.
loginModal#
Central state for the login modal.
open(fromCheckout = false, fromShoppingList = false)
close(keepSuccessMessage = false)
close() dispatches clear-login-modal-forms to clear forms.
productModal#
Holds the product modal (quick view) state.
open(...) reads HTML from [x-ref=variantModalContent-<uniqueKey>].
checkout#
Holds checkout state and step validation.
steps (per-step enabled + valid)
validateStep(step, isSelectable, stepsInvalid = false)
wishlist (conditional)#
Created only when window.showWishlist is enabled.Holds wishlist item ids and provides a toggle(...) method.
toggle(id, removeFromWishlistErrorMessage, addToWishlistErrorMessage)
Uses servicesreusabledefault.addItemToWishlist/removeItemFromWishlist.
Dispatches wishlistUpdated and writes localStorage.wishlistSync.
Created only when window.showShoppingLists is enabled.Manages the “save to shopping list” overlay/panel and list fetching.
dimension1Id, dimension2Id
isProductVariantInAnyList(variantId)
isInShoppingLists(product)
fetchSelectedVariantId(product)
Fetches data through servicesreusabledefault.getShoppingLists().
darkMode#
Controls dark mode by toggling the dark class on <html>.
Dependencies#
servicesreusabledefault (global)
Global flags/values from the rendered page:window.showProductComparison
Notes#
theme.js must be defensive: it runs on every page.
Avoid editing vendor/minified scripts in Assets/js/*.min.js; wrap or re-init via theme.js where needed.
Modified at 2026-04-14 13:18:56