Skip to content

Commit 78d7930

Browse files
committed
Add lazyload js
1 parent 39666e4 commit 78d7930

File tree

4 files changed

+1315
-3
lines changed

4 files changed

+1315
-3
lines changed

ViewModel/ImageResize.php

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ public function getImage(string $imagePath, int $width, int $height, array $para
9090
/** @var string $placeholderImageUrl */
9191
$placeholderImageUrl = $this->resize->resizeAndGetUrl($placeholderImagePath, $width, $height, $resize);
9292

93+
/** @var string $mainImageUrl */
9394
$mainImageUrl = $this->resize->resizeAndGetUrl($imagePath, $width, $height, $resize);
9495
if ($mainImageUrl === '') {
9596
return '';
@@ -110,12 +111,14 @@ public function getImage(string $imagePath, int $width, int $height, array $para
110111
}
111112
}
112113

114+
/** @var string $mainSrcset */
115+
$mainSrcset = '';
113116
if ($retina) {
114-
$imageUrl = $this->resize->resizeAndGetUrl($imagePath, $width * 2, $height * 2, $resize);
115-
$mainImageUrl = $placeholderImageUrl . ' 1x, ' . $imageUrl . ' 2x';
117+
$imageUrl = $this->resize->resizeAndGetUrl($imagePath, $width * 2, $height * 2, $resize);
118+
$mainSrcset = $mainImageUrl . ' 1x, ' . $imageUrl . ' 2x';
116119
}
117120

118-
$html .= '<img alt="' . $alt . '" title="' . $title . '" class="' . $class . '" src="' . $placeholderImageUrl . '" data-src="' . $mainImageUrl . '" />';
121+
$html .= '<img alt="' . $alt . '" title="' . $title . '" class="' . $class . '" src="' . $placeholderImageUrl . '" data-src="' . $mainImageUrl . '" data-srcset="' . $mainSrcset . '"/>';
119122
$html .= '</picture>';
120123

121124
return $html;

view/frontend/requirejs-config.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var config = {
2+
map: {
3+
'*': {
4+
'intersectionObserverAmd': 'Web200_ImageResize/js/intersection-observer-amd',
5+
'lazyloadAmd': 'Web200_ImageResize/js/lazyload.amd'
6+
}
7+
}
8+
};

0 commit comments

Comments
 (0)