From 4a99b308abd062f4975a60a2e9f72dd216cd9ae6 Mon Sep 17 00:00:00 2001 From: vincent-peugnet Date: Thu, 26 Sep 2024 22:19:18 +0200 Subject: [PATCH] admin option for img lazy loading close #421 lazy loading is the default setting --- app/class/Config.php | 13 +++++++++++++ app/class/Servicerender.php | 2 +- app/view/templates/admin.php | 7 +++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/app/class/Config.php b/app/class/Config.php index 5259728e..b16b5dbb 100644 --- a/app/class/Config.php +++ b/app/class/Config.php @@ -54,6 +54,9 @@ abstract class Config /** Page version during creation */ protected static int $pageversion = Page::V1; + /** Indicate if img should have loading="lazy" attribute */ + protected static bool $lazyloadimg = true; + public const LANG_MIN = 2; public const LANG_MAX = 16; @@ -345,6 +348,11 @@ public static function pageversion(): int return self::$pageversion; } + public static function lazyloadimg(): bool + { + return self::$lazyloadimg; + } + // __________________________________________ S E T ______________________________________ @@ -590,4 +598,9 @@ public static function setpageversion($pageversion): void self::$pageversion = $pageversion; } } + + public static function setlazyloadimg($lazyloadimg): bool + { + return self::$lazyloadimg = boolval($lazyloadimg); + } } diff --git a/app/class/Servicerender.php b/app/class/Servicerender.php index 514bbe8a..f8e00e2e 100644 --- a/app/class/Servicerender.php +++ b/app/class/Servicerender.php @@ -462,7 +462,7 @@ protected function sourceparser(DOMNodeList $sourcables): void if (!empty($classes)) { $sourcable->setAttribute('class', implode(' ', array_unique($classes))); } - if ($sourcable->tagName === 'img') { + if ($sourcable->tagName === 'img' && Config::lazyloadimg()) { $sourcable->setAttribute('loading', 'lazy'); } } diff --git a/app/view/templates/admin.php b/app/view/templates/admin.php index 2b0d1ac7..328cea57 100644 --- a/app/view/templates/admin.php +++ b/app/view/templates/admin.php @@ -258,6 +258,13 @@

This can be overide individualy for each element using render options. See 📖 manual section for more infos.

+

Lazy load images

+ +
+ + form="admin"> + +

(Thoses modifications need re-rendering)