shorten_expanded: remove loading=lazy from images if enabled

This commit is contained in:
Andrew Dolgov 2020-12-11 09:22:30 +03:00
parent 71c8d8d365
commit 43bd3394c3
2 changed files with 17 additions and 2 deletions

View File

@ -37,7 +37,7 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
c_inner.innerHTML = `<div class="content-shrink-wrap"> c_inner.innerHTML = `<div class="content-shrink-wrap">
${c_inner.innerHTML} ${c_inner.innerHTML}
${tmp.innerHTML}</div> ${tmp.innerHTML}</div>
<button dojoType="dijit.form.Button" class="alt-info expand-prompt" onclick="return Plugins.Shorten_Expanded.expand('${row.id}')" href="#"> <button dojoType="dijit.form.Button" class="alt-info expand-prompt" onclick="return Plugins.Shorten_Expanded.expand('${row.id}')" href="#">
${__("Click to expand article")}</button>`; ${__("Click to expand article")}</button>`;

View File

@ -11,6 +11,21 @@ class Shorten_Expanded extends Plugin {
function init($host) { function init($host) {
$this->host = $host; $this->host = $host;
$host->add_hook($host::HOOK_SANITIZE, $this);
}
// native lazy loading messes with plugin height calculation because images get loaded
// after headline is actually rendered (off screen) so we force disable it
function hook_sanitize($doc) {
$xpath = new DOMXPath($doc);
$entries = $xpath->query('(//*[@loading="lazy"])');
foreach ($entries as $entry) {
$entry->removeAttribute("loading");
}
return $doc;
} }
function get_css() { function get_css() {
@ -25,4 +40,4 @@ class Shorten_Expanded extends Plugin {
return 2; return 2;
} }
} }