{% liquid if customer assign account_url = routes.account_url else assign account_url = routes.account_login_url endif if section.settings.promo_text != blank assign promo_text = section.settings.promo_text else assign promo_text = 'header.promo' | t endif %}
{% if promo_text != blank %}
{% if section.settings.promo_link != blank %} {{ promo_text }} {% else %}

{{ promo_text }}

{% endif %}
{% endif %}
{% javascript %} (() => { if (window.__seasonHeader) return; window.__seasonHeader = true; const mobileQuery = window.matchMedia('(max-width: 1119px)'); const setHeaderOffset = () => { const group = document.querySelector('.shopify-section-group-header-group'); if (!group) return; document.documentElement.style.setProperty('--header-offset', group.offsetHeight + 'px'); }; setHeaderOffset(); window.addEventListener('resize', setHeaderOffset); const closeMenu = (header) => { const menu = header.querySelector('[data-menu]'); const toggle = header.querySelector('[data-menu-toggle]'); menu?.classList.remove('is-open'); header.classList.remove('is-menu-open'); toggle?.setAttribute('aria-expanded', 'false'); if (toggle) toggle.setAttribute('aria-label', toggle.dataset.labelOpen || ''); document.documentElement.classList.remove('overflow-hidden'); }; const closePredictive = (header) => { const panel = header.querySelector('[data-predictive]'); const input = header.querySelector('[data-search-input]'); const status = header.querySelector('[data-predictive-status]'); panel?.classList.remove('is-open'); panel?.setAttribute('hidden', ''); input?.setAttribute('aria-expanded', 'false'); input?.removeAttribute('aria-activedescendant'); if (status) status.textContent = ''; }; const closeSearch = (header) => { header.querySelector('[data-search]')?.classList.remove('is-open'); closePredictive(header); }; const bind = (header) => { if (header.dataset.ready === 'true') return; header.dataset.ready = 'true'; const toggle = header.querySelector('[data-menu-toggle]'); const menu = header.querySelector('[data-menu]'); const searchForm = header.querySelector('[data-search]'); const searchInput = header.querySelector('[data-search-input]'); const backdrop = header.querySelector('[data-menu-backdrop]'); if (toggle) { toggle.dataset.labelOpen = toggle.getAttribute('aria-label') || ''; toggle.dataset.labelClose = header.dataset.menuClose || toggle.dataset.labelOpen; } toggle?.addEventListener('click', () => { const willOpen = !menu.classList.contains('is-open'); closeSearch(header); menu.classList.toggle('is-open', willOpen); header.classList.toggle('is-menu-open', willOpen); toggle.setAttribute('aria-expanded', willOpen ? 'true' : 'false'); toggle.setAttribute('aria-label', willOpen ? toggle.dataset.labelClose : toggle.dataset.labelOpen); document.documentElement.classList.toggle('overflow-hidden', willOpen); }); backdrop?.addEventListener('click', () => closeMenu(header)); searchForm?.addEventListener('submit', (event) => { if (!mobileQuery.matches || searchForm.classList.contains('is-open')) return; event.preventDefault(); closeMenu(header); searchForm.classList.add('is-open'); searchInput?.focus(); }); if (searchForm && searchInput) { const panel = searchForm.querySelector('[data-predictive]'); const status = searchForm.querySelector('[data-predictive-status]'); let requestId = 0; let controller = null; let timer = 0; const resultOptions = () => [...panel.querySelectorAll('[role="option"]')]; const setActive = (index) => { const items = resultOptions(); items.forEach((item, itemIndex) => { const active = itemIndex === index; item.classList.toggle('is-active', active); if (active) searchInput.setAttribute('aria-activedescendant', item.id); }); if (index < 0) searchInput.removeAttribute('aria-activedescendant'); if (index >= 0 && items[index]) items[index].scrollIntoView({ block: 'nearest' }); }; const openPredictive = () => { panel.hidden = false; panel.classList.add('is-open'); searchInput.setAttribute('aria-expanded', 'true'); }; const fetchResults = (term) => { const id = ++requestId; controller?.abort(); controller = new AbortController(); const url = new URL(searchForm.dataset.predictiveUrl, window.location.origin); url.searchParams.set('q', term); url.searchParams.set('resources[type]', 'product'); url.searchParams.set('resources[limit]', '6'); url.searchParams.set('resources[options][unavailable_products]', 'last'); url.searchParams.set('section_id', 'predictive-search'); fetch(url, { signal: controller.signal }) .then((response) => { if (!response.ok) throw new Error('predictive search failed'); return response.text(); }) .then((html) => { if (id !== requestId || searchInput.value.trim() !== term) return; const parsed = new DOMParser().parseFromString(html, 'text/html'); const body = parsed.querySelector('.header__predictive-body'); if (!body) { closePredictive(header); return; } panel.replaceChildren(body); const count = panel.querySelector('[data-predictive-count]'); if (status && count) status.textContent = count.textContent; setActive(-1); openPredictive(); }) .catch((error) => { if (error.name === 'AbortError') return; if (id === requestId) closePredictive(header); }); }; searchInput.addEventListener('input', () => { const term = searchInput.value.trim(); window.clearTimeout(timer); if (term.length < 3) { requestId += 1; controller?.abort(); closePredictive(header); return; } timer = window.setTimeout(() => fetchResults(term), 180); }); searchInput.addEventListener('keydown', (event) => { if (!panel.classList.contains('is-open')) return; const items = resultOptions(); if (items.length === 0) return; const current = items.findIndex((item) => item.classList.contains('is-active')); if (event.key === 'ArrowDown') { event.preventDefault(); setActive(current < items.length - 1 ? current + 1 : 0); } else if (event.key === 'ArrowUp') { event.preventDefault(); setActive(current > 0 ? current - 1 : items.length - 1); } else if (event.key === 'Enter' && current >= 0) { event.preventDefault(); window.location.assign(items[current].href); } }); } menu?.addEventListener('click', (event) => { const submenuToggle = event.target.closest('[data-submenu-toggle]'); const toggleSubmenu = (submenuToggle) => { const item = submenuToggle.closest('[data-menu-item]'); const expanded = submenuToggle.getAttribute('aria-expanded') === 'true'; item.parentElement.querySelectorAll('[data-menu-item].is-open').forEach((sibling) => { if (sibling === item) return; sibling.classList.remove('is-open'); sibling.querySelector('[data-submenu-toggle]')?.setAttribute('aria-expanded', 'false'); }); item.classList.toggle('is-open', !expanded); submenuToggle.setAttribute('aria-expanded', expanded ? 'false' : 'true'); }; if (submenuToggle) { event.preventDefault(); toggleSubmenu(submenuToggle); return; } const parentLink = event.target.closest('[data-menu-item] > a'); if (mobileQuery.matches && parentLink) { const submenuToggleForLink = parentLink.parentElement.querySelector('[data-submenu-toggle]'); if (submenuToggleForLink) { event.preventDefault(); toggleSubmenu(submenuToggleForLink); return; } } if (mobileQuery.matches && event.target.closest('a')) closeMenu(header); }); }; document.querySelectorAll('[data-header]').forEach((header) => { header.dataset.menuClose = header.getAttribute('data-menu-close') || ''; bind(header); }); document.addEventListener('click', (event) => { document.querySelectorAll('[data-header]').forEach((header) => { const searchForm = header.querySelector('[data-search]'); if (searchForm && !searchForm.contains(event.target)) closePredictive(header); if (header.contains(event.target)) return; closeMenu(header); closeSearch(header); }); }); document.addEventListener('keydown', (event) => { if (event.key !== 'Escape') return; if (document.querySelector('[data-wish-drawer].is-open')) return; document.querySelectorAll('[data-header]').forEach((header) => { const panel = header.querySelector('[data-predictive]'); if (panel && !panel.hidden) { closePredictive(header); return; } closeMenu(header); closeSearch(header); }); }); mobileQuery.addEventListener('change', (event) => { if (event.matches) return; document.querySelectorAll('[data-header]').forEach((header) => { closeMenu(header); closeSearch(header); }); }); document.addEventListener('shopify:section:load', (event) => { const header = event.target.querySelector('[data-header]'); if (header) bind(header); }); const wishKey = 'seasons-wishlist'; const wishDrawer = document.querySelector('[data-wish-drawer]'); const wishList = document.querySelector('[data-wish-list]'); const wishButton = document.querySelector('[data-wish-open]'); const wishCount = document.querySelector('[data-wish-count]'); const readWishItems = () => { try { const stored = JSON.parse(window.localStorage.getItem(wishKey)); if (!Array.isArray(stored)) return []; return stored.map((item) => { if (item && typeof item === 'object') return { id: String(item.id || ''), handle: String(item.handle || '') }; return { id: String(item), handle: '' }; }).filter((item) => item.id); } catch (error) { return []; } }; const writeWishItems = (items) => { window.localStorage.setItem(wishKey, JSON.stringify(items)); document.dispatchEvent(new CustomEvent('seasons:wishlist')); }; const formatPrice = (cents) => { const currency = (window.Shopify && Shopify.currency && Shopify.currency.active) || 'MXN'; return new Intl.NumberFormat('es-MX', { style: 'currency', currency, minimumFractionDigits: 0, maximumFractionDigits: 2, }).format(cents / 100); }; let wishRequest = 0; const updateWishCount = () => { const count = readWishItems().filter((item) => item.handle).length; if (!wishButton || !wishCount) return; wishButton.classList.toggle('is-active', count > 0); wishCount.textContent = count > 0 ? String(count) : ''; wishCount.classList.toggle('is-visible', count > 0); const label = wishButton.dataset.countLabel || ''; if (label) wishButton.setAttribute('aria-label', label.replace('__COUNT__', String(count))); }; const renderWishList = async () => { if (!wishList) return; const request = ++wishRequest; const items = readWishItems().filter((item) => item.handle); if (!items.length) { wishList.replaceChildren(); const empty = document.createElement('p'); empty.className = 'wish-drawer__empty'; empty.textContent = wishDrawer?.dataset.empty || ''; wishList.append(empty); return; } const products = await Promise.all(items.map(async (item) => { try { const response = await fetch(window.location.origin + '/products/' + item.handle + '.js'); if (!response.ok) return null; const product = await response.json(); product._wishId = item.id; return product; } catch (error) { return null; } })); if (request !== wishRequest) return; const found = products.filter(Boolean); wishList.replaceChildren(); if (!found.length) { const empty = document.createElement('p'); empty.className = 'wish-drawer__empty'; empty.textContent = wishDrawer?.dataset.empty || ''; wishList.append(empty); return; } found.forEach((product) => { const row = document.createElement('article'); row.className = 'wish-drawer__item'; const link = document.createElement('a'); link.className = 'wish-drawer__thumb'; link.href = product.url; let imageSource = typeof product.featured_image === 'string' ? product.featured_image : product.featured_image && product.featured_image.src; if (imageSource && imageSource.indexOf('//') === 0) imageSource = 'https:' + imageSource; if (imageSource) { const image = document.createElement('img'); image.src = imageSource; image.alt = ''; image.width = 72; image.height = 72; link.append(image); } const copy = document.createElement('div'); const name = document.createElement('a'); name.className = 'wish-drawer__name'; name.href = product.url; name.textContent = product.title; const price = document.createElement('p'); price.className = 'wish-drawer__price'; price.textContent = formatPrice(product.price); copy.append(name, price); const remove = document.createElement('button'); remove.className = 'wish-drawer__remove'; remove.type = 'button'; remove.dataset.wishRemove = product._wishId; remove.textContent = wishDrawer?.dataset.remove || ''; row.append(link, copy, remove); wishList.append(row); }); }; const setWishOpen = (open) => { if (!wishDrawer || !wishButton) return; wishDrawer.classList.toggle('is-open', open); wishDrawer.setAttribute('aria-hidden', open ? 'false' : 'true'); document.querySelectorAll('[data-wish-open]').forEach((control) => { control.setAttribute('aria-expanded', open ? 'true' : 'false'); }); document.documentElement.classList.toggle('overflow-hidden', open); if (open) { document.querySelectorAll('[data-header]').forEach((header) => { closeMenu(header); closeSearch(header); closePredictive(header); }); document.querySelector('[data-cart-drawer].is-open [data-cart-drawer-close]')?.click(); renderWishList(); wishDrawer.querySelector('.wish-drawer__close')?.focus(); } }; updateWishCount(); document.addEventListener('seasons:wishlist', () => { updateWishCount(); if (wishDrawer?.classList.contains('is-open')) renderWishList(); }); document.addEventListener('click', (event) => { if (event.target.closest('[data-wish-open]')) { event.preventDefault(); setWishOpen(!wishDrawer?.classList.contains('is-open')); return; } if (event.target.closest('[data-wish-close]')) { setWishOpen(false); wishButton?.focus(); return; } const remove = event.target.closest('[data-wish-remove]'); if (!remove) return; const id = remove.dataset.wishRemove; writeWishItems(readWishItems().filter((item) => item.id !== id)); }); document.addEventListener('keydown', (event) => { if (event.key !== 'Escape' || !wishDrawer?.classList.contains('is-open')) return; setWishOpen(false); wishButton?.focus(); }); })(); {% endjavascript %} {% schema %} { "name": "t:general.header", "settings": [ { "type": "image_picker", "id": "logo", "label": "t:header.logo" }, { "type": "link_list", "id": "menu", "label": "t:header.main_menu", "info": "t:header.main_menu_info" }, { "type": "link_list", "id": "pills_menu", "label": "t:header.pills_menu" }, { "type": "link_list", "id": "utility_menu", "label": "t:header.utility_menu" }, { "type": "text", "id": "promo_text", "label": "t:header.promo_text", "default": "Cambia tu piel ¡hoy!" }, { "type": "url", "id": "promo_link", "label": "t:header.promo_link" } ] } {% endschema %}