feat(widgets): FriendLinks aksrt_links_box + iframe lazy data-src

Route friend links through shared links_box styles; iframe embeds use
lazyload data-src and pagination.js now hydrates iframe/video lazies.
This commit is contained in:
2026-07-21 08:59:27 +08:00
parent dff9d7dc1c
commit 8e3b86a21b
3 changed files with 173 additions and 91 deletions
+46 -42
View File
@@ -275,23 +275,49 @@
});
}
function activateLazyEl(el) {
var src = el.dataset.src;
if (!src) return;
var tag = (el.tagName || "").toLowerCase();
if (tag === "iframe" || tag === "video") {
el.src = src;
el.classList.remove("aksrt-lazy", "lazyload");
el.classList.add("aksrt-loaded", "lazyloaded");
return;
}
// img path with optional skeleton + decode
var tempImg = new Image();
tempImg.onload = function () {
el.src = src;
el.classList.remove("aksrt-lazy", "lazyload");
el.classList.add("aksrt-loaded", "lazyloaded");
var skeleton = el.previousElementSibling;
if (skeleton && skeleton.classList.contains("aksrt-skeleton")) {
skeleton.remove();
}
};
tempImg.onerror = function () {
el.classList.remove("aksrt-lazy", "lazyload");
el.classList.add("aksrt-error");
var skeleton = el.previousElementSibling;
if (skeleton && skeleton.classList.contains("aksrt-skeleton")) {
skeleton.remove();
}
};
tempImg.src = src;
}
function initLazyLoad(root) {
var scope = root || document;
var lazyImages = scope.querySelectorAll("img.aksrt-lazy");
if (!lazyImages.length) return;
// Images + iframes/videos that use data-src (zibll lazyload / aksrt-lazy).
var lazyEls = scope.querySelectorAll(
"img.aksrt-lazy, iframe.aksrt-lazy, iframe.lazyload, video.aksrt-lazy, video.lazyload"
);
if (!lazyEls.length) return;
if (!("IntersectionObserver" in window)) {
lazyImages.forEach(function (img) {
var src = img.dataset.src;
if (src) {
img.src = src;
img.classList.remove("aksrt-lazy");
img.classList.add("aksrt-loaded");
}
var skeleton = img.previousElementSibling;
if (skeleton && skeleton.classList.contains("aksrt-skeleton")) {
skeleton.remove();
}
lazyEls.forEach(function (el) {
activateLazyEl(el);
});
return;
}
@@ -299,43 +325,21 @@
var observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
var img = entry.target;
var src = img.dataset.src;
if (!src) {
observer.unobserve(img);
var el = entry.target;
if (!el.dataset.src) {
observer.unobserve(el);
return;
}
var tempImg = new Image();
tempImg.onload = function () {
img.src = src;
img.classList.remove("aksrt-lazy");
img.classList.add("aksrt-loaded");
var skeleton = img.previousElementSibling;
if (skeleton && skeleton.classList.contains("aksrt-skeleton")) {
skeleton.remove();
}
};
tempImg.onerror = function () {
img.classList.remove("aksrt-lazy");
img.classList.add("aksrt-error");
var skeleton = img.previousElementSibling;
if (skeleton && skeleton.classList.contains("aksrt-skeleton")) {
skeleton.remove();
}
};
tempImg.src = src;
observer.unobserve(img);
activateLazyEl(el);
observer.unobserve(el);
});
}, {
rootMargin: "200px 0px",
threshold: 0.01
});
lazyImages.forEach(function (img) {
observer.observe(img);
lazyEls.forEach(function (el) {
observer.observe(el);
});
}