-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add option to opt-out of lazysizes
- Loading branch information
moritzlang
committed
Sep 23, 2022
1 parent
c9a0c63
commit 0c8ba51
Showing
3 changed files
with
34 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,30 @@ | ||
@php | ||
$use_lazysizes = config("statamic-image-renderer.lazy_loading", "lazysizes") === "lazysizes"; | ||
@endphp | ||
|
||
<picture> | ||
@foreach ($srcsets as $srcset) | ||
<source | ||
<source | ||
sizes="{{ $srcset["sizes"] }}" | ||
{{-- width="{{ $srcset["width"] }}" --}} | ||
{{-- height="{{ $srcset["height"] }}" --}} | ||
@if(!$loop->last) media="(min-width: {{ $srcset["min_width"] }}px)"@endif | ||
@if (!$loop->last) media="(min-width: {{ $srcset["min_width"] }}px)"@endif | ||
@if ($use_lazysizes) | ||
data-srcset="{{ $srcset["srcset"] }}" | ||
@else | ||
srcset="{{ $srcset["srcset"] }}" | ||
@endif | ||
/> | ||
@endforeach | ||
<img | ||
onload="this.style.backgroundColor = 'transparent';" | ||
onload="this.style.backgroundColor='transparent';@if(!$use_lazysizes)this.classList.remove('lazyload');this.classList.add('lazyloaded')@endif" | ||
loading="lazy" | ||
height="{{ $height }}" | ||
width="{{ $width }}" | ||
src="{{ $placeholder }}" | ||
data-src="{{ $placeholder }}" | ||
src="{{ $placeholder }}" | ||
@if ($use_lazysizes) | ||
data-src="{{ $placeholder }}" | ||
@endif | ||
class="lazyload {{ $class }}" | ||
style="background-color: {{ $dominant_color }};" | ||
alt="{{ $alt }}" | ||
alt="{{ $alt }}" | ||
/> | ||
</picture> |