From 6677e75fcb69e819fa25b63e89e6897122dfcdd3 Mon Sep 17 00:00:00 2001 From: Cameron Date: Fri, 17 Apr 2020 12:02:10 -0700 Subject: [PATCH] toImage() Added support for native image lazy-loading. See https://addyosmani.com/blog/lazy-loading/ for more info. --- e107_handlers/e_parse_class.php | 7 ++++--- e107_tests/tests/unit/e_parseTest.php | 4 ++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/e107_handlers/e_parse_class.php b/e107_handlers/e_parse_class.php index bc7978e2a..3f0a3f3fb 100644 --- a/e107_handlers/e_parse_class.php +++ b/e107_handlers/e_parse_class.php @@ -4543,9 +4543,9 @@ class e_parser /** - * Render an tag. + * Render an img tag. * @param string $file - * @param array $parm legacy|w|h|alt|class|id|crop + * @param array $parm keys: legacy|w|h|alt|class|id|crop|loading * @param array $parm['legacy'] Usually a legacy path like {e_FILE} * @return string * @example $tp->toImage('welcome.png', array('legacy'=>{e_IMAGE}newspost_images/','w'=>200)); @@ -4655,8 +4655,9 @@ class e_parser $srcset = (!empty($parm['srcset'])) ? "srcset=\"".$parm['srcset']."\" " : ""; $width = (!empty($parm['w'])) ? "width=\"".intval($parm['w'])."\" " : ""; $height = (!empty($parm['h'])) ? "height=\"".intval($parm['h'])."\" " : ""; + $loading = !empty($parm['loading']) ? "loading=\"".$parm['loading']."\" " : ""; // eg. lazy, eager, auto - return "\"".$alt."\""; + return "\"".$alt."\""; } diff --git a/e107_tests/tests/unit/e_parseTest.php b/e107_tests/tests/unit/e_parseTest.php index 18d099540..74d07db25 100644 --- a/e107_tests/tests/unit/e_parseTest.php +++ b/e107_tests/tests/unit/e_parseTest.php @@ -822,6 +822,10 @@ TMP; $override = array('w'=>0, 'h'=>0); // display image without resizing $result3 = $this->tp->toImage($src, $override); $this->assertStringContainsString('Fbutterfly.jpg&w=0&h=0', $result3); // src + + $result4 = $this->tp->toImage($src, ['loading'=>'lazy']); + $this->assertStringContainsString('loading="lazy"', $result4); // src + } public function testThumbSrcSet()