Files
2026-10-22 22:33:56 -06:00

633 lines
20 KiB
Plaintext

{% liquid
assign media_type = section.settings.media_type | default: 'video'
if section.settings.cover_desktop != blank
assign cover_desktop = section.settings.cover_desktop | image_url: width: 2400
else
assign cover_desktop = 'mascara-video.avif' | asset_url
endif
if section.settings.cover_mobile != blank
assign cover_mobile = section.settings.cover_mobile | image_url: width: 1200
else
assign cover_mobile = 'mascara-vido-mobile.avif' | asset_url
endif
comment
Video hero: use the video's own first frame as the cover (LCP image). It is tiny
(AVIF ~20 KB desktop / ~8 KB mobile) and identical to frame 0, so the switch to video is seamless.
endcomment
assign cover_w = 1920
assign cover_h = 650
if media_type == 'video' and section.settings.poster_from_video
comment
Shopify's video preview image is frame 0 of the video, served as AVIF/WebP by the CDN.
endcomment
if section.settings.video.preview_image
assign cover_desktop = section.settings.video.preview_image | image_url: width: 1280
assign cover_w = section.settings.video.preview_image.width | at_most: 1280
assign cover_h = section.settings.video.preview_image.height | times: cover_w | divided_by: section.settings.video.preview_image.width
else
assign cover_desktop = 'hero-frame-desktop.avif' | asset_url
assign cover_w = 1280
assign cover_h = 720
endif
if section.settings.video_mobile.preview_image
assign cover_mobile = section.settings.video_mobile.preview_image | image_url: width: 720
elsif section.settings.use_light_mobile_video
assign cover_mobile = 'hero-frame-mobile.avif' | asset_url
elsif section.settings.video.preview_image
assign cover_mobile = section.settings.video.preview_image | image_url: width: 900
else
assign cover_mobile = cover_desktop
endif
endif
assign video_src = blank
assign video_src_mobile = blank
if media_type == 'video'
if section.settings.video != blank
comment
Desktop: the largest MP4 up to 1080p. Mobile: the smallest MP4 that is at least 480p.
endcomment
assign best_h = 0
assign mobile_h = 99999
for source in section.settings.video.sources
if source.mime_type == 'video/mp4' or source.format == 'mp4'
assign h = source.height | default: 0
if h <= 1080 and h >= best_h
assign best_h = h
assign video_src = source.url
endif
if h >= 480 and h < mobile_h
assign mobile_h = h
assign video_src_mobile = source.url
endif
endif
endfor
endif
if video_src == blank
assign video_src = 'home-video-op.mp4' | asset_url
endif
comment
Mobile: a dedicated vertical, light video (setting) or the theme's hero-mobile.mp4 (~450 KB, cropped 516x720).
endcomment
if section.settings.video_mobile != blank
assign mobile_h = 99999
for source in section.settings.video_mobile.sources
if source.mime_type == 'video/mp4' or source.format == 'mp4'
assign h = source.height | default: 0
if h >= 480 and h < mobile_h
assign mobile_h = h
assign video_src_mobile = source.url
endif
endif
endfor
elsif section.settings.use_light_mobile_video
assign video_src_mobile = 'hero-mobile.mp4' | asset_url
endif
comment
Theme-hosted optimized videos (no Shopify re-encoding: ~1 MB desktop / ~0.4 MB mobile)
plus their first frames as the cover. These files must match the videos picked above.
endcomment
if section.settings.theme_hosted_videos
assign video_src = 'seasons-hero-desktop.mp4' | asset_url
assign video_src_mobile = 'seasons-hero-mobile.mp4' | asset_url
if section.settings.poster_from_video
assign cover_desktop = 'hero-frame-desktop.avif' | asset_url
assign cover_mobile = 'hero-frame-mobile.avif' | asset_url
assign cover_w = 1280
assign cover_h = 720
endif
endif
endif
if section.settings.social_label != blank
assign social_label = section.settings.social_label
else
assign social_label = 'hero.follow' | t
endif
if section.settings.featured_label != blank
assign featured_label = section.settings.featured_label
else
assign featured_label = 'hero.featured_label' | t
endif
assign fallback_product = blank
for catalog_product in collections.all.products
if catalog_product.available
assign fallback_product = catalog_product
break
endif
endfor
assign show_products = false
if section.blocks.size > 0
if fallback_product != blank or request.design_mode
assign show_products = true
endif
endif
for block in section.blocks
if block.settings.product != blank
assign show_products = true
endif
endfor
assign line_1_weight = section.settings.heading_line_1_weight | default: 'light'
assign line_2_weight = section.settings.heading_line_2_weight | default: 'medium'
assign line_3_weight = section.settings.heading_line_3_weight | default: 'light'
%}
<section
class="hero full-width"
data-hero
data-cart-add-url="{{ routes.cart_add_url }}.js"
data-cart-url="{{ routes.cart_url }}.js"
>
<div class="hero__media" aria-hidden="true">
{% if media_type == 'image' %}
<picture class="hero__still">
<source media="(max-width: 1023px)" srcset="{{ cover_mobile }}">
<img
class="hero__poster-image"
src="{{ cover_desktop }}"
alt=""
width="1920"
height="650"
fetchpriority="high"
>
</picture>
{% else %}
<video
class="hero__video"
data-hero-video
data-src-desktop="{{ video_src }}"
data-src-mobile="{{ video_src_mobile | default: video_src }}"
muted
loop
playsinline
preload="none"
>
</video>
<picture class="hero__poster">
<source media="(max-width: 1023px)" srcset="{{ cover_mobile }}">
<img
class="hero__poster-image"
src="{{ cover_desktop }}"
alt=""
width="{{ cover_w }}"
height="{{ cover_h }}"
fetchpriority="high"
decoding="sync"
>
</picture>
{% endif %}
</div>
<div class="hero__content">
<div class="hero__copy">
{% if section.settings.heading_line_1 != blank or section.settings.heading_line_2 != blank or section.settings.heading_line_3 != blank %}
<h1 class="hero__title">
{% if section.settings.heading_line_1 != blank %}
<span class="hero__title-line hero__title-line--{{ line_1_weight }}">{{ section.settings.heading_line_1 | escape }}</span>
{% endif %}
{% if section.settings.heading_line_2 != blank %}
<span class="hero__title-line hero__title-line--{{ line_2_weight }}">{{ section.settings.heading_line_2 | escape }}</span>
{% endif %}
{% if section.settings.heading_line_3 != blank %}
<span class="hero__title-line hero__title-line--{{ line_3_weight }}">{{ section.settings.heading_line_3 | escape }}</span>
{% endif %}
</h1>
<span class="hero__rule" aria-hidden="true"></span>
{% endif %}
{% if show_products %}
<p class="hero__label">{{ featured_label | escape }}</p>
<div class="hero__products">
{% for block in section.blocks %}
{% liquid
assign featured_product = block.settings.product
if featured_product != blank
unless featured_product.available
assign featured_product = blank
endunless
endif
if featured_product == blank and forloop.first
assign featured_product = fallback_product
endif
%}
{% if featured_product != blank %}
<div class="hero__product" {{ block.shopify_attributes }}>
{% render 'hero-product', product: featured_product %}
</div>
{% elsif request.design_mode %}
<div class="hero__product" {{ block.shopify_attributes }}>
<div class="hero__card hero__card--empty">
<p>{{ 'hero.select_product' | t }}</p>
</div>
</div>
{% endif %}
{% endfor %}
</div>
{% endif %}
</div>
</div>
<aside class="hero__social">
<p class="hero__social-label">{{ social_label | escape }}</p>
<span class="hero__social-line" aria-hidden="true"></span>
<ul class="hero__social-list">
<li>
{% if section.settings.instagram_url != blank %}
<a class="hero__social-item" href="{{ section.settings.instagram_url }}" target="_blank" rel="noopener" aria-label="{{ 'hero.instagram' | t }}">
{{ 'icon-instagram.svg' | inline_asset_content }}
</a>
{% else %}
<span class="hero__social-item" aria-hidden="true">
{{ 'icon-instagram.svg' | inline_asset_content }}
</span>
{% endif %}
</li>
<li>
{% if section.settings.facebook_url != blank %}
<a class="hero__social-item" href="{{ section.settings.facebook_url }}" target="_blank" rel="noopener" aria-label="{{ 'hero.facebook' | t }}">
{{ 'icon-facebook.svg' | inline_asset_content }}
</a>
{% else %}
<span class="hero__social-item" aria-hidden="true">
{{ 'icon-facebook.svg' | inline_asset_content }}
</span>
{% endif %}
</li>
<li>
{% if section.settings.linkedin_url != blank %}
<a class="hero__social-item" href="{{ section.settings.linkedin_url }}" target="_blank" rel="noopener" aria-label="{{ 'hero.linkedin' | t }}">
{{ 'icon-linkedin.svg' | inline_asset_content }}
</a>
{% else %}
<span class="hero__social-item" aria-hidden="true">
{{ 'icon-linkedin.svg' | inline_asset_content }}
</span>
{% endif %}
</li>
</ul>
</aside>
</section>
<script nolazy>
(() => {
if (window.__seasonHeroVideo) return;
window.__seasonHeroVideo = true;
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) return;
// The cover (first frame of the video) is the LCP image. Once the page has loaded we
// start buffering the video, and it starts playing 3 s after the cover was shown.
const HOLD_MS = 3000;
const shownAt = performance.now();
let buffering = false;
const buffer = () => {
if (buffering) return;
buffering = true;
events.forEach((eventName) => window.removeEventListener(eventName, buffer));
const mobile = window.matchMedia('(max-width: 1023px)').matches;
document.querySelectorAll('[data-hero-video]').forEach((video) => {
const src = (mobile ? video.dataset.srcMobile : video.dataset.srcDesktop) || video.dataset.srcDesktop;
if (!src) return;
const hero = video.closest('[data-hero]');
video.addEventListener('playing', () => hero?.classList.add('is-playing'));
if (!video.getAttribute('src')) video.src = src;
video.preload = 'auto';
video.load();
const play = () => {
const attempt = video.play();
if (attempt && typeof attempt.catch === 'function') attempt.catch(() => {});
};
const wait = Math.max(0, HOLD_MS - (performance.now() - shownAt));
window.setTimeout(() => {
if (video.readyState >= 3) play();
else video.addEventListener('canplay', play, { once: true });
}, wait);
});
};
// Buffering begins after load (so it never competes with the cover image) or on the first interaction.
const events = ['keydown', 'mousedown', 'touchstart', 'wheel', 'scroll'];
events.forEach((eventName) => window.addEventListener(eventName, buffer, { passive: true }));
const conn = navigator.connection;
const slow = conn && (conn.saveData || /2g/.test(conn.effectiveType || ''));
if (!slow) {
// Wait for the page load AND for the cover (LCP image) to be painted, then an idle moment,
// so the video download never competes with the cover.
const cover = document.querySelector('.hero__poster-image');
const coverReady = () => new Promise((resolve) => {
if (!cover || cover.complete) return resolve();
cover.addEventListener('load', resolve, { once: true });
cover.addEventListener('error', resolve, { once: true });
});
const pageLoaded = () => new Promise((resolve) => {
if (document.readyState === 'complete') resolve();
else window.addEventListener('load', resolve, { once: true });
});
const idle = () => new Promise((resolve) => {
if ('requestIdleCallback' in window) window.requestIdleCallback(() => resolve(), { timeout: 1500 });
else window.setTimeout(resolve, 300);
});
Promise.all([pageLoaded(), coverReady()]).then(idle).then(buffer);
}
})();
</script>
{% javascript %}
(() => {
if (window.__seasonHero) return;
window.__seasonHero = true;
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);
};
document.querySelectorAll('[data-hero]').forEach((hero) => {
const video = hero.querySelector('[data-hero-video]');
if (!video || reduceMotion) return;
const markPlaying = () => hero.classList.add('is-playing');
video.addEventListener('playing', markPlaying);
// Playback timing (3 s hold on the first-frame cover) is handled by the inline hero script.
});
document.addEventListener('submit', async (event) => {
if (event.defaultPrevented) return;
const form = event.target;
if (!(form instanceof HTMLFormElement) || !form.classList.contains('hero__form')) return;
const hero = form.closest('[data-hero]');
if (!hero) 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(hero.dataset.cartAddUrl, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
Accept: 'application/json',
},
body: JSON.stringify({ id: variantId, quantity: 1 }),
});
if (!addResponse.ok) return;
const cartResponse = await fetch(hero.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'));
button.classList.add('is-added');
window.setTimeout(() => button.classList.remove('is-added'), 1200);
} catch (error) {
form.submit();
} finally {
button.disabled = false;
}
});
})();
{% endjavascript %}
{% schema %}
{
"name": "t:hero.name",
"tag": "section",
"class": "hero-section",
"max_blocks": 3,
"disabled_on": {
"groups": [
"header",
"footer"
]
},
"settings": [
{
"type": "header",
"content": "t:hero.heading"
},
{
"type": "text",
"id": "heading_line_1",
"label": "t:hero.line_1",
"default": "descubre"
},
{
"type": "select",
"id": "heading_line_1_weight",
"label": "t:hero.line_1_weight",
"default": "light",
"options": [
{
"value": "light",
"label": "t:hero.weight_light"
},
{
"value": "medium",
"label": "t:hero.weight_medium"
}
]
},
{
"type": "text",
"id": "heading_line_2",
"label": "t:hero.line_2",
"default": "lo que tu piel"
},
{
"type": "select",
"id": "heading_line_2_weight",
"label": "t:hero.line_2_weight",
"default": "medium",
"options": [
{
"value": "light",
"label": "t:hero.weight_light"
},
{
"value": "medium",
"label": "t:hero.weight_medium"
}
]
},
{
"type": "text",
"id": "heading_line_3",
"label": "t:hero.line_3",
"default": "disfrutará"
},
{
"type": "select",
"id": "heading_line_3_weight",
"label": "t:hero.line_3_weight",
"default": "light",
"options": [
{
"value": "light",
"label": "t:hero.weight_light"
},
{
"value": "medium",
"label": "t:hero.weight_medium"
}
]
},
{
"type": "text",
"id": "featured_label",
"label": "t:hero.featured_label",
"default": "Producto destacado"
},
{
"type": "header",
"content": "t:hero.media"
},
{
"type": "select",
"id": "media_type",
"label": "t:hero.media_type",
"default": "video",
"options": [
{
"value": "video",
"label": "t:hero.media_video"
},
{
"value": "image",
"label": "t:hero.media_image"
}
]
},
{
"type": "video",
"id": "video",
"label": "t:hero.video",
"info": "t:hero.video_info",
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "video",
"id": "video_mobile",
"label": "Video móvil (vertical, ligero)",
"info": "Opcional. Recomendado: vertical, sin audio, menos de 1 MB.",
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "checkbox",
"id": "use_light_mobile_video",
"label": "Usar versión ligera incluida en el tema para móvil",
"info": "Recorte vertical del video actual (~450 KB). Desactívalo si cambias el video principal y no subes uno móvil.",
"default": true,
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "checkbox",
"id": "poster_from_video",
"label": "Portada = primer cuadro del video",
"info": "Muestra el primer cuadro del video (imagen ligera precargada) 3 s antes de reproducir. Desactívalo para usar las portadas de abajo.",
"default": true,
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "checkbox",
"id": "theme_hosted_videos",
"label": "Usar videos optimizados del tema",
"info": "Sirve seasons-hero-desktop.mp4 (~1 MB) y seasons-hero-mobile.mp4 (~0.4 MB) desde el tema, sin la recompresión de Shopify (que los vuelve ~2 MB). Si cambias los videos, actualiza esos archivos o desactiva esta opción.",
"default": true,
"visible_if": "{{ section.settings.media_type == 'video' }}"
},
{
"type": "image_picker",
"id": "cover_desktop",
"label": "t:hero.cover_desktop",
"info": "t:hero.cover_info"
},
{
"type": "image_picker",
"id": "cover_mobile",
"label": "t:hero.cover_mobile"
},
{
"type": "header",
"content": "t:hero.social"
},
{
"type": "text",
"id": "social_label",
"label": "t:hero.social_label",
"default": "Síguenos"
},
{
"type": "url",
"id": "instagram_url",
"label": "t:hero.instagram"
},
{
"type": "url",
"id": "facebook_url",
"label": "t:hero.facebook"
},
{
"type": "url",
"id": "linkedin_url",
"label": "t:hero.linkedin"
}
],
"blocks": [
{
"type": "featured_product",
"name": "t:hero.featured_product",
"limit": 3,
"settings": [
{
"type": "product",
"id": "product",
"label": "t:hero.product"
}
]
}
],
"presets": [
{
"name": "t:hero.name",
"blocks": [
{
"type": "featured_product"
}
]
}
]
}
{% endschema %}