Ajustes antes de produccion
This commit is contained in:
@@ -21,7 +21,11 @@
|
||||
endif
|
||||
endif
|
||||
|
||||
if section.settings.promo_link != blank
|
||||
assign promo_href = section.settings.promo_link
|
||||
if promo_href == blank
|
||||
assign promo_href = more_url
|
||||
endif
|
||||
if promo_href != blank
|
||||
assign promo_tag = 'a'
|
||||
else
|
||||
assign promo_tag = 'div'
|
||||
@@ -71,7 +75,7 @@
|
||||
<{{ promo_tag }}
|
||||
class="bestsellers__promo"
|
||||
{% if promo_tag == 'a' %}
|
||||
href="{{ section.settings.promo_link }}"
|
||||
href="{{ promo_href }}"
|
||||
{% endif %}
|
||||
>
|
||||
{% if section.settings.promo_image != blank %}
|
||||
@@ -103,11 +107,19 @@
|
||||
<div class="bestsellers__slider">
|
||||
<div class="bestsellers__viewport" data-viewport tabindex="0">
|
||||
<div class="bestsellers__track" data-track>
|
||||
{% assign shown = 0 %}
|
||||
{% if product_collection != blank and product_collection.products_count > 0 %}
|
||||
{% for product in product_collection.products limit: products_to_show %}
|
||||
{% render 'bestsellers-card', product: product, form_suffix: section.id %}
|
||||
{% for product in product_collection.products %}
|
||||
{% if product.available %}
|
||||
{% render 'bestsellers-card', product: product, form_suffix: section.id %}
|
||||
{% assign shown = shown | plus: 1 %}
|
||||
{% endif %}
|
||||
{% if shown >= products_to_show %}
|
||||
{% break %}
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% elsif request.design_mode %}
|
||||
{% endif %}
|
||||
{% if shown == 0 and request.design_mode %}
|
||||
<p class="bestsellers__empty">{{ 'bestsellers.empty' | t }}</p>
|
||||
{% endif %}
|
||||
</div>
|
||||
@@ -164,7 +176,8 @@
|
||||
}
|
||||
|
||||
badge.textContent = String(count);
|
||||
link.setAttribute('aria-label', link.getAttribute('aria-label').replace(/\d+/, String(count)));
|
||||
const label = link.getAttribute('aria-label');
|
||||
if (label) link.setAttribute('aria-label', label.replace(/\d+/, String(count)));
|
||||
};
|
||||
|
||||
const updateArrows = (root) => {
|
||||
@@ -201,6 +214,28 @@
|
||||
root._bestsellersTimer = null;
|
||||
};
|
||||
|
||||
const mobileSlider = () => window.matchMedia('(max-width: 767px)').matches;
|
||||
|
||||
const slideStride = (viewport) => {
|
||||
const card = viewport.querySelector('.bestsellers__card');
|
||||
if (!card) return 0;
|
||||
const track = viewport.querySelector('[data-track]');
|
||||
const gap = track ? parseFloat(window.getComputedStyle(track).columnGap) || 0 : 0;
|
||||
return card.getBoundingClientRect().width + gap;
|
||||
};
|
||||
|
||||
const centerSlide = (viewport, index, behavior) => {
|
||||
const stride = slideStride(viewport);
|
||||
const count = viewport.querySelectorAll('.bestsellers__card').length;
|
||||
if (!stride || !count) return;
|
||||
const wrapped = ((index % count) + count) % count;
|
||||
const max = viewport.scrollWidth - viewport.clientWidth;
|
||||
viewport.scrollTo({
|
||||
left: Math.min(Math.max(wrapped * stride, 0), max),
|
||||
behavior,
|
||||
});
|
||||
};
|
||||
|
||||
const startAutoplay = (root) => {
|
||||
pauseAutoplay(root);
|
||||
if (reduceMotion.matches || root.dataset.paused === 'true') return;
|
||||
@@ -211,6 +246,16 @@
|
||||
const max = viewport.scrollWidth - viewport.clientWidth;
|
||||
if (max <= 2) return;
|
||||
|
||||
if (mobileSlider()) {
|
||||
const stride = slideStride(viewport);
|
||||
const count = viewport.querySelectorAll('.bestsellers__card').length;
|
||||
if (!stride || count < 2) return;
|
||||
const index = Math.round(viewport.scrollLeft / stride);
|
||||
const reduce = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
|
||||
centerSlide(viewport, index + 1 >= count ? 0 : index + 1, reduce ? 'auto' : 'smooth');
|
||||
return;
|
||||
}
|
||||
|
||||
if (viewport.scrollLeft >= max - 2) {
|
||||
viewport.scrollTo({ left: 0, behavior: 'smooth' });
|
||||
return;
|
||||
@@ -248,7 +293,10 @@
|
||||
const html = await response.text();
|
||||
const parsed = new DOMParser().parseFromString(html, 'text/html');
|
||||
const limit = Number(root.dataset.limit) || 8;
|
||||
const cards = Array.from(parsed.querySelectorAll('.bestsellers__card')).slice(0, limit);
|
||||
const cards = Array.from(parsed.querySelectorAll('.bestsellers__card')).filter((card) => {
|
||||
const button = card.querySelector('button[type="submit"]');
|
||||
return !button || !button.disabled;
|
||||
}).slice(0, limit);
|
||||
const track = root.querySelector('[data-track]');
|
||||
if (!track || !cards.length) {
|
||||
root.dataset.sorted = 'true';
|
||||
@@ -257,6 +305,8 @@
|
||||
|
||||
track.replaceChildren(...cards.map((card) => document.importNode(card, true)));
|
||||
applyWishlist(root);
|
||||
const loadedViewport = root.querySelector('[data-viewport]');
|
||||
if (loadedViewport && mobileSlider()) centerSlide(loadedViewport, 0, 'auto');
|
||||
updateArrows(root);
|
||||
root.dataset.sorted = 'true';
|
||||
startAutoplay(root);
|
||||
@@ -273,9 +323,17 @@
|
||||
if (!viewport) return;
|
||||
|
||||
applyWishlist(root);
|
||||
if (mobileSlider()) centerSlide(viewport, 0, 'auto');
|
||||
updateArrows(root);
|
||||
viewport.addEventListener('scroll', () => updateArrows(root), { passive: true });
|
||||
window.addEventListener('resize', () => updateArrows(root));
|
||||
window.addEventListener('resize', () => {
|
||||
if (mobileSlider()) {
|
||||
const stride = slideStride(viewport);
|
||||
const index = stride ? Math.round(viewport.scrollLeft / stride) : 0;
|
||||
centerSlide(viewport, index, 'auto');
|
||||
}
|
||||
updateArrows(root);
|
||||
});
|
||||
|
||||
root.addEventListener('mouseenter', () => {
|
||||
root.dataset.paused = 'true';
|
||||
@@ -369,6 +427,7 @@
|
||||
});
|
||||
|
||||
document.addEventListener('submit', async (event) => {
|
||||
if (event.defaultPrevented) return;
|
||||
const form = event.target;
|
||||
if (!(form instanceof HTMLFormElement) || !form.classList.contains('bestsellers__form')) return;
|
||||
|
||||
@@ -409,10 +468,10 @@
|
||||
return;
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent('season:cart:open'));
|
||||
const cartResponse = await fetch(root.dataset.cartUrl, { headers: { Accept: 'application/json' } });
|
||||
const cart = await cartResponse.json();
|
||||
if (typeof cart.item_count === 'number') setCartCount(cart.item_count);
|
||||
document.dispatchEvent(new CustomEvent('season:cart:open'));
|
||||
} catch (error) {
|
||||
form.submit();
|
||||
} finally {
|
||||
|
||||
Reference in New Issue
Block a user