Ajustes antes de produccion
This commit is contained in:
+296
-22
@@ -239,7 +239,7 @@
|
||||
if pill_title == favorites_label
|
||||
assign open_wishlist = true
|
||||
endif
|
||||
if pill_handle == 'los-favoritos'
|
||||
if pill_handle == 'los-favoritos' or pill_handle == 'tus-favoritos' or pill_handle == 'favoritos'
|
||||
assign open_wishlist = true
|
||||
endif
|
||||
%}
|
||||
@@ -253,7 +253,7 @@
|
||||
aria-expanded="false"
|
||||
aria-haspopup="dialog"
|
||||
>
|
||||
{{ link.title }}
|
||||
{{ 'header.links.favorites' | t }}
|
||||
</button>
|
||||
{% else %}
|
||||
<a
|
||||
@@ -300,16 +300,20 @@
|
||||
</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">
|
||||
{% 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 %}
|
||||
<a class="text-[20px] font-bold uppercase leading-none text-black no-underline xl:text-[14px]" href="{{ promo_url }}">
|
||||
{{ promo_text }}
|
||||
</a>
|
||||
</div>
|
||||
{% endif %}
|
||||
|
||||
@@ -322,7 +326,7 @@
|
||||
></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">
|
||||
<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">
|
||||
@@ -333,7 +337,46 @@
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<div class="wish-drawer__list" data-wish-list></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>
|
||||
|
||||
@@ -346,15 +389,55 @@
|
||||
|
||||
const mobileQuery = window.matchMedia('(max-width: 1119px)');
|
||||
|
||||
const headerGroup = () => document.querySelector('.shopify-section-group-header-group');
|
||||
|
||||
const setHeaderOffset = () => {
|
||||
const group = document.querySelector('.shopify-section-group-header-group');
|
||||
const group = headerGroup();
|
||||
if (!group) return;
|
||||
document.documentElement.style.setProperty('--header-offset', group.offsetHeight + 'px');
|
||||
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]');
|
||||
@@ -508,6 +591,133 @@
|
||||
});
|
||||
}
|
||||
|
||||
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) => {
|
||||
@@ -520,6 +730,9 @@
|
||||
});
|
||||
item.classList.toggle('is-open', !expanded);
|
||||
submenuToggle.setAttribute('aria-expanded', expanded ? 'false' : 'true');
|
||||
window.requestAnimationFrame(() => {
|
||||
menu.querySelectorAll('.header__submenu--cards').forEach(syncSubmenuArrows);
|
||||
});
|
||||
};
|
||||
|
||||
if (submenuToggle) {
|
||||
@@ -634,12 +847,19 @@
|
||||
if (!wishList) return;
|
||||
const request = ++wishRequest;
|
||||
const items = readWishItems().filter((item) => item.handle);
|
||||
if (!items.length) {
|
||||
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) => {
|
||||
@@ -657,12 +877,12 @@
|
||||
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);
|
||||
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';
|
||||
@@ -693,20 +913,59 @@
|
||||
remove.type = 'button';
|
||||
remove.dataset.wishRemove = product._wishId;
|
||||
remove.textContent = wishDrawer?.dataset.remove || '';
|
||||
row.append(link, copy, 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('overflow-hidden', open);
|
||||
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);
|
||||
@@ -735,6 +994,15 @@
|
||||
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;
|
||||
@@ -784,6 +1052,12 @@
|
||||
"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."
|
||||
}
|
||||
]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user