{% liquid if section.settings.heading != blank assign heading = section.settings.heading else assign heading = 'learn.heading' | t endif if section.settings.subheading != blank assign subheading = section.settings.subheading else assign subheading = 'learn.subheading' | t endif assign slide_count = section.blocks.size assign active_index = slide_count | minus: 1 | divided_by: 2 | floor if active_index < 0 assign active_index = 0 endif %}

{{ heading | escape }}

{{ subheading | escape }}

{% for block in section.blocks %} {% liquid assign video_src = blank if block.settings.video != blank for source in block.settings.video.sources if source.mime_type == 'video/mp4' or source.format == 'mp4' assign video_src = source.url endif endfor endif if video_src == blank and forloop.index <= 5 assign reel_name = forloop.index | append: '-reel-ig.mp4' assign video_src = reel_name | asset_url endif assign fallback_image = blank case forloop.index when 1 assign fallback_image = 'video-11.png' when 2 assign fallback_image = 'video-22.png' when 3 assign fallback_image = 'learn-reel-3.avif' when 4 assign fallback_image = 'video-44.png' when 5 assign fallback_image = 'video-55.png' endcase assign poster_alt = heading assign slide_state = '' if forloop.index0 == active_index assign slide_state = ' is-active' endif %}
{% if block.settings.poster != blank %} {{ block.settings.poster | image_url: width: 900 | image_tag: alt: poster_alt, widths: '384, 768', sizes: '384px', class: 'learn__poster', loading: 'lazy' }} {% elsif fallback_image != blank %} {{ poster_alt | escape }} {% endif %} {% if video_src != blank %} {% endif %}
{% endfor %}
{% for block in section.blocks %}
{% for product_key in (1..2) %} {% liquid if product_key == 1 assign slide_product = block.settings.product_1 else assign slide_product = block.settings.product_2 endif %} {% if slide_product != blank and slide_product.available %} {% liquid assign variant = slide_product.selected_or_first_available_variant assign card_image = slide_product.featured_image assign hover_image = blank for image in slide_product.images offset: 1 limit: 1 assign hover_image = image endfor %} {% endif %} {% endfor %}
{% endfor %}
{% javascript %} (() => { const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches; const setCartCount = (count) => { const link = document.querySelector('.header__cart'); if (!link || count < 1) return; let badge = link.querySelector('[data-cart-count]'); if (!badge) { badge = document.createElement('span'); badge.className = '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'; badge.setAttribute('data-cart-count', ''); link.appendChild(badge); } badge.textContent = String(count); }; const playSlide = (slide) => { const video = slide.querySelector('[data-learn-video]'); if (!video) return; const root = slide.closest('[data-learn]'); const soundOn = root && root.dataset.sound === 'on'; if (reduceMotion && !soundOn) return; // Only download/play once the section is on screen (or the visitor asked for sound). if (!soundOn && root && root.dataset.inview !== '1') return; video.muted = !soundOn; if (video.dataset.loaded !== 'true' && video.dataset.src) { video.dataset.loaded = 'true'; if (video.getAttribute('src') !== video.dataset.src) { video.src = video.dataset.src; video.load(); } } const mark = () => slide.classList.add('is-playing'); if (!video.paused && video.currentTime > 0) mark(); video.addEventListener('playing', mark, { once: true }); const attempt = video.play(); if (attempt && typeof attempt.catch === 'function') attempt.catch(() => {}); }; const stopSlide = (slide) => { const video = slide.querySelector('[data-learn-video]'); slide.classList.remove('is-playing'); slide.classList.remove('is-paused'); if (video && video.dataset.loaded === 'true') video.pause(); }; const boot = (root) => { if (!root || root.dataset.ready === 'true') return; const viewport = root.querySelector('[data-viewport]'); const slides = [...root.querySelectorAll('[data-slide]')]; const rows = [...root.querySelectorAll('[data-product-row]')]; const progress = root.querySelector('[data-progress]'); const bar = root.querySelector('[data-progress-bar]'); const prev = root.querySelector('[data-learn-prev]'); const next = root.querySelector('[data-learn-next]'); if (!viewport || !slides.length) return; root.dataset.ready = 'true'; let index = Number(root.dataset.active) || 0; if (index < 0) index = 0; if (index > slides.length - 1) index = slides.length - 1; const paint = (animate) => { slides.forEach((slide, i) => { const active = i === index; slide.classList.toggle('is-active', active); if (active) playSlide(slide); else stopSlide(slide); }); rows.forEach((row, i) => { row.hidden = i !== index; }); if (bar) { const width = 100 / slides.length; const travel = 100 - width; bar.style.width = `${width}%`; bar.style.left = `${slides.length < 2 ? 0 : (index / (slides.length - 1)) * travel}%`; } if (prev) prev.disabled = index === 0; if (next) next.disabled = index === slides.length - 1; if (progress) { progress.setAttribute('aria-valuemax', String(slides.length)); progress.setAttribute('aria-valuenow', String(index + 1)); } const slide = slides[index]; const left = slide.offsetLeft - (viewport.clientWidth - slide.offsetWidth) / 2; viewport.scrollTo({ left: Math.max(left, 0), behavior: animate && !reduceMotion ? 'smooth' : 'auto' }); }; const go = (nextIndex) => { const target = Math.min(Math.max(nextIndex, 0), slides.length - 1); if (target === index) return; index = target; paint(true); }; root.__learnGo = go; prev?.addEventListener('click', () => go(index - 1)); next?.addEventListener('click', () => go(index + 1)); let pointerId = null; let startX = 0; let startScroll = 0; let moved = false; viewport.addEventListener('pointerdown', (event) => { if (event.button !== 0) return; if (event.target.closest('a, button')) return; pointerId = event.pointerId; startX = event.clientX; startScroll = viewport.scrollLeft; moved = false; viewport.classList.add('is-dragging'); viewport.setPointerCapture(pointerId); }); viewport.addEventListener('pointermove', (event) => { if (event.pointerId !== pointerId) return; const delta = event.clientX - startX; if (Math.abs(delta) > 4) moved = true; viewport.scrollLeft = startScroll - delta; }); const endDrag = (event) => { if (event.pointerId !== pointerId) return; pointerId = null; viewport.classList.remove('is-dragging'); if (!moved) return; const center = viewport.scrollLeft + viewport.clientWidth / 2; let nearest = index; let best = Infinity; slides.forEach((slide, i) => { const mid = slide.offsetLeft + slide.offsetWidth / 2; const distance = Math.abs(mid - center); if (distance < best) { best = distance; nearest = i; } }); index = nearest; paint(true); viewport.addEventListener('click', (clickEvent) => { clickEvent.preventDefault(); clickEvent.stopPropagation(); }, { capture: true, once: true }); }; viewport.addEventListener('pointerup', endDrag); viewport.addEventListener('pointercancel', endDrag); const indexFromClientX = (clientX) => { if (!progress || slides.length < 2) return 0; const rect = progress.getBoundingClientRect(); const ratio = Math.min(Math.max((clientX - rect.left) / rect.width, 0), 1); return Math.round(ratio * (slides.length - 1)); }; if (progress) { let progressPointer = null; progress.addEventListener('pointerdown', (event) => { if (event.button !== 0) return; progressPointer = event.pointerId; progress.setPointerCapture(progressPointer); go(indexFromClientX(event.clientX)); }); progress.addEventListener('pointermove', (event) => { if (event.pointerId !== progressPointer) return; go(indexFromClientX(event.clientX)); }); const endProgress = (event) => { if (event.pointerId !== progressPointer) return; progressPointer = null; }; progress.addEventListener('pointerup', endProgress); progress.addEventListener('pointercancel', endProgress); progress.addEventListener('keydown', (event) => { if (event.key === 'ArrowRight') go(index + 1); if (event.key === 'ArrowLeft') go(index - 1); }); } window.addEventListener('resize', () => paint(false)); if (root.dataset.pending) { index = Math.min(Math.max(Number(root.dataset.pending) || 0, 0), slides.length - 1); delete root.dataset.pending; } paint(false); }; document.querySelectorAll('[data-learn]').forEach(boot); document.addEventListener('shopify:section:load', (event) => { const root = event.target.querySelector('[data-learn]'); if (root) { delete root.dataset.ready; boot(root); } }); if (!window.__seasonLearn) { window.__seasonLearn = true; document.addEventListener('submit', async (event) => { if (event.defaultPrevented) return; const form = event.target; if (!(form instanceof HTMLFormElement) || !form.classList.contains('learn__form')) return; const root = form.closest('[data-learn]'); if (!root) return; event.preventDefault(); const button = form.querySelector('[type="submit"]'); const variantId = form.querySelector('[name="id"]')?.value; if (!button || button.disabled || !variantId) return; button.disabled = true; try { const addResponse = await fetch(root.dataset.cartAddUrl, { method: 'POST', headers: { 'Content-Type': 'application/json', Accept: 'application/json', }, body: JSON.stringify({ id: variantId, quantity: 1 }), }); if (!addResponse.ok) { form.submit(); return; } 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 { button.disabled = false; } }); } })(); {% endjavascript %} {% schema %} { "name": "t:learn.name", "tag": "section", "class": "learn-section", "disabled_on": { "groups": ["header", "footer"] }, "settings": [ { "type": "text", "id": "heading", "label": "t:learn.heading", "default": "Aprende, aplica y brilla con Seasons" }, { "type": "text", "id": "subheading", "label": "t:learn.subheading", "default": "Descubre tips, rutinas y formas reales de usar tus productos favoritos." } ], "blocks": [ { "type": "clip", "name": "t:learn.clip", "settings": [ { "type": "image_picker", "id": "poster", "label": "t:learn.poster", "info": "t:learn.poster_info" }, { "type": "video", "id": "video", "label": "t:learn.video", "info": "t:learn.video_info" }, { "type": "product", "id": "product_1", "label": "t:learn.product_1" }, { "type": "product", "id": "product_2", "label": "t:learn.product_2" } ] } ], "presets": [ { "name": "t:learn.name", "blocks": [ { "type": "clip" }, { "type": "clip" }, { "type": "clip" }, { "type": "clip" }, { "type": "clip" } ] } ] } {% endschema %}