Files
2026-10-09 23:02:05 -06:00

791 lines
33 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'
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"
>
{{ link.title }}
</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 %}
<div class="header__promo flex h-[50px] items-center justify-center bg-brand-mint px-4 text-center">
{% if section.settings.promo_link != blank %}
<a class="text-[20px] font-bold uppercase leading-none text-black no-underline xl:text-[14px]" href="{{ section.settings.promo_link }}">
{{ promo_text }}
</a>
{% else %}
<p class="m-0 text-[20px] font-bold uppercase leading-none xl:text-[14px]">
{{ promo_text }}
</p>
{% endif %}
</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 }}" aria-hidden="true">
<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__list" data-wish-list></div>
</div>
</div>
{% 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 %}