Files
season/sections/header.liquid
2026-10-22 22:33:56 -06:00

1065 lines
44 KiB
Plaintext

{% 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
%}
<header
class="header full-width relative z-40 bg-white font-sans text-black"
data-header
data-menu-close="{{ 'header.menu_close' | t | escape }}"
>
<div class="header__shell relative grid grid-cols-[auto_minmax(0,699px)_1fr_auto_auto] items-center px-[100px] pt-[15px]">
<button
type="button"
class="header__toggle col-start-1 row-start-1 hidden size-[30px] cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0"
data-menu-toggle
aria-expanded="false"
aria-controls="header-menu"
aria-label="{{ 'header.menu_open' | t }}"
>
<span class="header__icon header__icon--menu" aria-hidden="true">
{{ 'icon-menu.svg' | inline_asset_content }}
</span>
<span class="header__icon header__icon--close" aria-hidden="true"></span>
</button>
<a
class="header__logo col-start-1 row-start-1 mr-[50px] block w-[223px] shrink-0 no-underline"
href="{{ routes.root_url }}"
>
{% if section.settings.logo != blank %}
{{
section.settings.logo
| image_url: width: 480
| image_tag: alt: shop.name, class: 'header__logo-image h-auto w-[223px]', widths: '150, 223, 446'
}}
{% else %}
<span class="header__logo-mark" aria-hidden="true">
{{ 'logo-seasons.svg' | inline_asset_content }}
</span>
<span class="sr-only">{{ shop.name }}</span>
{% endif %}
</a>
<form
class="header__search col-start-2 row-start-1 mr-[50px] flex h-[55px] w-full min-w-0 max-w-[699px] items-center rounded-full bg-brand-cloud p-[5px]"
action="{{ routes.search_url }}"
method="get"
role="search"
data-search
data-predictive-url="{{ routes.predictive_search_url }}"
>
<button
type="submit"
class="header__search-button grid size-10 shrink-0 cursor-pointer appearance-none place-items-center rounded-full border-0 bg-brand-mint p-0"
aria-label="{{ 'header.search_label' | t }}"
>
<span class="header__icon header__icon--search" aria-hidden="true">
{{ 'icon-search.svg' | inline_asset_content }}
</span>
</button>
<label class="sr-only" for="header-search">{{ 'header.search_label' | t }}</label>
<input
id="header-search"
class="header__search-input min-w-0 flex-1 border-0 bg-transparent px-5 text-[16px] font-light leading-none text-black outline-none placeholder:font-light placeholder:text-brand-placeholder"
type="search"
name="q"
placeholder="{{ 'header.search_placeholder' | t }}"
{% if template.name == 'search' %}
value="{{ search.terms | escape }}"
{% endif %}
role="combobox"
aria-expanded="false"
aria-controls="header-predictive-{{ section.id }}"
aria-autocomplete="list"
autocomplete="off"
data-search-input
>
<div
id="header-predictive-{{ section.id }}"
class="header__predictive"
data-predictive
role="listbox"
hidden
></div>
<p class="sr-only" data-predictive-status aria-live="polite"></p>
</form>
<div class="header__actions col-start-5 row-start-1 flex items-center">
<button
type="button"
class="header__wish relative flex size-[45px] cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0"
data-wish-open
data-count-label="{{ 'header.wishlist_count' | t: count: '__COUNT__' | escape }}"
aria-controls="wish-drawer"
aria-expanded="false"
aria-haspopup="dialog"
aria-label="{{ 'header.wishlist' | t }}"
>
<span class="header__icon header__icon--wish" aria-hidden="true">
<svg width="22" height="22" viewBox="0 0 25 25" fill="none">
<path d="M17.2324 3.90625C14.0625 3.90625 12.5 7.03125 12.5 7.03125C12.5 7.03125 10.9375 3.90625 7.76758 3.90625C5.19141 3.90625 3.15137 6.06152 3.125 8.6333C3.07129 13.9717 7.35986 17.7681 12.0605 20.9585C12.1901 21.0467 12.3433 21.0938 12.5 21.0938C12.6567 21.0938 12.8099 21.0467 12.9395 20.9585C17.6396 17.7681 21.9282 13.9717 21.875 8.6333C21.8486 6.06152 19.8086 3.90625 17.2324 3.90625Z" stroke="currentColor" stroke-width="1.4" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
<span class="header__wish-count absolute right-0 top-0 hidden h-4 min-w-4 items-center justify-center rounded-full bg-brand-mint px-[3px] text-[10px] font-medium leading-none text-black" data-wish-count></span>
</button>
<button
type="button"
class="header__cart relative flex size-[45px] cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0"
data-cart-open
data-cart-count-label="{{ 'header.cart_count' | t: count: '__COUNT__' | escape }}"
aria-controls="cart-drawer"
aria-expanded="false"
aria-haspopup="dialog"
aria-label="{{ 'header.cart_count' | t: count: cart.item_count }}"
>
<span class="header__icon header__icon--bag" aria-hidden="true">
{{ 'icon-bag.svg' | inline_asset_content }}
</span>
{% if cart.item_count > 0 %}
<span class="absolute right-0 top-0 flex h-4 min-w-4 items-center justify-center rounded-full bg-brand-mint px-[3px] text-[10px] font-medium leading-none text-black" data-cart-count>
{{ cart.item_count }}
</span>
{% endif %}
</button>
</div>
<nav
id="header-menu"
class="header__nav pointer-events-none col-span-5 col-start-1 row-span-2 row-start-1 grid grid-cols-subgrid grid-rows-subgrid self-stretch"
data-menu
>
<div class="header__utility pointer-events-auto col-start-4 row-start-1 mr-5 flex items-center gap-[50px] xxl:gap-8">
<ul class="m-0 flex list-none items-center gap-5 p-0">
{% if section.settings.utility_menu != blank and section.settings.utility_menu.links.size > 0 %}
{% for link in section.settings.utility_menu.links %}
<li>
<a
class="inline-flex items-center px-5 py-1 text-[14px] font-normal leading-none text-black no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-black"
href="{{ link.url }}"
>
{{ link.title }}
</a>
</li>
{% endfor %}
{% else %}
<li>
<a
class="inline-flex items-center px-5 py-1 text-[14px] font-normal leading-none text-black no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-black"
href="/pages/glow-army"
>
{{ 'header.links.glow_army' | t }}
</a>
</li>
<li>
<a
class="inline-flex items-center px-5 py-1 text-[14px] font-normal leading-none text-black no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-black"
href="https://seasonsexperts.com/pages/quiero-ser-distribuidor"
>
{{ 'header.links.experts' | t }}
</a>
</li>
{% endif %}
</ul>
<a
class="header__account flex size-[45px] items-center justify-center no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-black"
href="{{ account_url }}"
>
<span class="header__icon header__icon--user" aria-hidden="true">
{{ 'icon-user.svg' | inline_asset_content }}
</span>
<span class="header__account-label text-[14px] font-normal leading-none text-black">
{{ 'header.account' | t }}
</span>
</a>
</div>
<div class="header__menu pointer-events-auto col-span-5 row-start-2 mt-[15px] flex items-center justify-center gap-[50px] py-2 xxl:gap-8">
<ul class="header__links m-0 flex list-none items-center gap-10 p-0 xxl:gap-6">
{% if section.settings.menu != blank and section.settings.menu.links.size > 0 %}
{% for link in section.settings.menu.links %}
{% render 'header-menu-item', title: link.title, url: link.url, child_links: link.links %}
{% endfor %}
{% else %}
{% liquid
assign nav_categories = 'header.links.categories' | t
assign nav_routine = 'header.links.routine' | t
assign nav_skin_type = 'header.links.skin_type' | t
assign nav_concern = 'header.links.concern' | t
assign label_all = 'header.dropdowns.all_products' | t
assign label_blockers = 'header.dropdowns.blockers' | t
assign label_moisturizers = 'header.dropdowns.moisturizers' | t
assign label_cleansers = 'header.dropdowns.cleansers' | t
assign label_masks = 'header.dropdowns.masks' | t
assign label_serums = 'header.dropdowns.serums' | t
assign label_clean = 'header.dropdowns.clean' | t
assign label_treat = 'header.dropdowns.treat' | t
assign label_hydrate = 'header.dropdowns.hydrate' | t
assign label_protect = 'header.dropdowns.protect' | t
assign label_kits = 'header.dropdowns.kits' | t
assign label_combination = 'header.dropdowns.combination' | t
assign label_oily = 'header.dropdowns.oily' | t
assign label_dry = 'header.dropdowns.dry' | t
assign label_sun = 'header.dropdowns.sun_protection' | t
assign label_oil = 'header.dropdowns.oil_control' | t
assign label_acne = 'header.dropdowns.acne' | t
assign label_hydration = 'header.dropdowns.hydration' | t
assign label_aging = 'header.dropdowns.anti_aging' | t
assign label_spots = 'header.dropdowns.spots' | t
assign categories_menu = label_all | append: '::/collections/all-products|' | append: label_blockers | append: '::/collections/proteccion-solar-1|' | append: label_moisturizers | append: '::/collections/hidratantes|' | append: label_cleansers | append: '::/collections/limpiadores|' | append: label_masks | append: '::/collections/mascarillas|' | append: label_serums | append: '::/collections/serum'
assign routine_menu = label_clean | append: '::/collections/1-limpia|' | append: label_treat | append: '::/collections/2-trata|' | append: label_hydrate | append: '::/collections/3-hidrata|' | append: label_protect | append: '::/collections/4-protege-bloqueadores-solares|' | append: label_kits | append: '::/collections/kits-skincare-facial'
assign skin_menu = label_combination | append: '::/collections/piel-mixta-grasa|' | append: label_oily | append: '::/collections/piel-grasa|' | append: label_dry | append: '::/collections/piel-seca-1'
assign concern_menu = label_sun | append: '::/collections/proteccion-solar-1|' | append: label_oil | append: '::/collections/control-grasa|' | append: label_acne | append: '::/collections/acne-1|' | append: label_hydration | append: '::/collections/hidratacion|' | append: label_aging | append: '::/collections/antiedad-1|' | append: label_spots | append: '::/collections/aclarar'
%}
{% render 'header-menu-item', title: nav_categories, url: '/collections/all-products', child_menu: categories_menu, image_set: 'categories' %}
{% render 'header-menu-item', title: nav_routine, url: routes.collections_url, child_menu: routine_menu, image_set: 'routine' %}
{% render 'header-menu-item', title: nav_skin_type, url: routes.collections_url, child_menu: skin_menu, image_set: 'skin' %}
{% render 'header-menu-item', title: nav_concern, url: routes.collections_url, child_menu: concern_menu, image_set: 'concern' %}
{% endif %}
</ul>
<ul class="header__pills m-0 flex list-none items-center gap-[15px] p-0">
{% assign favorites_label = 'header.links.favorites' | t | downcase %}
{% if section.settings.pills_menu != blank and section.settings.pills_menu.links.size > 0 %}
{% for link in section.settings.pills_menu.links %}
{% liquid
assign pill_title = link.title | strip | downcase
assign pill_handle = link.title | handleize
assign open_wishlist = false
if pill_title == favorites_label
assign open_wishlist = true
endif
if pill_handle == 'los-favoritos' or pill_handle == 'tus-favoritos' or pill_handle == 'favoritos'
assign open_wishlist = true
endif
%}
<li>
{% if open_wishlist %}
<button
type="button"
class="inline-flex cursor-pointer appearance-none items-center justify-center rounded-full border border-solid border-black bg-transparent px-5 py-1 font-sans text-[14px] font-normal leading-none text-black focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-black"
data-wish-open
aria-controls="wish-drawer"
aria-expanded="false"
aria-haspopup="dialog"
>
{{ 'header.links.favorites' | t }}
</button>
{% else %}
<a
class="inline-flex items-center justify-center rounded-full border border-solid border-black px-5 py-1 text-[14px] font-normal leading-none text-black no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-black"
href="{{ link.url }}"
>
{{ link.title }}
</a>
{% endif %}
</li>
{% endfor %}
{% else %}
<li>
<a class="inline-flex items-center justify-center rounded-full border border-solid border-black px-5 py-1 text-[14px] font-normal leading-none text-black no-underline" href="/collections/proteccion-solar-1">
{{ 'header.links.sunscreen' | t }}
</a>
</li>
<li>
<button
type="button"
class="inline-flex cursor-pointer appearance-none items-center justify-center rounded-full border border-solid border-black bg-transparent px-5 py-1 font-sans text-[14px] font-normal leading-none text-black"
data-wish-open
aria-controls="wish-drawer"
aria-expanded="false"
aria-haspopup="dialog"
>
{{ 'header.links.favorites' | t }}
</button>
</li>
<li>
<a class="inline-flex items-center justify-center rounded-full border border-solid border-black px-5 py-1 text-[14px] font-normal leading-none text-black no-underline" href="/collections/kits-skincare-facial">
{{ 'header.links.kits' | t }}
</a>
</li>
<li>
<a class="inline-flex items-center justify-center rounded-full border border-solid border-black px-5 py-1 text-[14px] font-normal leading-none text-black no-underline" href="/collections/hidratantes">
{{ 'header.links.moisturizers' | t }}
</a>
</li>
{% endif %}
</ul>
</div>
</nav>
</div>
{% if promo_text != blank %}
{% liquid
assign promo_url = section.settings.promo_link
if promo_url == blank
if routes.root_url == '/'
assign promo_url = '/collections/all-products'
else
assign promo_url = routes.root_url | append: '/collections/all-products'
endif
endif
%}
<div class="header__promo flex h-[50px] items-center justify-center bg-brand-mint px-4 text-center">
<a class="text-[20px] font-bold uppercase leading-none text-black no-underline xl:text-[14px]" href="{{ promo_url }}">
{{ promo_text }}
</a>
</div>
{% endif %}
<button
type="button"
class="header__backdrop fixed inset-0 z-30 hidden cursor-pointer border-0 bg-black/40 p-0"
data-menu-backdrop
aria-label="{{ 'header.menu_close' | t }}"
tabindex="-1"
></button>
</header>
<div id="wish-drawer" class="wish-drawer" data-wish-drawer data-empty="{{ 'header.wishlist_empty' | t | escape }}" data-remove="{{ 'header.wishlist_remove' | t | escape }}" data-add="{{ 'header.wishlist_add' | t | escape }}" data-sold-out="{{ 'header.wishlist_sold_out' | t | escape }}" data-cart-add-url="{{ routes.cart_add_url }}.js" aria-hidden="true" inert>
<button class="wish-drawer__backdrop" type="button" data-wish-close tabindex="-1" aria-label="{{ 'header.wishlist_close' | t }}"></button>
<div class="wish-drawer__panel" role="dialog" aria-modal="true" aria-labelledby="wish-drawer-title">
<div class="wish-drawer__head">
<h2 id="wish-drawer-title" class="wish-drawer__title">{{ 'header.wishlist' | t }}</h2>
<button class="wish-drawer__close" type="button" data-wish-close aria-label="{{ 'header.wishlist_close' | t }}">
<svg width="14" height="14" viewBox="0 0 14 14" aria-hidden="true" focusable="false">
<path d="M2 2l10 10M12 2L2 12" fill="none" stroke="currentColor" stroke-width="1.4" stroke-linecap="round"/>
</svg>
</button>
</div>
<div class="wish-drawer__scroll">
<div class="wish-drawer__list" data-wish-list></div>
{%- liquid
assign wish_suggest = section.settings.wishlist_suggestions
if wish_suggest == blank
assign wish_suggest = collections['los-mas-vendidos']
endif
if wish_suggest == blank or wish_suggest.products_count == 0
assign wish_suggest = collections.all
endif
-%}
<div class="wish-drawer__suggest" data-wish-suggest hidden>
<p class="wish-drawer__suggest-title">{{ 'header.wishlist_suggest' | t }}</p>
<div class="wish-drawer__suggest-list">
{%- assign wish_shown = 0 -%}
{%- for sp in wish_suggest.products limit: 12 -%}
{%- if wish_shown >= 4 -%}{%- break -%}{%- endif -%}
{%- if sp.available -%}
{%- assign wish_shown = wish_shown | plus: 1 -%}
<article class="wish-drawer__item">
<a class="wish-drawer__thumb" href="{{ sp.url }}">
{%- if sp.featured_image -%}{{ sp.featured_image | image_url: width: 160 | image_tag: width: 72, height: 72, loading: 'lazy', alt: '' }}{%- endif -%}
</a>
<div>
<a class="wish-drawer__name" href="{{ sp.url }}">{{ sp.title }}</a>
<p class="wish-drawer__price">{{ sp.price | money_without_trailing_zeros }}</p>
</div>
<div class="wish-drawer__actions">
<button class="wish-drawer__add" type="button" data-wish-add="{{ sp.selected_or_first_available_variant.id }}">{{ 'header.wishlist_add' | t }}</button>
</div>
</article>
{%- endif -%}
{%- endfor -%}
</div>
<a class="wish-drawer__browse" href="{{ wish_suggest.url | default: routes.all_products_collection_url }}">{{ 'header.wishlist_browse' | t }}</a>
</div>
<div class="wish-drawer__foot" data-wish-foot hidden>
<button class="wish-drawer__add wish-drawer__add--all" type="button" data-wish-add-all>{{ 'header.wishlist_add_all' | t }}</button>
</div>
</div>
</div>
</div>
{% javascript %}
(() => {
if (window.__seasonHeader) return;
window.__seasonHeader = true;
const mobileQuery = window.matchMedia('(max-width: 1119px)');
const headerGroup = () => document.querySelector('.shopify-section-group-header-group');
const setHeaderOffset = () => {
const group = headerGroup();
if (!group) return;
const hidden = !mobileQuery.matches && group.classList.contains('is-header-hidden');
document.documentElement.style.setProperty('--header-offset', (hidden ? 0 : group.offsetHeight) + 'px');
};
setHeaderOffset();
window.addEventListener('resize', setHeaderOffset);
const header = document.querySelector('[data-header]');
const group = headerGroup();
if (header && group && !window.Shopify?.designMode) {
let lastY = window.scrollY;
let frame = 0;
const onScroll = () => {
frame = 0;
if (mobileQuery.matches) {
if (group.classList.contains('is-header-hidden')) {
group.classList.remove('is-header-hidden');
setHeaderOffset();
}
lastY = window.scrollY;
return;
}
if (header.classList.contains('is-menu-open') || header.querySelector('.header__search.is-open') || document.documentElement.classList.contains('wish-drawer-open')) {
group.classList.remove('is-header-hidden');
setHeaderOffset();
lastY = window.scrollY;
return;
}
const y = Math.max(0, window.scrollY);
const delta = y - lastY;
if (Math.abs(delta) < 8) return;
const hide = y > group.offsetHeight && delta > 0;
if (hide !== group.classList.contains('is-header-hidden')) {
group.classList.toggle('is-header-hidden', hide);
setHeaderOffset();
}
lastY = y;
};
window.addEventListener('scroll', () => {
if (frame) return;
frame = window.requestAnimationFrame(onScroll);
}, { passive: true });
}
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);
}
});
}
const syncSubmenuArrows = (list) => {
if (!(list instanceof HTMLElement)) return;
const item = list.closest('[data-menu-item]');
if (!item) return;
const prev = item.querySelector('[data-submenu-scroll="-1"]');
const next = item.querySelector('[data-submenu-scroll="1"]');
const max = Math.max(0, list.scrollWidth - list.clientWidth);
const overflow = mobileQuery.matches && item.classList.contains('is-open') && max > 8;
if (prev) prev.hidden = !overflow || list.scrollLeft <= 4;
if (next) next.hidden = !overflow || list.scrollLeft >= max - 4;
const media = list.querySelector('.header__card-media');
if (!overflow || !media) return;
const top = media.getBoundingClientRect().top - item.getBoundingClientRect().top + (media.getBoundingClientRect().height - 36) / 2;
item.querySelectorAll('[data-submenu-scroll]').forEach((control) => {
control.style.top = top + 'px';
});
};
menu?.querySelectorAll('.header__submenu--cards').forEach((list) => {
list.addEventListener('scroll', () => syncSubmenuArrows(list), { passive: true });
});
let arrowFrame = 0;
let arrowDelay = 0;
let arrowList = null;
let arrowDir = 0;
let arrowHolding = false;
let arrowTime = 0;
const stopSubmenuHold = () => {
window.clearTimeout(arrowDelay);
arrowDelay = 0;
arrowHolding = false;
arrowList = null;
if (arrowFrame) window.cancelAnimationFrame(arrowFrame);
arrowFrame = 0;
};
const holdSubmenu = (now) => {
if (!arrowHolding || !arrowList) return;
const delta = Math.min(40, now - arrowTime);
arrowTime = now;
const max = Math.max(0, arrowList.scrollWidth - arrowList.clientWidth);
arrowList.scrollLeft = Math.min(max, Math.max(0, arrowList.scrollLeft + arrowDir * (delta / 1000) * 420));
syncSubmenuArrows(arrowList);
const atEdge = arrowDir < 0 ? arrowList.scrollLeft <= 0 : arrowList.scrollLeft >= max - 1;
if (atEdge) {
stopSubmenuHold();
return;
}
arrowFrame = window.requestAnimationFrame(holdSubmenu);
};
const submenuCards = (list) => [...list.querySelectorAll('.header__card')];
const submenuIndex = (list) => {
const cards = submenuCards(list);
const mid = list.getBoundingClientRect().left + list.clientWidth / 2;
let index = 0;
let best = Infinity;
cards.forEach((card, cardIndex) => {
const rect = card.getBoundingClientRect();
const distance = Math.abs(rect.left + rect.width / 2 - mid);
if (distance < best) {
best = distance;
index = cardIndex;
}
});
return index;
};
const scrollToSubmenuCard = (list, index) => {
const cards = submenuCards(list);
const card = cards[Math.max(0, Math.min(cards.length - 1, index))];
if (!card) return;
const listRect = list.getBoundingClientRect();
const cardRect = card.getBoundingClientRect();
const delta = cardRect.left + cardRect.width / 2 - (listRect.left + listRect.width / 2);
list.scrollTo({ left: list.scrollLeft + delta, behavior: 'smooth' });
};
const stepSubmenu = (list, dir) => {
scrollToSubmenuCard(list, submenuIndex(list) + dir);
};
menu?.addEventListener('pointerdown', (event) => {
const button = event.target.closest('[data-submenu-scroll]');
if (!button || !mobileQuery.matches) return;
const list = button.closest('[data-menu-item]')?.querySelector('.header__submenu--cards');
if (!list) return;
event.preventDefault();
event.stopPropagation();
stopSubmenuHold();
arrowList = list;
arrowDir = Number(button.dataset.submenuScroll);
try {
if (button.setPointerCapture) button.setPointerCapture(event.pointerId);
} catch (error) {}
arrowDelay = window.setTimeout(() => {
arrowHolding = true;
arrowTime = window.performance.now();
arrowFrame = window.requestAnimationFrame(holdSubmenu);
}, 200);
});
const finishSubmenuPointer = () => {
if (!arrowList) return;
const list = arrowList;
const dir = arrowDir;
const wasHolding = arrowHolding;
stopSubmenuHold();
if (wasHolding) scrollToSubmenuCard(list, submenuIndex(list));
else stepSubmenu(list, dir);
};
menu?.addEventListener('pointerup', finishSubmenuPointer);
menu?.addEventListener('pointercancel', stopSubmenuHold);
menu?.addEventListener('click', (event) => {
if (!event.target.closest('[data-submenu-scroll]')) return;
event.preventDefault();
event.stopPropagation();
});
window.addEventListener('resize', () => {
menu?.querySelectorAll('.header__submenu--cards').forEach(syncSubmenuArrows);
});
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');
window.requestAnimationFrame(() => {
menu.querySelectorAll('.header__submenu--cards').forEach(syncSubmenuArrows);
});
};
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);
const suggest = wishDrawer?.querySelector('[data-wish-suggest]');
const foot = wishDrawer?.querySelector('[data-wish-foot]');
const showEmpty = () => {
wishList.replaceChildren();
const empty = document.createElement('p');
empty.className = 'wish-drawer__empty';
empty.textContent = wishDrawer?.dataset.empty || '';
wishList.append(empty);
if (suggest) suggest.hidden = false;
if (foot) foot.hidden = true;
};
if (!items.length) {
showEmpty();
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) {
showEmpty();
return;
}
if (suggest) suggest.hidden = true;
const buyable = found.filter((product) => (product.variants || []).some((variant) => variant.available));
if (foot) foot.hidden = buyable.length < 2;
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 || '';
const actions = document.createElement('div');
actions.className = 'wish-drawer__actions';
const variant = (product.variants || []).find((v) => v.available);
const add = document.createElement('button');
add.className = 'wish-drawer__add';
add.type = 'button';
if (variant) {
add.dataset.wishAdd = String(variant.id);
add.textContent = wishDrawer?.dataset.add || 'Agregar';
} else {
add.disabled = true;
add.textContent = wishDrawer?.dataset.soldOut || 'Agotado';
}
actions.append(add, remove);
row.append(link, copy, actions);
wishList.append(row);
});
};
const addWishToCart = async (ids, button) => {
if (!ids.length || !button || button.disabled) return;
button.disabled = true;
button.classList.add('is-busy');
try {
const response = await fetch(wishDrawer?.dataset.cartAddUrl || '/cart/add.js', {
method: 'POST',
headers: { 'Content-Type': 'application/json', Accept: 'application/json' },
body: JSON.stringify({ items: ids.map((id) => ({ id: Number(id), quantity: 1 })) }),
});
if (!response.ok) throw new Error('add failed');
setWishOpen(false);
document.dispatchEvent(new CustomEvent('season:cart:open'));
} catch (error) {
button.classList.add('is-error');
window.setTimeout(() => button.classList.remove('is-error'), 1500);
} finally {
button.disabled = false;
button.classList.remove('is-busy');
}
};
const setWishOpen = (open) => {
if (!wishDrawer || !wishButton) return;
if (open && wishDrawer.parentElement !== document.body) document.body.appendChild(wishDrawer);
wishDrawer.classList.toggle('is-open', open);
wishDrawer.setAttribute('aria-hidden', open ? 'false' : 'true');
wishDrawer.inert = !open;
document.querySelectorAll('[data-wish-open]').forEach((control) => {
control.setAttribute('aria-expanded', open ? 'true' : 'false');
});
document.documentElement.classList.toggle('wish-drawer-open', open);
if (open) {
document.querySelector('.shopify-section-group-header-group')?.classList.remove('is-header-hidden');
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 addOne = event.target.closest('[data-wish-add]');
const addAll = event.target.closest('[data-wish-add-all]');
if (addOne || addAll) {
const ids = addAll
? [...(wishDrawer?.querySelectorAll('[data-wish-list] [data-wish-add]') || [])].map((b) => b.dataset.wishAdd)
: [addOne.dataset.wishAdd];
addWishToCart(ids.filter(Boolean), addOne || addAll);
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": "CUIDARTE ES CELEBRARTE"
},
{
"type": "url",
"id": "promo_link",
"label": "t:header.promo_link"
},
{
"type": "collection",
"id": "wishlist_suggestions",
"label": "Sugerencias en Favoritos vacío",
"info": "Por defecto: Los más vendidos."
}
]
}
{% endschema %}