Files
season/sections/routine.liquid
T

343 lines
10 KiB
Plaintext

{% liquid
if section.settings.heading != blank
assign heading = section.settings.heading
else
assign heading = 'routine.heading' | t
endif
if section.settings.cover_link != blank
assign cover_href = section.settings.cover_link
else
assign cover_href = '/collections/kits-skincare-facial'
endif
assign cover_tag = 'a'
%}
<section class="routine full-width">
<div class="routine__layout">
<{{ cover_tag }}
class="routine__cover"
{% if cover_tag == 'a' %}
href="{{ cover_href }}"
{% endif %}
>
{% if section.settings.cover_image != blank %}
{{
section.settings.cover_image
| image_url: width: 1700
| image_tag:
alt: heading,
widths: '400, 800, 1200, 1700',
sizes: '(max-width: 1024px) calc(100vw - 30px), 50vw',
class: 'routine__cover-image',
loading: 'lazy'
}}
{% else %}
<img
class="routine__cover-image"
src="{{ 'routine-photo.avif' | asset_url }}"
alt="{{ heading | escape }}"
width="849"
height="892"
srcset="{{ 'routine-photo-sm.avif' | asset_url }} 700w, {{ 'routine-photo.avif' | asset_url }} 1240w"
sizes="(max-width: 1024px) 95vw, 849px"
loading="lazy"
decoding="async"
>
{% endif %}
<h2 class="routine__heading">{{ heading | escape | newline_to_br }}</h2>
</{{ cover_tag }}>
<div class="routine__steps" data-routine-viewport>
<div class="routine__track" data-routine-track>
{% for block in section.blocks %}
{% liquid
if block.settings.title != blank
assign step_title = block.settings.title
else
assign step_key = 'routine.steps.step_' | append: forloop.index
assign step_title = step_key | t
endif
assign step_url = block.settings.link
if step_url == blank
case forloop.index
when 1
assign step_url = '/collections/1-limpia'
when 2
assign step_url = '/collections/2-trata'
when 3
assign step_url = '/collections/3-hidrata'
when 4
assign step_url = '/collections/4-protege-bloqueadores-solares'
endcase
endif
if step_url != blank
assign step_tag = 'a'
else
assign step_tag = 'div'
endif
assign fallback_image = blank
case forloop.index
when 1
assign fallback_image = 'routine-limpia.avif'
when 2
assign fallback_image = 'routine-trata.avif'
when 3
assign fallback_image = 'routine-hidrata.avif'
when 4
assign fallback_image = 'routine-protege.avif'
endcase
%}
<{{ step_tag }}
class="routine__card"
{{ block.shopify_attributes }}
{% if step_tag == 'a' %}
href="{{ step_url }}"
{% endif %}
>
<span class="routine__media">
{% if block.settings.image != blank %}
{{
block.settings.image
| image_url: width: 900
| image_tag:
alt: step_title,
widths: '245, 415, 830',
sizes: '(max-width: 1024px) 245px, 25vw',
class: 'routine__image',
loading: 'lazy'
}}
{% elsif fallback_image != blank %}
<img
class="routine__image"
src="{{ fallback_image | asset_url }}"
alt="{{ step_title | escape }}"
width="415"
height="436"
srcset="{{ fallback_image | replace: '.avif', '-sm.avif' | asset_url }} 450w, {{ fallback_image | asset_url }} 750w"
sizes="(max-width: 1024px) 245px, 415px"
loading="lazy"
decoding="async"
>
{% endif %}
<span class="routine__shade" aria-hidden="true"></span>
</span>
<span class="routine__caption">
<span class="routine__label">{{ step_title | escape }}</span>
<span class="routine__arrow" aria-hidden="true">
<span class="routine__arrow-icon">
<svg width="20" height="20" viewBox="0 0 20 20" fill="none" xmlns="http://www.w3.org/2000/svg">
<path d="M4.375 9.53125L10 3.90625L15.625 9.53125M10 4.6875V16.0938" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
</span>
</span>
</span>
</{{ step_tag }}>
{% else %}
{% if request.design_mode %}
<p class="routine__empty">{{ 'routine.empty' | t }}</p>
{% endif %}
{% endfor %}
</div>
</div>
<div class="routine__progress" aria-hidden="true">
<span class="routine__progress-bar" data-routine-bar></span>
</div>
</div>
</section>
<script nolazy>
(() => {
const sliderQuery = window.matchMedia('(max-width: 1024px)');
const phoneQuery = window.matchMedia('(max-width: 767px)');
const reduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)');
const strideOf = (viewport) => {
const card = viewport.querySelector('.routine__card');
const track = viewport.querySelector('[data-routine-track]');
if (!card) return 0;
const gap = track ? parseFloat(window.getComputedStyle(track).columnGap) || 0 : 0;
return card.getBoundingClientRect().width + gap;
};
const updateProgress = (viewport) => {
const section = viewport.closest('.routine');
const bar = section && section.querySelector('[data-routine-bar]');
if (!bar) return;
const max = viewport.scrollWidth - viewport.clientWidth;
const visible = viewport.scrollWidth > 0 ? viewport.clientWidth / viewport.scrollWidth : 1;
const width = Math.min(Math.max(visible * 100, 12), 100);
const travel = 100 - width;
const progress = max <= 2 ? 0 : viewport.scrollLeft / max;
bar.style.width = `${width}%`;
bar.style.left = `${progress * travel}%`;
};
const goTo = (viewport, index, behavior) => {
const stride = strideOf(viewport);
const count = viewport.querySelectorAll('.routine__card').length;
if (!stride || !count) return;
const wrapped = ((index % count) + count) % count;
const max = Math.max(viewport.scrollWidth - viewport.clientWidth, 0);
viewport.scrollTo({ left: Math.min(wrapped * stride, max), behavior });
};
const boot = (section) => {
const viewport = section.querySelector('[data-routine-viewport]');
if (!viewport || viewport.dataset.ready === 'true') return;
viewport.dataset.ready = 'true';
const pause = () => {
if (viewport._routineTimer) window.clearInterval(viewport._routineTimer);
viewport._routineTimer = null;
};
const play = () => {
pause();
if (!sliderQuery.matches || reduceMotion.matches || viewport.dataset.paused === 'true') return;
viewport._routineTimer = window.setInterval(() => {
const max = viewport.scrollWidth - viewport.clientWidth;
if (max <= 2) return;
const stride = strideOf(viewport);
const count = viewport.querySelectorAll('.routine__card').length;
if (!stride || count < 2) return;
const index = Math.round(viewport.scrollLeft / stride);
const behavior = reduceMotion.matches ? 'auto' : 'smooth';
goTo(viewport, index + 1 >= count ? 0 : index + 1, behavior);
}, 4000);
};
if (phoneQuery.matches) goTo(viewport, 0, 'auto');
updateProgress(viewport);
play();
viewport.addEventListener('scroll', () => updateProgress(viewport), { passive: true });
viewport.addEventListener('pointerdown', () => {
viewport.dataset.paused = 'true';
pause();
});
viewport.addEventListener('pointerup', () => {
window.setTimeout(() => {
delete viewport.dataset.paused;
play();
}, 2500);
});
viewport.addEventListener('pointercancel', () => {
delete viewport.dataset.paused;
play();
});
const onChange = () => {
if (phoneQuery.matches) {
const stride = strideOf(viewport);
const index = stride ? Math.round(viewport.scrollLeft / stride) : 0;
goTo(viewport, index, 'auto');
}
updateProgress(viewport);
play();
};
sliderQuery.addEventListener('change', onChange);
phoneQuery.addEventListener('change', onChange);
window.addEventListener('resize', onChange);
};
document.querySelectorAll('.routine').forEach(boot);
if (window.__seasonRoutine) return;
window.__seasonRoutine = true;
document.addEventListener('shopify:section:load', (event) => {
const section = event.target.querySelector('.routine');
if (section) boot(section);
});
})();
</script>
{% schema %}
{
"name": "t:routine.name",
"tag": "section",
"class": "routine-section",
"disabled_on": {
"groups": ["header", "footer"]
},
"settings": [
{
"type": "textarea",
"id": "heading",
"label": "t:routine.heading",
"default": "Tu rutina\nen 4 pasos"
},
{
"type": "image_picker",
"id": "cover_image",
"label": "t:routine.cover_image",
"info": "t:routine.cover_image_info"
},
{
"type": "url",
"id": "cover_link",
"label": "t:routine.cover_link"
}
],
"blocks": [
{
"type": "step",
"name": "t:routine.step",
"limit": 4,
"settings": [
{
"type": "image_picker",
"id": "image",
"label": "t:routine.step_image",
"info": "t:routine.step_image_info"
},
{
"type": "text",
"id": "title",
"label": "t:routine.step_title"
},
{
"type": "url",
"id": "link",
"label": "t:routine.step_link"
}
]
}
],
"presets": [
{
"name": "t:routine.name",
"blocks": [
{
"type": "step",
"settings": {
"title": "Paso 1: Limpia"
}
},
{
"type": "step",
"settings": {
"title": "Paso 2: Trata"
}
},
{
"type": "step",
"settings": {
"title": "Paso 3: Hidrata"
}
},
{
"type": "step",
"settings": {
"title": "Paso 4: Protege"
}
}
]
}
]
}
{% endschema %}