From 3cdd02ed21a9292bca99e078f80665a49d132693 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Fromme?= Date: Sun, 26 Dec 2021 21:09:22 +0100 Subject: [PATCH] WIP Implement viewhelper for image lazyloading --- .../ViewHelpers/LazyLoadImageViewHelper.php | 47 +++++++++++++++++++ .../Resources/Private/Partials/Officetip.html | 13 ++--- .../Private/Partials/Product/Teaser.html | 12 +++-- .../Private/Partials/RegionMaps.html | 10 ++-- .../Resources/Private/Partials/Teamer.html | 8 ++-- .../Private/Partials/TeaserImage.html | 25 +++++----- 6 files changed, 83 insertions(+), 32 deletions(-) create mode 100644 public/typo3conf/ext/ep_theme/Classes/ViewHelpers/LazyLoadImageViewHelper.php diff --git a/public/typo3conf/ext/ep_theme/Classes/ViewHelpers/LazyLoadImageViewHelper.php b/public/typo3conf/ext/ep_theme/Classes/ViewHelpers/LazyLoadImageViewHelper.php new file mode 100644 index 00000000..37387929 --- /dev/null +++ b/public/typo3conf/ext/ep_theme/Classes/ViewHelpers/LazyLoadImageViewHelper.php @@ -0,0 +1,47 @@ +registerArgument('loaderimg', 'string', '', false); + } + + public function render(): string + { + parent::render(); + + $src = $this->tag->getAttribute('src'); + $this->tag->removeAttribute('src'); + $this->tag->addAttribute('data', ['src' => $src]); + + if (isset($this->arguments['loaderimg'])) { + $loaderImage = $this->imageService->getImage($this->arguments['loaderimg'], null, false); + $processingInstructions = [ + 'width' => $this->arguments['width'], + 'height' => $this->arguments['height'], + 'minWidth' => $this->arguments['minWidth'], + 'minHeight' => $this->arguments['minHeight'], + 'maxWidth' => $this->arguments['maxWidth'], + 'maxHeight' => $this->arguments['maxHeight'], + ]; + $processedLoaderImage = $this->imageService->applyProcessingInstructions($loaderImage, $processingInstructions); + $loaderImageUri = $this->imageService->getImageUri($processedLoaderImage, $this->arguments['absolute']); + $this->tag->addAttribute('src', $loaderImageUri); + } + + $classes = $this->tag->getAttribute('class'); + $classItems = GeneralUtility::trimExplode(' ', $classes, true); + $classItems[] = 'lazyload'; + $classes = implode(' ', array_unique($classItems)); + $this->tag->addAttribute('class', $classes); + + return $this->tag->render(); + } +} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Officetip.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Officetip.html index 6d7845e2..f65ecb58 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Officetip.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Officetip.html @@ -8,14 +8,11 @@
- - {officetip.author.name} - - - {officetip.author.name} - +
diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Product/Teaser.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Product/Teaser.html index 175e60c4..b58cd09d 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Product/Teaser.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Product/Teaser.html @@ -1,5 +1,6 @@ @@ -13,11 +14,12 @@
- {product.name} +
diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/RegionMaps.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/RegionMaps.html index 734266a7..a89168b3 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/RegionMaps.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/RegionMaps.html @@ -11,10 +11,12 @@ data-lightbox-index="{iteration.cycle}" data-lightbox-caption="Pistenplan {region.name}" title="Pistenplan {region.name}"> - {regionMap.alternative} +
diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Teamer.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Teamer.html index a8dd50c8..5a3647d8 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Teamer.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/Teamer.html @@ -7,9 +7,11 @@

- {teamerInCharge.name} + {teamerInCharge.name} diff --git a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/TeaserImage.html b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/TeaserImage.html index 83a2cf6f..9469bf85 100644 --- a/public/typo3conf/ext/ep_theme/Resources/Private/Partials/TeaserImage.html +++ b/public/typo3conf/ext/ep_theme/Resources/Private/Partials/TeaserImage.html @@ -16,12 +16,13 @@ - {image.alternative} + @@ -46,12 +47,12 @@ src: 'EXT:ep_theme/Resources/Public/images/header-winter.jpg', width: '350', height: '175c-100' )} 320w"/> - +