Files
season/sections/hero.liquid
T
2026-10-09 23:02:05 -06:00

465 lines
14 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
assign video_src = blank
if media_type == 'video'
if section.settings.video != blank
for source in section.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
assign video_src = 'home-video-op.mp4' | asset_url
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"
>
<link rel="preload" as="image" href="{{ cover_desktop }}" media="(min-width: 1024px)" fetchpriority="high">
<link rel="preload" as="image" href="{{ cover_mobile }}" media="(max-width: 1023px)" fetchpriority="high">
<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
muted
loop
playsinline
preload="none"
>
<source src="{{ video_src }}" type="video/mp4">
</video>
<picture class="hero__poster">
<source media="(max-width: 1023px)" srcset="{{ cover_mobile }}">
<img
class="hero__poster-image"
src="{{ cover_desktop }}"
alt=""
width="1920"
height="650"
fetchpriority="high"
>
</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 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;
const events = ['keydown', 'mousedown', 'mousemove', 'touchstart', 'wheel'];
const start = () => {
events.forEach((eventName) => window.removeEventListener(eventName, start));
document.querySelectorAll('[data-hero-video]').forEach((video) => {
const hero = video.closest('[data-hero]');
const play = () => {
const attempt = video.play();
if (attempt && typeof attempt.catch === 'function') attempt.catch(() => {});
};
video.addEventListener('playing', () => hero?.classList.add('is-playing'));
video.preload = 'auto';
if (video.readyState >= 2) play();
else video.addEventListener('canplay', play, { once: true });
video.load();
});
};
events.forEach((eventName) => window.addEventListener(eventName, start, { passive: true }));
})();
</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);
const tryPlay = () => {
const playAttempt = video.play();
if (playAttempt && typeof playAttempt.catch === 'function') {
playAttempt.catch(() => {});
}
};
if (video.readyState >= 2) {
tryPlay();
} else {
video.addEventListener('canplay', tryPlay, { once: true });
}
});
document.addEventListener('submit', async (event) => {
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": 2,
"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": "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": 2,
"settings": [
{
"type": "product",
"id": "product",
"label": "t:hero.product"
}
]
}
],
"presets": [
{
"name": "t:hero.name",
"blocks": [
{ "type": "featured_product" }
]
}
]
}
{% endschema %}