mirror of
https://github.com/e107inc/e107.git
synced 2025-08-03 13:17:24 +02:00
toImage() Added support for native image lazy-loading. See https://addyosmani.com/blog/lazy-loading/ for more info.
This commit is contained in:
@@ -4543,9 +4543,9 @@ class e_parser
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Render an <img> tag.
|
* Render an img tag.
|
||||||
* @param string $file
|
* @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}
|
* @param array $parm['legacy'] Usually a legacy path like {e_FILE}
|
||||||
* @return string
|
* @return string
|
||||||
* @example $tp->toImage('welcome.png', array('legacy'=>{e_IMAGE}newspost_images/','w'=>200));
|
* @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']."\" " : "";
|
$srcset = (!empty($parm['srcset'])) ? "srcset=\"".$parm['srcset']."\" " : "";
|
||||||
$width = (!empty($parm['w'])) ? "width=\"".intval($parm['w'])."\" " : "";
|
$width = (!empty($parm['w'])) ? "width=\"".intval($parm['w'])."\" " : "";
|
||||||
$height = (!empty($parm['h'])) ? "height=\"".intval($parm['h'])."\" " : "";
|
$height = (!empty($parm['h'])) ? "height=\"".intval($parm['h'])."\" " : "";
|
||||||
|
$loading = !empty($parm['loading']) ? "loading=\"".$parm['loading']."\" " : ""; // eg. lazy, eager, auto
|
||||||
|
|
||||||
return "<img {$id}class='{$class}' src='".$path."' alt=\"".$alt."\" ".$srcset.$width.$height.$style." />";
|
return "<img {$id}class='{$class}' src='".$path."' alt=\"".$alt."\" ".$srcset.$width.$height.$style.$loading." />";
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -822,6 +822,10 @@ TMP;
|
|||||||
$override = array('w'=>0, 'h'=>0); // display image without resizing
|
$override = array('w'=>0, 'h'=>0); // display image without resizing
|
||||||
$result3 = $this->tp->toImage($src, $override);
|
$result3 = $this->tp->toImage($src, $override);
|
||||||
$this->assertStringContainsString('Fbutterfly.jpg&w=0&h=0', $result3); // src
|
$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()
|
public function testThumbSrcSet()
|
||||||
|
Reference in New Issue
Block a user