quitar media print css
This commit is contained in:
@@ -0,0 +1,181 @@
|
||||
{% doc %}
|
||||
Renders one product card for the best sellers slider.
|
||||
|
||||
@param {product} product - Product to display
|
||||
@param {string} [form_suffix] - Suffix that keeps the add-to-cart form id unique
|
||||
|
||||
@example
|
||||
{% render 'bestsellers-card', product: product, form_suffix: section.id %}
|
||||
{% enddoc %}
|
||||
|
||||
{% liquid
|
||||
assign variant = product.selected_or_first_available_variant
|
||||
assign card_image = product.featured_image
|
||||
assign hover_image = blank
|
||||
for image in product.images offset: 1 limit: 1
|
||||
assign hover_image = image
|
||||
endfor
|
||||
assign image_alt = card_image.alt | default: product.title
|
||||
|
||||
assign subtitle = product.metafields.custom.subtitulo.value | default: product.metafields.custom.subtitulo
|
||||
if subtitle == blank
|
||||
assign subtitle = product.metafields.custom.subtitle.value | default: product.metafields.custom.subtitle
|
||||
endif
|
||||
if subtitle == blank
|
||||
assign subtitle = product.metafields.custom.presentacion.value | default: product.metafields.custom.presentacion
|
||||
endif
|
||||
if subtitle == blank and variant.title != 'Default Title'
|
||||
assign subtitle = variant.title
|
||||
endif
|
||||
|
||||
assign skin_label = product.metafields.custom.tipo_de_piel.value | default: product.metafields.custom.tipo_de_piel
|
||||
if skin_label == blank
|
||||
assign skin_label = product.metafields.custom.skin_type.value | default: product.metafields.custom.skin_type
|
||||
endif
|
||||
if skin_label == blank
|
||||
assign skin_fallback = blank
|
||||
for tag in product.tags
|
||||
assign tag_label = tag | downcase
|
||||
if tag_label contains 'piel'
|
||||
if skin_fallback == blank
|
||||
assign skin_fallback = tag
|
||||
endif
|
||||
if tag_label contains 'pieles' or tag_label contains 'piel '
|
||||
assign skin_label = tag
|
||||
break
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
if skin_label == blank
|
||||
assign skin_label = skin_fallback
|
||||
endif
|
||||
endif
|
||||
|
||||
assign rating_value = 0
|
||||
assign rating_count = 0
|
||||
if product.metafields.reviews.rating.value != blank
|
||||
assign rating_value = product.metafields.reviews.rating.value.rating | round
|
||||
endif
|
||||
if product.metafields.reviews.rating_count.value != blank
|
||||
assign rating_count = product.metafields.reviews.rating_count.value
|
||||
endif
|
||||
|
||||
assign compare_price = variant.compare_at_price
|
||||
assign show_compare = false
|
||||
if compare_price > variant.price
|
||||
assign show_compare = true
|
||||
endif
|
||||
%}
|
||||
|
||||
<article class="bestsellers__card">
|
||||
<div class="bestsellers__media">
|
||||
<a class="bestsellers__media-link" href="{{ product.url }}">
|
||||
{% if card_image %}
|
||||
{{
|
||||
card_image
|
||||
| image_url: width: 800
|
||||
| image_tag:
|
||||
alt: image_alt,
|
||||
widths: '245, 386, 490, 772',
|
||||
sizes: '(max-width: 1024px) 245px, 386px',
|
||||
class: 'bestsellers__image',
|
||||
loading: 'lazy'
|
||||
}}
|
||||
{% if hover_image != blank %}
|
||||
{{
|
||||
hover_image
|
||||
| image_url: width: 800
|
||||
| image_tag:
|
||||
alt: '',
|
||||
widths: '245, 386, 490, 772',
|
||||
sizes: '(max-width: 1024px) 245px, 386px',
|
||||
class: 'bestsellers__image bestsellers__image--hover',
|
||||
loading: 'lazy'
|
||||
}}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class="bestsellers__image bestsellers__image--empty" aria-hidden="true"></span>
|
||||
{% endif %}
|
||||
</a>
|
||||
|
||||
<div class="bestsellers__badges">
|
||||
<span class="bestsellers__badge bestsellers__badge--best">{{ 'bestsellers.badge' | t }}</span>
|
||||
{% if skin_label != blank %}
|
||||
<span class="bestsellers__badge bestsellers__badge--skin">{{ skin_label | escape }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<form class="bestsellers__actions bestsellers__form" action="{{ routes.cart_add_url }}" method="post">
|
||||
<input type="hidden" name="id" value="{{ variant.id }}">
|
||||
<input type="hidden" name="quantity" value="1">
|
||||
<button
|
||||
class="bestsellers__bag"
|
||||
type="submit"
|
||||
{% unless variant.available %}disabled{% endunless %}
|
||||
aria-label="{{ 'bestsellers.add_to_cart' | t }}"
|
||||
>
|
||||
<img src="{{ 'testimonials-bag.svg' | asset_url }}" alt="" width="25" height="25">
|
||||
</button>
|
||||
<button
|
||||
class="bestsellers__buy"
|
||||
type="submit"
|
||||
data-buy
|
||||
{% unless variant.available %}disabled{% endunless %}
|
||||
>
|
||||
{% if variant.available %}
|
||||
{{ 'bestsellers.buy_now' | t }}
|
||||
{% else %}
|
||||
{{ 'bestsellers.sold_out' | t }}
|
||||
{% endif %}
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<button
|
||||
class="bestsellers__wish"
|
||||
type="button"
|
||||
data-wishlist
|
||||
data-product-id="{{ product.id }}"
|
||||
aria-pressed="false"
|
||||
aria-label="{{ 'bestsellers.save' | t: product: product.title }}"
|
||||
data-label-save="{{ 'bestsellers.save' | t: product: product.title }}"
|
||||
data-label-saved="{{ 'bestsellers.saved' | t: product: product.title }}"
|
||||
>
|
||||
<span class="bestsellers__wish-icon" aria-hidden="true">
|
||||
<svg width="25" height="25" viewBox="0 0 25 25" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M17.2324 3.90625C14.0625 3.90625 12.5 7.03125 12.5 7.03125C12.5 7.03125 10.9375 3.90625 7.76758 3.90625C5.19141 3.90625 3.15137 6.06152 3.125 8.6333C3.07129 13.9717 7.35986 17.7681 12.0605 20.9585C12.1901 21.0467 12.3433 21.0938 12.5 21.0938C12.6567 21.0938 12.8099 21.0467 12.9395 20.9585C17.6396 17.7681 21.9282 13.9717 21.875 8.6333C21.8486 6.06152 19.8086 3.90625 17.2324 3.90625Z" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="bestsellers__info">
|
||||
<div class="bestsellers__copy">
|
||||
<a class="bestsellers__title" href="{{ product.url }}">{{ product.title | escape }}</a>
|
||||
{% if subtitle != blank %}
|
||||
<p class="bestsellers__subtitle">{{ subtitle | escape }}</p>
|
||||
{% endif %}
|
||||
{% if rating_count > 0 %}
|
||||
<div class="bestsellers__rating">
|
||||
<div class="bestsellers__stars" aria-hidden="true">
|
||||
{% for index in (1..5) %}
|
||||
<span class="bestsellers__star{% if index > rating_value %} is-off{% endif %}">
|
||||
<svg width="10" height="10" viewBox="0 0 10 10" fill="none" xmlns="http://www.w3.org/2000/svg" aria-hidden="true">
|
||||
<path d="M7.69531 9.39111C7.62954 9.39136 7.56536 9.37086 7.51191 9.33251L5 7.51142L2.48809 9.33251C2.43442 9.37144 2.36977 9.39228 2.30347 9.39204C2.23718 9.3918 2.17268 9.37048 2.1193 9.33117C2.06592 9.29186 2.02642 9.23659 2.00652 9.17335C1.98662 9.11011 1.98735 9.04218 2.00859 8.97939L2.98828 6.07763L0.449219 4.33642C0.394221 4.29874 0.352712 4.24447 0.330756 4.18153C0.3088 4.11858 0.307549 4.05027 0.327184 3.98656C0.34682 3.92285 0.386313 3.86709 0.439895 3.82743C0.493476 3.78777 0.558336 3.76628 0.625 3.7661H3.75742L4.70273 0.856925C4.7231 0.794117 4.76283 0.739373 4.81624 0.700546C4.86964 0.66172 4.93397 0.640807 5 0.640807C5.06603 0.640807 5.13036 0.66172 5.18376 0.700546C5.23717 0.739373 5.2769 0.794117 5.29727 0.856925L6.24258 3.76708H9.375C9.44175 3.76705 9.50675 3.78839 9.56049 3.82797C9.61423 3.86756 9.65389 3.92331 9.67365 3.98707C9.69341 4.05082 9.69223 4.11923 9.6703 4.18227C9.64837 4.24531 9.60682 4.29967 9.55176 4.33739L7.01172 6.07763L7.99082 8.97861C8.00668 9.02557 8.01115 9.07564 8.00384 9.12467C7.99653 9.17371 7.97766 9.2203 7.94879 9.2606C7.91992 9.3009 7.88188 9.33375 7.8378 9.35644C7.79373 9.37913 7.74489 9.39102 7.69531 9.39111Z" fill="black"/>
|
||||
</svg>
|
||||
</span>
|
||||
{% endfor %}
|
||||
</div>
|
||||
<p class="bestsellers__reviews">{{ 'bestsellers.reviews' | t: count: rating_count }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<div class="bestsellers__prices">
|
||||
<span class="bestsellers__price">{{ variant.price | money_without_trailing_zeros }}</span>
|
||||
{% if show_compare %}
|
||||
<s class="bestsellers__compare">{{ compare_price | money_without_trailing_zeros }}</s>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</article>
|
||||
@@ -0,0 +1,589 @@
|
||||
{% doc %}
|
||||
Renders a collection product card. Hover shows the second image plus add to cart and buy now.
|
||||
|
||||
@param {product} product - Product to display
|
||||
@param {string} [form_suffix] - Keeps the product form id unique
|
||||
|
||||
@example
|
||||
{% render 'collection-card', product: product, form_suffix: section.id %}
|
||||
{% enddoc %}
|
||||
|
||||
{% liquid
|
||||
assign variant = product.selected_or_first_available_variant
|
||||
assign card_image = product.featured_image
|
||||
assign hover_image = blank
|
||||
for image in product.images offset: 1 limit: 1
|
||||
assign hover_image = image
|
||||
endfor
|
||||
assign image_alt = card_image.alt | default: product.title
|
||||
|
||||
assign subtitle = product.metafields.custom.subtitulo.value | default: product.metafields.custom.subtitulo
|
||||
if subtitle == blank
|
||||
assign subtitle = product.metafields.custom.subtitle.value | default: product.metafields.custom.subtitle
|
||||
endif
|
||||
if subtitle == blank
|
||||
assign subtitle = product.metafields.custom.presentacion.value | default: product.metafields.custom.presentacion
|
||||
endif
|
||||
if subtitle == blank and variant.title != 'Default Title'
|
||||
assign subtitle = variant.title
|
||||
endif
|
||||
|
||||
assign skin_label = product.metafields.custom.tipo_de_piel.value | default: product.metafields.custom.tipo_de_piel
|
||||
if skin_label == blank
|
||||
assign skin_label = product.metafields.custom.skin_type.value | default: product.metafields.custom.skin_type
|
||||
endif
|
||||
|
||||
assign badge_best = false
|
||||
assign badge_recommended = false
|
||||
for tag in product.tags
|
||||
assign tag_label = tag | downcase
|
||||
if tag_label contains 'vendido' or tag_label contains 'bestseller'
|
||||
assign badge_best = true
|
||||
endif
|
||||
if tag_label contains 'recomend'
|
||||
assign badge_recommended = true
|
||||
endif
|
||||
if skin_label == blank and tag_label contains 'piel'
|
||||
assign skin_label = tag
|
||||
endif
|
||||
endfor
|
||||
|
||||
assign rating_value = 0
|
||||
assign rating_count = 0
|
||||
if product.metafields.reviews.rating.value != blank
|
||||
assign rating_value = product.metafields.reviews.rating.value.rating | round
|
||||
endif
|
||||
if product.metafields.reviews.rating_count.value != blank
|
||||
assign rating_count = product.metafields.reviews.rating_count.value
|
||||
endif
|
||||
|
||||
assign show_compare = false
|
||||
if variant.compare_at_price > variant.price
|
||||
assign show_compare = true
|
||||
endif
|
||||
|
||||
assign form_id = 'collection-card-' | append: product.id
|
||||
if form_suffix != blank
|
||||
assign form_id = form_id | append: '-' | append: form_suffix
|
||||
endif
|
||||
%}
|
||||
|
||||
<article class="collection-card">
|
||||
<div class="collection-card__media">
|
||||
<a class="collection-card__link" href="{{ product.url }}">
|
||||
{% if card_image %}
|
||||
{{
|
||||
card_image
|
||||
| image_url: width: 900
|
||||
| image_tag:
|
||||
alt: image_alt,
|
||||
widths: '186, 372, 560, 800',
|
||||
sizes: '(max-width: 767px) 46vw, 33vw',
|
||||
class: 'collection-card__image',
|
||||
loading: 'lazy'
|
||||
}}
|
||||
{% if hover_image != blank %}
|
||||
{{
|
||||
hover_image
|
||||
| image_url: width: 900
|
||||
| image_tag:
|
||||
alt: '',
|
||||
widths: '186, 372, 560, 800',
|
||||
sizes: '(max-width: 767px) 46vw, 33vw',
|
||||
class: 'collection-card__image collection-card__image--hover',
|
||||
loading: 'lazy'
|
||||
}}
|
||||
{% endif %}
|
||||
{% else %}
|
||||
<span class="collection-card__image collection-card__image--empty" aria-hidden="true"></span>
|
||||
{% endif %}
|
||||
</a>
|
||||
|
||||
<div class="collection-card__badges">
|
||||
{% if badge_best %}
|
||||
<span class="collection-card__badge collection-card__badge--best">{{ 'bestsellers.badge' | t }}</span>
|
||||
{% endif %}
|
||||
{% if badge_recommended %}
|
||||
<span class="collection-card__badge collection-card__badge--best">{{ 'collection_page.recommended' | t }}</span>
|
||||
{% endif %}
|
||||
{% if skin_label != blank %}
|
||||
<span class="collection-card__badge collection-card__badge--skin">{{ skin_label | escape }}</span>
|
||||
{% endif %}
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="collection-card__wish"
|
||||
type="button"
|
||||
data-wishlist
|
||||
data-product-id="{{ product.id }}"
|
||||
aria-pressed="false"
|
||||
aria-label="{{ 'bestsellers.save' | t: product: product.title }}"
|
||||
data-label-save="{{ 'bestsellers.save' | t: product: product.title }}"
|
||||
data-label-saved="{{ 'bestsellers.saved' | t: product: product.title }}"
|
||||
>
|
||||
<svg width="25" height="25" viewBox="0 0 25 25" aria-hidden="true" focusable="false">
|
||||
<path d="M17.2324 3.90625C14.0625 3.90625 12.5 7.03125 12.5 7.03125C12.5 7.03125 10.9375 3.90625 7.76758 3.90625C5.19141 3.90625 3.15137 6.06152 3.125 8.6333C3.07129 13.9717 7.35986 17.7681 12.0605 20.9585C12.1901 21.0467 12.3433 21.0938 12.5 21.0938C12.6567 21.0938 12.8099 21.0467 12.9395 20.9585C17.6396 17.7681 21.9282 13.9717 21.875 8.6333C21.8486 6.06152 19.8086 3.90625 17.2324 3.90625Z" fill="none" stroke="black" stroke-linecap="round" stroke-linejoin="round"/>
|
||||
</svg>
|
||||
</button>
|
||||
|
||||
<form
|
||||
id="{{ form_id }}"
|
||||
class="collection-card__actions"
|
||||
action="{{ routes.cart_add_url }}"
|
||||
method="post"
|
||||
data-collection-card
|
||||
>
|
||||
<input type="hidden" name="id" value="{{ variant.id }}">
|
||||
<input type="hidden" name="quantity" value="1">
|
||||
<button class="collection-card__add" type="submit" {% unless variant.available %}disabled{% endunless %}>
|
||||
{% if variant.available %}
|
||||
{{ 'bestsellers.add_to_cart' | t }}
|
||||
{% else %}
|
||||
{{ 'bestsellers.sold_out' | t }}
|
||||
{% endif %}
|
||||
</button>
|
||||
<button class="collection-card__buy" type="submit" data-buy {% unless variant.available %}disabled{% endunless %}>
|
||||
{{ 'bestsellers.buy_now' | t }}
|
||||
</button>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="collection-card__info">
|
||||
<a class="collection-card__title" href="{{ product.url }}">{{ product.title | escape }}</a>
|
||||
{% if subtitle != blank %}
|
||||
<p class="collection-card__subtitle">{{ subtitle | escape }}</p>
|
||||
{% endif %}
|
||||
{% if rating_count > 0 %}
|
||||
<div class="collection-card__rating">
|
||||
<span class="collection-card__stars" aria-hidden="true">
|
||||
{% for star in (1..5) %}
|
||||
<svg class="collection-card__star{% if star > rating_value %} is-off{% endif %}" width="14" height="14" viewBox="0 0 14 14" focusable="false">
|
||||
<path d="M7 1.2l1.45 3.22 3.5.4-2.62 2.38.74 3.46L7 8.95 3.93 10.66l.74-3.46L2.05 4.82l3.5-.4L7 1.2z" fill="currentColor"/>
|
||||
</svg>
|
||||
{% endfor %}
|
||||
</span>
|
||||
<p class="collection-card__reviews">{{ 'bestsellers.reviews' | t: count: rating_count }}</p>
|
||||
</div>
|
||||
{% endif %}
|
||||
<p class="collection-card__prices">
|
||||
<span class="collection-card__price">{{ variant.price | money_without_trailing_zeros }}</span>
|
||||
{% if show_compare %}
|
||||
<s class="collection-card__compare">{{ variant.compare_at_price | money_without_trailing_zeros }}</s>
|
||||
{% endif %}
|
||||
</p>
|
||||
</div>
|
||||
</article>
|
||||
|
||||
{% stylesheet %}
|
||||
.collection-card {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 15px;
|
||||
min-width: 0;
|
||||
}
|
||||
|
||||
.collection-card__media {
|
||||
position: relative;
|
||||
aspect-ratio: 1;
|
||||
overflow: hidden;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.collection-card__link {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.collection-card__image {
|
||||
display: block;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
object-fit: cover;
|
||||
}
|
||||
|
||||
.collection-card__image--hover {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
opacity: 0;
|
||||
transition: opacity 0.35s ease;
|
||||
}
|
||||
|
||||
.collection-card__media:hover .collection-card__image--hover,
|
||||
.collection-card__media:focus-within .collection-card__image--hover {
|
||||
opacity: 1;
|
||||
}
|
||||
|
||||
.collection-card__image--empty {
|
||||
background: #f3f3f3;
|
||||
}
|
||||
|
||||
.collection-card__badges {
|
||||
position: absolute;
|
||||
top: 10px;
|
||||
left: 10px;
|
||||
z-index: 1;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: flex-start;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.collection-card__badge {
|
||||
display: inline-flex;
|
||||
align-items: center;
|
||||
padding: 3px 5px;
|
||||
border-radius: 2px;
|
||||
color: #000;
|
||||
font-size: 10px;
|
||||
font-weight: 300;
|
||||
line-height: normal;
|
||||
text-transform: uppercase;
|
||||
}
|
||||
|
||||
.collection-card__badge--best {
|
||||
background: #bfffb2;
|
||||
}
|
||||
|
||||
.collection-card__badge--skin {
|
||||
background: #f7c585;
|
||||
}
|
||||
|
||||
.collection-card__wish {
|
||||
position: absolute;
|
||||
top: 16px;
|
||||
right: 16px;
|
||||
z-index: 2;
|
||||
display: grid;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
place-items: center;
|
||||
padding: 0;
|
||||
border: 0;
|
||||
background: transparent;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.collection-card__wish svg {
|
||||
display: block;
|
||||
width: 25px;
|
||||
height: 25px;
|
||||
}
|
||||
|
||||
.collection-card__wish.is-active svg path {
|
||||
fill: #000;
|
||||
}
|
||||
|
||||
.collection-card__actions {
|
||||
position: absolute;
|
||||
right: 16px;
|
||||
bottom: 16px;
|
||||
left: 16px;
|
||||
z-index: 2;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
margin: 0;
|
||||
opacity: 0;
|
||||
pointer-events: none;
|
||||
transition: opacity 0.25s ease;
|
||||
}
|
||||
|
||||
.collection-card__media:hover .collection-card__actions,
|
||||
.collection-card__media:focus-within .collection-card__actions {
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
}
|
||||
|
||||
.collection-card__add,
|
||||
.collection-card__buy {
|
||||
flex: 1 1 0;
|
||||
height: 48px;
|
||||
border-radius: 60px;
|
||||
font: inherit;
|
||||
font-size: 14px;
|
||||
font-weight: 500;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.collection-card__add {
|
||||
border: 1px solid #111;
|
||||
background: #fff;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.collection-card__buy {
|
||||
border: 0;
|
||||
background: #9dd6c7;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.collection-card__add:disabled,
|
||||
.collection-card__buy:disabled {
|
||||
cursor: default;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.collection-card__info {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 5px;
|
||||
}
|
||||
|
||||
.collection-card__title {
|
||||
color: #000;
|
||||
font-size: 22px;
|
||||
font-weight: 700;
|
||||
line-height: normal;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.collection-card__subtitle,
|
||||
.collection-card__reviews,
|
||||
.collection-card__prices {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
.collection-card__subtitle {
|
||||
color: #808181;
|
||||
font-size: 18px;
|
||||
font-weight: 300;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.collection-card__rating {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.collection-card__stars {
|
||||
display: flex;
|
||||
gap: 1px;
|
||||
color: #000;
|
||||
}
|
||||
|
||||
.collection-card__star {
|
||||
display: block;
|
||||
width: 14px;
|
||||
height: 14px;
|
||||
}
|
||||
|
||||
.collection-card__star.is-off {
|
||||
opacity: 0.25;
|
||||
}
|
||||
|
||||
.collection-card__reviews {
|
||||
color: #000;
|
||||
font-size: 14px;
|
||||
font-weight: 300;
|
||||
}
|
||||
|
||||
.collection-card__prices {
|
||||
display: flex;
|
||||
align-items: baseline;
|
||||
gap: 16px;
|
||||
}
|
||||
|
||||
.collection-card__price,
|
||||
.collection-card__compare {
|
||||
font-size: 20px;
|
||||
line-height: normal;
|
||||
}
|
||||
|
||||
.collection-card__price {
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.collection-card__compare {
|
||||
color: #808181;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.recent .collection-card__title {
|
||||
font-size: 18px;
|
||||
}
|
||||
|
||||
.recent .collection-card__subtitle,
|
||||
.recent .collection-card__reviews {
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.recent .collection-card__price,
|
||||
.recent .collection-card__compare {
|
||||
font-size: 16px;
|
||||
}
|
||||
|
||||
.recent .collection-card__star {
|
||||
width: 10px;
|
||||
height: 10px;
|
||||
}
|
||||
|
||||
@media (max-width: 767px) {
|
||||
.collection-card {
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.collection-card__media {
|
||||
aspect-ratio: auto;
|
||||
overflow: visible;
|
||||
background: transparent;
|
||||
}
|
||||
|
||||
.collection-card__link {
|
||||
position: relative;
|
||||
aspect-ratio: 1;
|
||||
overflow: hidden;
|
||||
border-radius: 10px;
|
||||
background: #fff;
|
||||
}
|
||||
|
||||
.collection-card__image {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
}
|
||||
|
||||
.collection-card__actions {
|
||||
position: static;
|
||||
opacity: 1;
|
||||
pointer-events: auto;
|
||||
margin-top: 8px;
|
||||
}
|
||||
|
||||
.collection-card__add,
|
||||
.collection-card__buy {
|
||||
height: 36px;
|
||||
font-size: 11px;
|
||||
}
|
||||
|
||||
.collection-card__title,
|
||||
.recent .collection-card__title {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.collection-card__subtitle,
|
||||
.recent .collection-card__subtitle {
|
||||
font-size: 10px;
|
||||
}
|
||||
|
||||
.collection-card__price,
|
||||
.collection-card__compare,
|
||||
.recent .collection-card__price,
|
||||
.recent .collection-card__compare {
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.collection-card__reviews,
|
||||
.recent .collection-card__reviews {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.collection-card__wish {
|
||||
top: 8px;
|
||||
right: 8px;
|
||||
}
|
||||
|
||||
.collection-card__wish svg {
|
||||
width: 18px;
|
||||
height: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
@media (prefers-reduced-motion: reduce) {
|
||||
.collection-card__image--hover,
|
||||
.collection-card__actions {
|
||||
transition: none;
|
||||
}
|
||||
}
|
||||
{% endstylesheet %}
|
||||
|
||||
{% javascript %}
|
||||
(() => {
|
||||
if (window.__seasonCollectionCard) return;
|
||||
window.__seasonCollectionCard = true;
|
||||
|
||||
const wishlistKey = 'seasons-wishlist';
|
||||
|
||||
const readWishlist = () => {
|
||||
try {
|
||||
const stored = JSON.parse(window.localStorage.getItem(wishlistKey));
|
||||
return Array.isArray(stored) ? stored.map(String) : [];
|
||||
} catch (error) {
|
||||
return [];
|
||||
}
|
||||
};
|
||||
|
||||
const applyWishlist = () => {
|
||||
const saved = readWishlist();
|
||||
document.querySelectorAll('.collection-card [data-wishlist]').forEach((button) => {
|
||||
const active = saved.includes(String(button.dataset.productId));
|
||||
button.classList.toggle('is-active', active);
|
||||
button.setAttribute('aria-pressed', active ? 'true' : 'false');
|
||||
const label = active ? button.dataset.labelSaved : button.dataset.labelSave;
|
||||
if (label) button.setAttribute('aria-label', label);
|
||||
});
|
||||
};
|
||||
|
||||
applyWishlist();
|
||||
|
||||
document.addEventListener('click', (event) => {
|
||||
const wish = event.target.closest('.collection-card [data-wishlist]');
|
||||
if (!wish) return;
|
||||
const id = String(wish.dataset.productId || '');
|
||||
if (!id) return;
|
||||
const saved = readWishlist();
|
||||
const next = saved.includes(id) ? saved.filter((item) => item !== id) : saved.concat(id);
|
||||
window.localStorage.setItem(wishlistKey, JSON.stringify(next));
|
||||
applyWishlist();
|
||||
});
|
||||
|
||||
document.addEventListener('submit', async (event) => {
|
||||
const form = event.target;
|
||||
if (!(form instanceof HTMLFormElement) || !form.hasAttribute('data-collection-card')) return;
|
||||
if (event.defaultPrevented) return;
|
||||
|
||||
event.preventDefault();
|
||||
const button = event.submitter instanceof HTMLButtonElement ? event.submitter : form.querySelector('[type="submit"]');
|
||||
const variantId = form.querySelector('[name="id"]')?.value;
|
||||
if (!button || button.disabled || !variantId) return;
|
||||
|
||||
const buttons = [...form.querySelectorAll('button')];
|
||||
buttons.forEach((item) => {
|
||||
item.disabled = true;
|
||||
});
|
||||
const buyNow = button.hasAttribute('data-buy');
|
||||
|
||||
try {
|
||||
const addResponse = await fetch(`${form.action}.js`, {
|
||||
method: 'POST',
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
Accept: 'application/json',
|
||||
},
|
||||
body: JSON.stringify({ id: Number(variantId), quantity: 1 }),
|
||||
});
|
||||
|
||||
if (!addResponse.ok) {
|
||||
form.submit();
|
||||
return;
|
||||
}
|
||||
|
||||
if (buyNow) {
|
||||
window.location.href = `${window.Shopify?.routes?.root || '/'}checkout`;
|
||||
return;
|
||||
}
|
||||
|
||||
document.dispatchEvent(new CustomEvent('season:cart:open'));
|
||||
} catch (error) {
|
||||
form.submit();
|
||||
} finally {
|
||||
if (!buyNow) {
|
||||
buttons.forEach((item) => {
|
||||
item.disabled = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
});
|
||||
})();
|
||||
{% endjavascript %}
|
||||
@@ -1,14 +1,5 @@
|
||||
{% style %}
|
||||
{% # Loads all font variantions with display: swap %}
|
||||
{{ settings.type_primary_font | font_face: font_display: 'swap' }}
|
||||
{{ settings.type_primary_font | font_modify: 'weight', 'bold' | font_face: font_display: 'swap' }}
|
||||
{{ settings.type_primary_font | font_modify: 'weight', 'bold' | font_modify: 'style', 'italic' | font_face: font_display: 'swap' }}
|
||||
{{ settings.type_primary_font | font_modify: 'style', 'italic' | font_face: font_display: 'swap' }}
|
||||
|
||||
:root {
|
||||
--font-primary--family: {{ settings.type_primary_font.family }}, {{ settings.type_primary_font.fallback_families }};
|
||||
--font-primary--style: {{ settings.type_primary_font.style }};
|
||||
--font-primary--weight: {{ settings.type_primary_font.weight }};
|
||||
--page-width: {{ settings.max_page_width }};
|
||||
--page-margin: {{ settings.min_page_margin }}px;
|
||||
--color-background: {{ settings.background_color }};
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
{% doc %}
|
||||
Delays Shopify header scripts until the first interaction.
|
||||
Scripts tagged nolazy, plus JSON and JSON-LD blocks, stay immediate.
|
||||
|
||||
@param {string} html - Markup captured from content_for_header
|
||||
|
||||
@example
|
||||
{% capture shopify_header %}{{ content_for_header }}{% endcapture %}
|
||||
{% render 'delay-header-scripts', html: shopify_header %}
|
||||
{% enddoc %}
|
||||
|
||||
{% liquid
|
||||
if request.design_mode or html == blank
|
||||
echo html
|
||||
else
|
||||
assign chunks = html | split: '<script'
|
||||
for chunk in chunks
|
||||
if forloop.first
|
||||
echo chunk
|
||||
else
|
||||
assign open_tag = chunk | split: '>' | first
|
||||
if open_tag contains 'application/json' or open_tag contains 'application/ld+json' or open_tag contains 'nolazy'
|
||||
echo '<script'
|
||||
echo chunk
|
||||
elsif open_tag == blank
|
||||
echo '<script type="rocketlazyloadscript"'
|
||||
echo chunk
|
||||
else
|
||||
assign delayed_open = open_tag | replace: 'type="module"', 'data-rocket-type="module"' | replace: "type='module'", "data-rocket-type='module'"
|
||||
echo '<script type="rocketlazyloadscript"'
|
||||
echo delayed_open
|
||||
assign script_rest = chunk | remove_first: open_tag
|
||||
echo script_rest
|
||||
endif
|
||||
endif
|
||||
endfor
|
||||
endif
|
||||
%}
|
||||
@@ -0,0 +1,44 @@
|
||||
{% doc %}
|
||||
Loads the Archivo weights used by the storefront.
|
||||
|
||||
@example
|
||||
{% render 'font-faces' %}
|
||||
{% enddoc %}
|
||||
|
||||
<style>
|
||||
@font-face {
|
||||
font-family: Archivo;
|
||||
src: url('{{ 'archivo-light.ttf' | asset_url }}') format('truetype');
|
||||
font-weight: 300;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Archivo;
|
||||
src: url('{{ 'archivo-regular.ttf' | asset_url }}') format('truetype');
|
||||
font-weight: 400;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Archivo;
|
||||
src: url('{{ 'archivo-medium.ttf' | asset_url }}') format('truetype');
|
||||
font-weight: 500;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
@font-face {
|
||||
font-family: Archivo;
|
||||
src: url('{{ 'archivo-bold.ttf' | asset_url }}') format('truetype');
|
||||
font-weight: 700;
|
||||
font-style: normal;
|
||||
font-display: swap;
|
||||
}
|
||||
|
||||
body {
|
||||
font-family: Archivo, sans-serif;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,86 @@
|
||||
{% doc %}
|
||||
Renders one item of the storefront navigation.
|
||||
|
||||
Parent links with nested items include a submenu. The same markup is used
|
||||
on desktop and mobile.
|
||||
|
||||
@param {string} title - Link label
|
||||
@param {string} url - Link URL
|
||||
@param {link[]} [child_links] - Nested links from a menu
|
||||
@param {string} [child_menu] - Fallback items as `Label::/url`, separated by `|`
|
||||
@param {boolean} [show_caret] - Shows a decorative caret when there are no child links
|
||||
|
||||
@example
|
||||
{% render 'header-menu-item', title: link.title, url: link.url, child_links: link.links %}
|
||||
{% enddoc %}
|
||||
|
||||
{% liquid
|
||||
assign child_count = 0
|
||||
assign manual_items = blank
|
||||
|
||||
if child_links != blank and child_links.size > 0
|
||||
assign child_count = child_links.size
|
||||
elsif child_menu != blank
|
||||
assign manual_items = child_menu | strip | split: '|'
|
||||
assign child_count = manual_items.size
|
||||
endif
|
||||
%}
|
||||
|
||||
<li class="header__item relative flex items-center self-stretch gap-2.5" data-menu-item>
|
||||
<a
|
||||
class="text-[16px] font-medium uppercase leading-none text-black no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-4 focus-visible:outline-black"
|
||||
href="{{ url }}"
|
||||
>
|
||||
{{ title }}
|
||||
</a>
|
||||
|
||||
{% if child_count > 0 %}
|
||||
<button
|
||||
type="button"
|
||||
class="header__caret-button grid size-[10px] shrink-0 cursor-pointer appearance-none items-center justify-center border-0 bg-transparent p-0"
|
||||
data-submenu-toggle
|
||||
aria-expanded="false"
|
||||
aria-label="{{ 'header.submenu' | t: menu_title: title }}"
|
||||
>
|
||||
<span class="header__icon header__icon--caret" aria-hidden="true">
|
||||
{{ 'icon-caret-down.svg' | inline_asset_content }}
|
||||
</span>
|
||||
</button>
|
||||
<ul class="header__submenu absolute left-0 top-full z-30 m-0 hidden min-w-[260px] list-none bg-white px-5 py-4 shadow-[0_12px_40px_rgba(0,0,0,0.08)]">
|
||||
{% if child_links != blank and child_links.size > 0 %}
|
||||
{% for child in child_links %}
|
||||
<li>
|
||||
<a
|
||||
class="block py-2 text-[14px] font-medium uppercase leading-none text-black no-underline hover:text-brand-ink focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-black"
|
||||
href="{{ child.url }}"
|
||||
>
|
||||
{{ child.title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endfor %}
|
||||
{% else %}
|
||||
{% for item in manual_items %}
|
||||
{% liquid
|
||||
assign item_parts = item | split: '::'
|
||||
assign item_title = item_parts[0] | strip
|
||||
assign item_url = item_parts[1] | strip
|
||||
%}
|
||||
{% if item_title != blank %}
|
||||
<li>
|
||||
<a
|
||||
class="block py-2 text-[14px] font-medium uppercase leading-none text-black no-underline focus-visible:outline focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-black"
|
||||
href="{{ item_url }}"
|
||||
>
|
||||
{{ item_title }}
|
||||
</a>
|
||||
</li>
|
||||
{% endif %}
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% elsif show_caret %}
|
||||
<span class="header__icon header__icon--caret" aria-hidden="true">
|
||||
{{ 'icon-caret-down.svg' | inline_asset_content }}
|
||||
</span>
|
||||
{% endif %}
|
||||
</li>
|
||||
@@ -0,0 +1,53 @@
|
||||
{% doc %}
|
||||
Renders a featured product card for the homepage hero.
|
||||
|
||||
@param {product} product - Product to show in the card
|
||||
|
||||
@example
|
||||
{% render 'hero-product', product: block.settings.product %}
|
||||
{% enddoc %}
|
||||
|
||||
{% liquid
|
||||
assign variant = product.selected_or_first_available_variant
|
||||
assign card_image = product.featured_image
|
||||
assign image_alt = card_image.alt | default: product.title
|
||||
%}
|
||||
|
||||
<article class="hero__card">
|
||||
<a class="hero__card-media" href="{{ product.url }}">
|
||||
{% if card_image %}
|
||||
{{
|
||||
card_image
|
||||
| image_url: width: 200
|
||||
| image_tag:
|
||||
alt: image_alt,
|
||||
widths: '100, 140, 200',
|
||||
sizes: '(max-width: 1023px) 70px, 100px',
|
||||
class: 'hero__card-image',
|
||||
loading: 'eager'
|
||||
}}
|
||||
{% endif %}
|
||||
</a>
|
||||
|
||||
<div class="hero__card-copy">
|
||||
<a class="hero__card-title" href="{{ product.url }}">{{ product.title | escape }}</a>
|
||||
<p class="hero__card-price">{{ variant.price | money_without_trailing_zeros }}</p>
|
||||
</div>
|
||||
|
||||
{% form 'product', product, class: 'hero__form' %}
|
||||
<input type="hidden" name="id" value="{{ variant.id }}">
|
||||
<input type="hidden" name="quantity" value="1">
|
||||
<button
|
||||
class="hero__cart"
|
||||
type="submit"
|
||||
{% unless variant.available %}
|
||||
disabled
|
||||
{% endunless %}
|
||||
aria-label="{% if variant.available %}{{ 'hero.add_to_cart' | t: product: product.title }}{% else %}{{ 'hero.sold_out' | t }}{% endif %}"
|
||||
>
|
||||
<span class="hero__cart-icon" aria-hidden="true">
|
||||
{{ 'icon-bag.svg' | inline_asset_content }}
|
||||
</span>
|
||||
</button>
|
||||
{% endform %}
|
||||
</article>
|
||||
@@ -1,4 +1,5 @@
|
||||
<meta charset="utf-8">
|
||||
{% render 'rocket-delay' %}
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width,initial-scale=1">
|
||||
|
||||
|
||||
@@ -0,0 +1,440 @@
|
||||
{% doc %}
|
||||
Loads delayed scripts after the first pointer, key, or wheel interaction.
|
||||
A script keeps running immediately when it has the nolazy attribute.
|
||||
|
||||
@example
|
||||
{% render 'rocket-delay' %}
|
||||
{% enddoc %}
|
||||
|
||||
{% unless request.design_mode %}
|
||||
<script nolazy>
|
||||
(() => {
|
||||
const exemptScript = (script) => {
|
||||
if (!script || script.tagName !== 'SCRIPT') return true;
|
||||
if (script.hasAttribute('nolazy') || script.hasAttribute('data-nolazy')) return true;
|
||||
const type = script.getAttribute('type') || '';
|
||||
return type === 'application/json' || type === 'application/ld+json' || type === 'rocketlazyloadscript';
|
||||
};
|
||||
|
||||
const holdScript = (script) => {
|
||||
if (exemptScript(script)) return;
|
||||
const src = script.getAttribute('src');
|
||||
if (src) {
|
||||
script.setAttribute('data-rocket-src', src);
|
||||
script.removeAttribute('src');
|
||||
}
|
||||
script.setAttribute('type', 'rocketlazyloadscript');
|
||||
};
|
||||
|
||||
const holdTree = (node) => {
|
||||
if (!node || node.nodeType !== 1) return;
|
||||
holdScript(node);
|
||||
if (node.querySelectorAll) node.querySelectorAll('script').forEach(holdScript);
|
||||
};
|
||||
|
||||
new MutationObserver((mutations) => {
|
||||
mutations.forEach((mutation) => {
|
||||
mutation.addedNodes.forEach(holdTree);
|
||||
});
|
||||
}).observe(document.documentElement, { childList: true, subtree: true });
|
||||
|
||||
class RocketLazyLoadScripts {
|
||||
constructor() {
|
||||
this.triggerEvents = ['keydown', 'mousedown', 'mousemove', 'touchmove', 'touchstart', 'touchend', 'wheel'];
|
||||
this.userEventHandler = this._triggerListener.bind(this);
|
||||
this.touchStartHandler = this._onTouchStart.bind(this);
|
||||
this.touchMoveHandler = this._onTouchMove.bind(this);
|
||||
this.touchEndHandler = this._onTouchEnd.bind(this);
|
||||
this.clickHandler = this._onClick.bind(this);
|
||||
this.interceptedClicks = [];
|
||||
this.delayedScripts = { normal: [], async: [], defer: [] };
|
||||
this.trash = [];
|
||||
this.allJQueries = [];
|
||||
window.addEventListener('pageshow', (event) => {
|
||||
this.persisted = event.persisted;
|
||||
});
|
||||
window.addEventListener('DOMContentLoaded', () => {
|
||||
this._preconnect3rdParties();
|
||||
});
|
||||
}
|
||||
|
||||
_addUserInteractionListener(instance) {
|
||||
if (document.hidden) {
|
||||
instance._triggerListener();
|
||||
return;
|
||||
}
|
||||
this.triggerEvents.forEach((eventName) => window.addEventListener(eventName, instance.userEventHandler, { passive: true }));
|
||||
window.addEventListener('touchstart', instance.touchStartHandler, { passive: true });
|
||||
window.addEventListener('mousedown', instance.touchStartHandler);
|
||||
document.addEventListener('visibilitychange', instance.userEventHandler);
|
||||
}
|
||||
|
||||
_removeUserInteractionListener() {
|
||||
this.triggerEvents.forEach((eventName) => window.removeEventListener(eventName, this.userEventHandler, { passive: true }));
|
||||
document.removeEventListener('visibilitychange', this.userEventHandler);
|
||||
}
|
||||
|
||||
_onTouchStart(event) {
|
||||
if (event.target.tagName === 'HTML') return;
|
||||
window.addEventListener('touchend', this.touchEndHandler);
|
||||
window.addEventListener('mouseup', this.touchEndHandler);
|
||||
window.addEventListener('touchmove', this.touchMoveHandler, { passive: true });
|
||||
window.addEventListener('mousemove', this.touchMoveHandler);
|
||||
event.target.addEventListener('click', this.clickHandler);
|
||||
this._renameDOMAttribute(event.target, 'onclick', 'rocket-onclick');
|
||||
this._pendingClickStarted();
|
||||
}
|
||||
|
||||
_onTouchMove(event) {
|
||||
window.removeEventListener('touchend', this.touchEndHandler);
|
||||
window.removeEventListener('mouseup', this.touchEndHandler);
|
||||
window.removeEventListener('touchmove', this.touchMoveHandler, { passive: true });
|
||||
window.removeEventListener('mousemove', this.touchMoveHandler);
|
||||
event.target.removeEventListener('click', this.clickHandler);
|
||||
this._renameDOMAttribute(event.target, 'rocket-onclick', 'onclick');
|
||||
this._pendingClickFinished();
|
||||
}
|
||||
|
||||
_onTouchEnd() {
|
||||
window.removeEventListener('touchend', this.touchEndHandler);
|
||||
window.removeEventListener('mouseup', this.touchEndHandler);
|
||||
window.removeEventListener('touchmove', this.touchMoveHandler, { passive: true });
|
||||
window.removeEventListener('mousemove', this.touchMoveHandler);
|
||||
}
|
||||
|
||||
_onClick(event) {
|
||||
event.target.removeEventListener('click', this.clickHandler);
|
||||
this._renameDOMAttribute(event.target, 'rocket-onclick', 'onclick');
|
||||
this.interceptedClicks.push(event);
|
||||
event.preventDefault();
|
||||
event.stopPropagation();
|
||||
event.stopImmediatePropagation();
|
||||
this._pendingClickFinished();
|
||||
}
|
||||
|
||||
_replayClicks() {
|
||||
window.removeEventListener('touchstart', this.touchStartHandler, { passive: true });
|
||||
window.removeEventListener('mousedown', this.touchStartHandler);
|
||||
this.interceptedClicks.forEach((event) => {
|
||||
event.target.dispatchEvent(new MouseEvent('click', { view: event.view, bubbles: true, cancelable: true }));
|
||||
});
|
||||
}
|
||||
|
||||
_waitForPendingClicks() {
|
||||
return new Promise((resolve) => {
|
||||
if (this._isClickPending) this._pendingClickFinished = resolve;
|
||||
else resolve();
|
||||
});
|
||||
}
|
||||
|
||||
_pendingClickStarted() {
|
||||
this._isClickPending = true;
|
||||
}
|
||||
|
||||
_pendingClickFinished() {
|
||||
this._isClickPending = false;
|
||||
}
|
||||
|
||||
_renameDOMAttribute(node, from, to) {
|
||||
if (node.hasAttribute && node.hasAttribute(from)) {
|
||||
node.setAttribute(to, node.getAttribute(from));
|
||||
node.removeAttribute(from);
|
||||
}
|
||||
}
|
||||
|
||||
_triggerListener() {
|
||||
this._removeUserInteractionListener();
|
||||
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', this._loadEverythingNow.bind(this));
|
||||
else this._loadEverythingNow();
|
||||
}
|
||||
|
||||
_preconnect3rdParties() {
|
||||
const origins = [];
|
||||
document.querySelectorAll('script[type="rocketlazyloadscript"][data-rocket-src], script[type="rocketlazyloadscript"][src]').forEach((script) => {
|
||||
let src = script.getAttribute('data-rocket-src') || script.getAttribute('src');
|
||||
if (!src || src.indexOf('data:') === 0) return;
|
||||
if (src.indexOf('//') === 0) src = location.protocol + src;
|
||||
try {
|
||||
const origin = new URL(src, location.href).origin;
|
||||
if (origin !== location.origin) {
|
||||
origins.push({ src: origin, crossOrigin: script.crossOrigin || (script.getAttribute('data-rocket-type') === 'module') });
|
||||
}
|
||||
} catch (error) {
|
||||
origins.push(error);
|
||||
}
|
||||
});
|
||||
const unique = [...new Map(origins.filter((item) => item && item.src).map((item) => [item.src, item])).values()];
|
||||
this._batchInjectResourceHints(unique, 'preconnect');
|
||||
}
|
||||
|
||||
async _loadEverythingNow() {
|
||||
this.lastBreath = Date.now();
|
||||
this._delayEventListeners();
|
||||
this._delayJQueryReady();
|
||||
this._handleDocumentWrite();
|
||||
this._registerAllDelayedScripts();
|
||||
this._preloadAllScripts();
|
||||
await this._loadScriptsFromList(this.delayedScripts.normal);
|
||||
await this._loadScriptsFromList(this.delayedScripts.defer);
|
||||
await this._loadScriptsFromList(this.delayedScripts.async);
|
||||
try {
|
||||
await this._triggerDOMContentLoaded();
|
||||
await this._pendingWebpackRequests();
|
||||
await this._triggerWindowLoad();
|
||||
} catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
window.dispatchEvent(new Event('rocket-allScriptsLoaded'));
|
||||
this._waitForPendingClicks().then(() => {
|
||||
this._replayClicks();
|
||||
});
|
||||
this._emptyTrash();
|
||||
}
|
||||
|
||||
_isExempt(script) {
|
||||
if (script.hasAttribute('nolazy') || script.hasAttribute('data-nolazy')) return true;
|
||||
const type = script.getAttribute('type') || '';
|
||||
return type === 'application/json' || type === 'application/ld+json';
|
||||
}
|
||||
|
||||
_registerAllDelayedScripts() {
|
||||
document.querySelectorAll('script[type="rocketlazyloadscript"]').forEach((script) => {
|
||||
if (this._isExempt(script) || !script.isConnected) return;
|
||||
const src = script.getAttribute('data-rocket-src') || script.getAttribute('src');
|
||||
const moduleScript = script.getAttribute('data-rocket-type') === 'module';
|
||||
if (src) {
|
||||
if (script.hasAttribute('async') && script.async !== false) this.delayedScripts.async.push(script);
|
||||
else if (script.hasAttribute('defer') || moduleScript) this.delayedScripts.defer.push(script);
|
||||
else this.delayedScripts.normal.push(script);
|
||||
} else {
|
||||
this.delayedScripts.normal.push(script);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async _transformScript(script) {
|
||||
await this._littleBreath();
|
||||
if (script.noModule && 'noModule' in HTMLScriptElement.prototype) {
|
||||
script.setAttribute('data-rocket-status', 'skipped');
|
||||
return;
|
||||
}
|
||||
await new Promise((resolve) => {
|
||||
const next = document.createElement('script');
|
||||
[...script.attributes].forEach((attribute) => {
|
||||
let name = attribute.nodeName;
|
||||
if (name === 'type') return;
|
||||
if (name === 'data-rocket-type') name = 'type';
|
||||
if (name === 'data-rocket-src') name = 'src';
|
||||
next.setAttribute(name, attribute.nodeValue);
|
||||
});
|
||||
const src = script.getAttribute('data-rocket-src') || script.getAttribute('src');
|
||||
if (src) next.src = src;
|
||||
else if (script.text) next.text = script.text;
|
||||
if (next.src) {
|
||||
next.addEventListener('load', () => resolve());
|
||||
next.addEventListener('error', () => resolve());
|
||||
}
|
||||
try {
|
||||
script.parentNode.replaceChild(next, script);
|
||||
} catch (error) {
|
||||
resolve();
|
||||
return;
|
||||
}
|
||||
if (!next.src) resolve();
|
||||
});
|
||||
}
|
||||
|
||||
async _loadScriptsFromList(list) {
|
||||
const script = list.shift();
|
||||
if (!script || !script.isConnected) return;
|
||||
await this._transformScript(script);
|
||||
await this._loadScriptsFromList(list);
|
||||
}
|
||||
|
||||
_preloadAllScripts() {
|
||||
this._batchInjectResourceHints([...this.delayedScripts.normal, ...this.delayedScripts.defer, ...this.delayedScripts.async], 'preload');
|
||||
}
|
||||
|
||||
_batchInjectResourceHints(items, rel) {
|
||||
const fragment = document.createDocumentFragment();
|
||||
items.forEach((item) => {
|
||||
const src = (item.getAttribute && (item.getAttribute('data-rocket-src') || item.getAttribute('src'))) || item.src;
|
||||
if (!src) return;
|
||||
const link = document.createElement('link');
|
||||
link.href = src;
|
||||
link.rel = rel;
|
||||
if (rel !== 'preconnect') link.as = 'script';
|
||||
if (item.crossOrigin) link.crossOrigin = item.crossOrigin;
|
||||
if (item.getAttribute && item.getAttribute('data-rocket-type') === 'module') link.crossOrigin = 'anonymous';
|
||||
if (item.integrity) link.integrity = item.integrity;
|
||||
fragment.appendChild(link);
|
||||
this.trash.push(link);
|
||||
});
|
||||
document.head.appendChild(fragment);
|
||||
}
|
||||
|
||||
_delayEventListeners() {
|
||||
const registry = {};
|
||||
const wrapTarget = (target) => {
|
||||
if (registry[target]) return;
|
||||
registry[target] = {
|
||||
originalFunctions: { add: target.addEventListener, remove: target.removeEventListener },
|
||||
eventsToRewrite: [],
|
||||
};
|
||||
target.addEventListener = function addEventListener(...args) {
|
||||
args[0] = rename(args[0]);
|
||||
registry[target].originalFunctions.add.apply(target, args);
|
||||
};
|
||||
target.removeEventListener = function removeEventListener(...args) {
|
||||
args[0] = rename(args[0]);
|
||||
registry[target].originalFunctions.remove.apply(target, args);
|
||||
};
|
||||
function rename(eventName) {
|
||||
return registry[target].eventsToRewrite.indexOf(eventName) >= 0 ? `rocket-${eventName}` : eventName;
|
||||
}
|
||||
};
|
||||
const rewrite = (target, eventName) => {
|
||||
wrapTarget(target);
|
||||
registry[target].eventsToRewrite.push(eventName);
|
||||
};
|
||||
const delayProperty = (target, property) => {
|
||||
let value = target[property];
|
||||
Object.defineProperty(target, property, {
|
||||
get: () => value || function noop() {},
|
||||
set(next) {
|
||||
target[`rocket${property}`] = value = next;
|
||||
},
|
||||
});
|
||||
};
|
||||
rewrite(document, 'DOMContentLoaded');
|
||||
rewrite(window, 'DOMContentLoaded');
|
||||
rewrite(window, 'load');
|
||||
rewrite(window, 'pageshow');
|
||||
rewrite(document, 'readystatechange');
|
||||
delayProperty(document, 'onreadystatechange');
|
||||
delayProperty(window, 'onload');
|
||||
delayProperty(window, 'onpageshow');
|
||||
}
|
||||
|
||||
_delayJQueryReady() {
|
||||
let current;
|
||||
const renameLoad = (events) => events.split(' ').map((eventName) => (eventName === 'load' || eventName.indexOf('load.') === 0 ? 'rocket-jquery-load' : eventName)).join(' ');
|
||||
const patch = (jquery) => {
|
||||
if (!jquery || !jquery.fn || this.allJQueries.includes(jquery)) {
|
||||
current = jquery;
|
||||
return;
|
||||
}
|
||||
jquery.fn.ready = jquery.fn.init.prototype.ready = (callback) => {
|
||||
if (this.domReadyFired) callback.bind(document)(jquery);
|
||||
else document.addEventListener('rocket-DOMContentLoaded', () => callback.bind(document)(jquery));
|
||||
return jquery([]);
|
||||
};
|
||||
const originalOn = jquery.fn.on;
|
||||
jquery.fn.on = jquery.fn.init.prototype.on = function on(...args) {
|
||||
if (this[0] === window) {
|
||||
if (typeof args[0] === 'string') args[0] = renameLoad(args[0]);
|
||||
else if (args[0] && typeof args[0] === 'object') {
|
||||
Object.keys(args[0]).forEach((key) => {
|
||||
const handler = args[0][key];
|
||||
delete args[0][key];
|
||||
args[0][renameLoad(key)] = handler;
|
||||
});
|
||||
}
|
||||
}
|
||||
return originalOn.apply(this, args);
|
||||
};
|
||||
this.allJQueries.push(jquery);
|
||||
current = jquery;
|
||||
};
|
||||
patch(window.jQuery);
|
||||
Object.defineProperty(window, 'jQuery', {
|
||||
get: () => current,
|
||||
set: patch,
|
||||
});
|
||||
}
|
||||
|
||||
async _pendingWebpackRequests() {
|
||||
const script = document.querySelector('script[data-webpack]');
|
||||
if (!script) return;
|
||||
await new Promise((resolve) => {
|
||||
script.addEventListener('load', resolve);
|
||||
script.addEventListener('error', resolve);
|
||||
});
|
||||
await this._requestAnimFrame();
|
||||
await this._pendingWebpackRequests();
|
||||
}
|
||||
|
||||
async _triggerDOMContentLoaded() {
|
||||
this.domReadyFired = true;
|
||||
await this._littleBreath();
|
||||
document.dispatchEvent(new Event('rocket-DOMContentLoaded'));
|
||||
await this._littleBreath();
|
||||
window.dispatchEvent(new Event('rocket-DOMContentLoaded'));
|
||||
await this._littleBreath();
|
||||
document.dispatchEvent(new Event('rocket-readystatechange'));
|
||||
await this._littleBreath();
|
||||
if (document.rocketonreadystatechange) document.rocketonreadystatechange();
|
||||
}
|
||||
|
||||
async _triggerWindowLoad() {
|
||||
await this._littleBreath();
|
||||
window.dispatchEvent(new Event('rocket-load'));
|
||||
await this._littleBreath();
|
||||
if (window.rocketonload) window.rocketonload();
|
||||
await this._littleBreath();
|
||||
this.allJQueries.forEach((jquery) => jquery(window).trigger('rocket-jquery-load'));
|
||||
await this._littleBreath();
|
||||
const pageShow = new Event('rocket-pageshow');
|
||||
pageShow.persisted = this.persisted;
|
||||
window.dispatchEvent(pageShow);
|
||||
await this._littleBreath();
|
||||
if (window.rocketonpageshow) window.rocketonpageshow({ persisted: this.persisted });
|
||||
}
|
||||
|
||||
_handleDocumentWrite() {
|
||||
const nextSibling = new Map();
|
||||
const write = (markup) => {
|
||||
const current = document.currentScript;
|
||||
if (!current) return;
|
||||
const range = document.createRange();
|
||||
const parent = current.parentElement;
|
||||
let marker = nextSibling.get(current);
|
||||
if (marker === undefined) {
|
||||
marker = current.nextSibling;
|
||||
nextSibling.set(current, marker);
|
||||
}
|
||||
const fragment = document.createDocumentFragment();
|
||||
range.setStart(fragment, 0);
|
||||
fragment.appendChild(range.createContextualFragment(markup));
|
||||
parent.insertBefore(fragment, marker);
|
||||
};
|
||||
document.write = write;
|
||||
document.writeln = write;
|
||||
}
|
||||
|
||||
async _littleBreath() {
|
||||
if (Date.now() - this.lastBreath > 45) {
|
||||
await this._requestAnimFrame();
|
||||
this.lastBreath = Date.now();
|
||||
}
|
||||
}
|
||||
|
||||
async _requestAnimFrame() {
|
||||
if (document.hidden) await new Promise((resolve) => setTimeout(resolve));
|
||||
else await new Promise((resolve) => requestAnimationFrame(resolve));
|
||||
}
|
||||
|
||||
_emptyTrash() {
|
||||
this.trash.forEach((node) => node.remove());
|
||||
}
|
||||
|
||||
static run() {
|
||||
const instance = new RocketLazyLoadScripts();
|
||||
instance._addUserInteractionListener(instance);
|
||||
}
|
||||
}
|
||||
|
||||
RocketLazyLoadScripts.run();
|
||||
})();
|
||||
</script>
|
||||
{% endunless %}
|
||||
Reference in New Issue
Block a user