feat(frontend): replace lazy loading with zibll lazysizes

This commit is contained in:
2026-08-18 01:33:38 +08:00
parent 02571eecd6
commit 435ee1daa7
78 changed files with 1515 additions and 909 deletions
+1
View File
@@ -16,6 +16,7 @@
!/tests/widget-system/
/tests/widget-system/*
!/tests/widget-system/post-visual-contract.test.cjs
!/tests/widget-system/lazyload-contract.test.cjs
!/tests/visual/docker-compose.zibll.yml
!/tests/visual/zibll-Caddyfile
!/tests/visual/README.md
@@ -1,21 +1,24 @@
const themeRoot = typeof window !== 'undefined' && window.aksrtAdminData?.themeUri
? String(window.aksrtAdminData.themeUri).replace(/\/$/, '')
: ''
const defaultThumbnail = themeRoot ? `${themeRoot}/assets/img/thumbnail.svg` : ''
export const commonSchema = {
key: 'global.common',
title: '常用功能',
icon: 'fas fa-cog',
description: '管理站点常用开关、懒加载与备案信息等基础配置。',
defaults: {
lazyload_enabled: true,
lazyload_animation: 'blur',
lazyload_placeholder: '',
lazyload_blur: true,
lazyload_avatar: true,
lazyload_content: false,
lazyload_comment: true,
lazyload_private: true,
lazyload_slider: true,
lazyload_cover: true,
lazyload_other: true,
lazyload_widget: true,
lazy_posts_thumb: true,
lazy_avatar: true,
lazy_posts_content: false,
lazy_comment: true,
lazy_private: true,
lazy_sider: true,
lazy_cover: true,
lazy_other: true,
lazy_animation: 'blur',
thumbnail: defaultThumbnail,
icp_filing: '',
police_filing: '',
footer_text: '',
@@ -26,9 +29,9 @@ export const commonSchema = {
title: '性能优化',
icon: 'fas fa-tachometer-alt',
fields: [
{ key: 'lazyload_enabled', label: '图片懒加载', type: 'switch', default: true, help: '开启后页面中的图片将在滚动到可见区域时才加载' },
{ key: 'lazy_posts_thumb', label: '文章缩略图懒加载', type: 'switch', default: true, help: '滚动到图像附近时再加载真实图片。' },
{
key: 'lazyload_animation',
key: 'lazy_animation',
label: '懒加载动画',
type: 'select',
default: 'blur',
@@ -37,10 +40,8 @@ export const commonSchema = {
{ label: '淡入', value: 'fade' },
{ label: '缩放', value: 'scale' },
],
dependsOn: { key: 'lazyload_enabled', value: true },
},
{ key: 'lazyload_placeholder', label: '预载图', type: 'media', default: '', dependsOn: { key: 'lazyload_enabled', value: true }, help: '自定义占位图,留空使用内置默认' },
{ key: 'lazyload_blur', label: '模糊预览', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true }, help: '加载前显示低分辨率模糊预览' },
{ key: 'thumbnail', label: '懒加载预载图', type: 'media', default: defaultThumbnail, help: '图片加载前显示的占位图。' },
],
},
{
@@ -48,14 +49,13 @@ export const commonSchema = {
title: '懒加载范围',
icon: 'fas fa-layer-group',
fields: [
{ key: 'lazyload_avatar', label: '头像懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_content', label: '文章内容图片懒加载', type: 'switch', default: false, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_comment', label: '评论内容图片懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_private', label: '私信聊天图片懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_slider', label: '幻灯片图片懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_cover', label: '封面图片懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_other', label: '其它图片懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazyload_widget', label: '小工具图片懒加载', type: 'switch', default: true, dependsOn: { key: 'lazyload_enabled', value: true } },
{ key: 'lazy_avatar', label: '头像懒加载', type: 'switch', default: true },
{ key: 'lazy_posts_content', label: '文章内容图片懒加载', type: 'switch', default: false },
{ key: 'lazy_comment', label: '评论内容图片懒加载', type: 'switch', default: true },
{ key: 'lazy_private', label: '私信聊天图片懒加载', type: 'switch', default: true },
{ key: 'lazy_sider', label: '幻灯片图片懒加载', type: 'switch', default: true },
{ key: 'lazy_cover', label: '封面图片懒加载', type: 'switch', default: true },
{ key: 'lazy_other', label: '其它图片懒加载', type: 'switch', default: true },
],
},
{
@@ -69,53 +69,34 @@
}
}
/* ============================================================
* 14. 图片懒加载 blur-to-sharp 过渡
* 模仿 zibll 的 lazy_blur 效果
* ============================================================ */
img.lazyload,
img.lazyloaded,
img[data-src] {
transition: filter 0.6s var(--ease), opacity 0.4s var(--ease);
/* Zibll lazySizes state and animation contract. */
.lazyloaded {
transition: 0.3s;
--lazy-animation: lazy_blur;
}
img.lazyload,
img[data-src] {
filter: blur(5px);
opacity: 0.7;
.lazyloaded.img-icon {
--lazy-animation: lazy_fade;
}
img.lazyloaded {
filter: blur(0);
opacity: 1;
img.lazyloaded:not(.lazyloadafter) {
-webkit-animation: var(--lazy-animation) 0.6s;
animation: var(--lazy-animation) 0.6s;
}
/* 14b. aksrt-lazy 动画变体(按 lazyload_animation 配置切换) */
@keyframes aksrt-lazy-blur {
from { filter: blur(8px); opacity: 0.6; }
to { filter: blur(0); opacity: 1; }
}
@keyframes aksrt-lazy-fade {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes aksrt-lazy-scale {
from { transform: scale(1.08); opacity: 0.8; }
to { transform: scale(1); opacity: 1; }
@keyframes lazy_blur {
0% { filter: blur(5px); }
100% { filter: blur(0); }
}
img.aksrt-lazy {
transition: filter 0.5s var(--ease), opacity 0.5s var(--ease), transform 0.5s var(--ease);
@keyframes lazy_fade {
0% { opacity: 0; }
100% { opacity: 1; }
}
img.aksrt-loaded[data-lazy-animation="blur"] {
animation: aksrt-lazy-blur 0.6s ease both;
}
img.aksrt-loaded[data-lazy-animation="fade"] {
animation: aksrt-lazy-fade 0.6s ease both;
}
img.aksrt-loaded[data-lazy-animation="scale"] {
animation: aksrt-lazy-scale 0.5s ease both;
@keyframes lazy_scale {
0% { transform: scale(1.1); }
80% { transform: unset; }
}
/* ============================================================
@@ -308,21 +289,6 @@ input:focus, textarea:focus, select:focus,
animation: aksrtPopIn var(--dur-fast) var(--ease-out) forwards;
}
/* --- 图片懒加载过渡 --- */
img.lazyload, img.lazyloaded, img[data-src] {
transition: filter 0.6s var(--ease), opacity 0.4s var(--ease);
}
img.lazyload, img[data-src] {
filter: blur(5px);
opacity: 0.7;
}
img.lazyloaded {
filter: blur(0);
opacity: 1;
}
/* --- 滚动进度条动效 --- */
.reading-progress-bar {
transition: width 0.1s linear;
@@ -43,35 +43,6 @@
object-fit: cover;
}
/* Lazy preloader */
.new-swiper .swiper-lazy-preloader {
position: absolute;
top: 50%;
left: 50%;
width: 42px;
height: 42px;
margin: -21px 0 0 -21px;
border: 3px solid rgba(255, 255, 255, 0.3);
border-top-color: #fff;
border-radius: 50%;
animation: aksrt-swiper-spin 0.8s linear infinite;
}
@keyframes aksrt-swiper-spin {
from { transform: rotate(0deg); }
to { transform: rotate(360deg); }
}
.new-swiper .swiper-lazy {
opacity: 0;
transition: opacity 0.3s;
}
.new-swiper .swiper-lazy.lazyloaded,
.new-swiper .swiper-slide-visible .swiper-lazy {
opacity: 1;
}
.new-swiper .pagination-thumbnail-item {
width: 60px;
height: 40px;
@@ -256,21 +256,6 @@
flex-shrink: 0;
}
/* 懒加载骨架 */
.cat-card__banner .aksrt-skeleton {
position: absolute;
inset: 0;
}
.cat-card__banner img.aksrt-lazy {
opacity: 0;
transition: opacity 0.3s ease;
}
.cat-card__banner img.aksrt-loaded {
opacity: 1;
}
/* 响应式 */
@media (max-width: 767px) {
.cat-cards-grid {
@@ -291,4 +276,3 @@
/* ============================================================
* Phase 5: 运营型模块样式
* ============================================================ */
@@ -15,21 +15,6 @@
0. ANIMATIONS
================================================================ */
@keyframes aksrt-lazy-blur {
from { filter: blur(5px); opacity: 0.6; }
to { filter: blur(0); opacity: 1; }
}
@keyframes aksrt-lazy-fade {
from { opacity: 0; }
to { opacity: 1; }
}
@keyframes aksrt-lazy-scale {
from { transform: scale(1.1); opacity: 0.8; }
to { transform: scale(1); opacity: 1; }
}
@keyframes aksrt-skeleton-pulse {
0%, 100% { opacity: 1; }
50% { opacity: 0.4; }
@@ -55,14 +40,6 @@
transition: color 0.2s, background 0.3s, opacity 0.3s, box-shadow 0.3s, transform 0.3s;
}
.aksrt-homepage img.aksrt-loaded {
animation: aksrt-lazy-blur 0.6s ease;
}
.aksrt-homepage img.aksrt-loaded.img-icon {
animation: aksrt-lazy-fade 0.6s ease;
}
.aksrt-homepage .aksrt-skeleton {
animation: aksrt-skeleton-pulse 1.5s ease-in-out infinite;
}
@@ -177,13 +177,6 @@ html.dark #index-tab-main > .posts-item.list:hover {
transform: scale(1.02);
}
.aksrt-homepage__posts > .posts-item.list .item-thumbnail .aksrt-skeleton {
position: absolute;
inset: 0;
background: var(--surface-2, #eee);
border-radius: inherit;
}
.aksrt-homepage__posts > .posts-item.list .item-thumbnail .img-badge {
position: absolute;
top: 8px;
@@ -230,7 +223,6 @@ html.dark #index-tab-main > .posts-item.list:hover {
border-radius: var(--radius, 8px);
}
.aksrt-homepage__posts > .posts-item.list.mult-thumb .thumb-items > span .aksrt-skeleton,
.aksrt-homepage__posts > .posts-item.list.mult-thumb .thumb-items > span > img {
position: absolute;
inset: 0;
-16
View File
@@ -26,21 +26,6 @@
text-decoration: underline;
}
/* 分类推荐懒加载骨架 */
.category-recommend-card__hero .aksrt-skeleton {
position: absolute;
inset: 0;
}
.category-recommend-card__hero img.aksrt-lazy {
opacity: 0;
transition: opacity 0.3s ease;
}
.category-recommend-card__hero img.aksrt-loaded {
opacity: 1;
}
/* 分类推荐响应式 */
@media (max-width: 767px) {
.category-recommend {
@@ -121,4 +106,3 @@
line-height: var(--leading-relaxed, 1.7);
color: var(--color-ink-3);
}
-21
View File
@@ -734,27 +734,6 @@
});
});
// Lazy images
root.querySelectorAll('img.aksrt-lazy[data-src]').forEach(function (img) {
if (img.classList.contains('aksrt-loaded')) return;
if ('IntersectionObserver' in window) {
var obs = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
img.src = img.dataset.src;
img.classList.remove('aksrt-lazy');
img.classList.add('aksrt-loaded');
obs.unobserve(img);
});
}, { rootMargin: '200px' });
obs.observe(img);
} else {
img.src = img.dataset.src;
img.classList.remove('aksrt-lazy');
img.classList.add('aksrt-loaded');
}
});
// Swiper re-init
if (typeof Swiper !== 'undefined') {
root.querySelectorAll('[data-swiper-config]:not(.swiper-initialized)').forEach(function (el) {
+26 -120
View File
@@ -31,9 +31,10 @@
var failed = false;
var loadMoreBtn = container.querySelector(".aksrt-load-more-btn, .ajax-next");
var indicator = container.querySelector(".aksrt-loading-indicator");
var observer = null;
var iasEnabled = false;
var successfulAutoLoads = 0;
var iasMax = isComment
? ((window.aksrtData && typeof aksrtData.commentIasMax !== "undefined") ? parseInt(aksrtData.commentIasMax, 10) : 0)
: ((window.aksrtData && typeof aksrtData.iasMax !== "undefined") ? parseInt(aksrtData.iasMax, 10) : 0);
var homepagePanel = container.closest("[data-home-tab-panel]");
var target = homepagePanel || container.previousElementSibling;
if (!homepagePanel && target && target.classList && target.classList.contains("content-stream__footer")) {
@@ -65,11 +66,6 @@
}
function stopInfinite(markNomore) {
if (observer) {
observer.disconnect();
observer = null;
}
iasEnabled = false;
container.classList.remove("ias-pending");
if (markNomore && loadMoreBtn) {
loadMoreBtn.textContent = nomoreText;
@@ -177,8 +173,6 @@
successfulAutoLoads++;
}
if (typeof initLazyLoad === "function") initLazyLoad(target);
if (nextPage > maxPages || !res.data.has_more) {
stopInfinite(true);
if (!loadMoreBtn) {
@@ -198,6 +192,17 @@
if (loadMoreBtn && !loadMoreBtn.classList.contains("ajax-nomore") && !failed) {
loadMoreBtn.classList.remove("is-loading");
loadMoreBtn.textContent = triggerText;
if (mode === "infinite") {
if (iasMax > 0 && successfulAutoLoads >= iasMax) {
stopInfinite(true);
} else {
loadMoreBtn.classList.remove("lazyloaded", "lazyloading");
loadMoreBtn.classList.add("lazyload");
if (window.lazySizes && lazySizes.loader) {
lazySizes.loader.checkElems();
}
}
}
}
});
}
@@ -227,127 +232,28 @@
window.location.href = archiveUrl.toString();
return;
}
var fromAuto = loadMoreBtn.dataset.lazyAuto === "1";
delete loadMoreBtn.dataset.lazyAuto;
if (fromAuto && iasMax > 0 && successfulAutoLoads >= iasMax) {
stopInfinite(true);
return;
}
// Manual click can recover from a previous auto-load failure.
failed = false;
loadNextPage(false);
loadNextPage(fromAuto);
});
}
if (mode === "infinite" && "IntersectionObserver" in window) {
if (isComment && window.aksrtData && aksrtData.commentIasAuto === false) {
if (mode === "infinite") {
if ((isComment && window.aksrtData && aksrtData.commentIasAuto === false) || !hasAjaxConfig()) {
loadMoreBtn.classList.remove("lazyload");
loadMoreBtn.removeAttribute("lazyload-action");
return;
}
if (!hasAjaxConfig()) {
return;
}
var sentinel = document.createElement("div");
sentinel.className = "aksrt-scroll-sentinel";
container.appendChild(sentinel);
var lazyloadAction = container.dataset.lazyloadAction || "";
var iasMax = isComment
? ((window.aksrtData && typeof aksrtData.commentIasMax !== "undefined") ? parseInt(aksrtData.commentIasMax, 10) : 0)
: ((window.aksrtData && typeof aksrtData.iasMax !== "undefined") ? parseInt(aksrtData.iasMax, 10) : 0);
observer = new IntersectionObserver(
function (entries) {
if (!iasEnabled || failed) return;
if (!(entries[0] && entries[0].isIntersecting) || loading) return;
if (iasMax > 0 && successfulAutoLoads >= iasMax) {
stopInfinite(true);
return;
}
loadNextPage(true);
},
{ rootMargin: "200px" }
);
if (lazyloadAction === "ias") {
container.classList.add("ias-pending");
}
// Policy A: do not auto-fire on first paint; wait for real user scroll.
var enableOnScroll = function () {
if (iasEnabled || failed) return;
iasEnabled = true;
container.classList.remove("ias-pending");
observer.observe(sentinel);
};
window.addEventListener("scroll", enableOnScroll, { passive: true, once: true });
window.addEventListener("touchmove", enableOnScroll, { passive: true, once: true });
window.addEventListener("wheel", enableOnScroll, { passive: true, once: true });
container.classList.add("ias-pending");
}
});
}
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;
// 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)) {
lazyEls.forEach(function (el) {
activateLazyEl(el);
});
return;
}
var observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
if (!entry.isIntersecting) return;
var el = entry.target;
if (!el.dataset.src) {
observer.unobserve(el);
return;
}
activateLazyEl(el);
observer.unobserve(el);
});
}, {
rootMargin: "200px 0px",
threshold: 0.01
});
lazyEls.forEach(function (el) {
observer.observe(el);
});
}
window.AksrtFrontend.register("aksrt-ajax-pagination", function (root) { initAjaxPagination(root); });
window.AksrtFrontend.register("aksrt-lazy-load", function (root) { initLazyLoad(root); });
})();
+2 -6
View File
@@ -191,7 +191,6 @@
spaceBetween: spaceBetween,
parallax: parallax,
effect: effect,
lazy: { loadPrevNext: true },
autoplay: autoplay,
speed: speed,
pagination: pagination,
@@ -199,9 +198,6 @@
keyboard: keyboard,
a11y: { prevSlideMessage: "上一张", nextSlideMessage: "下一张" },
on: {
lazyImageReady: function (slideEl, imageEl) {
if (imageEl) imageEl.classList.add("lazyloaded");
},
slideChange: function () {
el.querySelectorAll(".aksrt-dplayer, video").forEach(function (media) {
if (media.pause) media.pause();
@@ -238,7 +234,7 @@
var img = slide.querySelector("img");
var src = img ? (img.dataset.src || img.src) : "";
if (src) {
return '<div class="' + className + '"><img class="aksrt-tilt-thumb" src="' + src + '"></div>';
return '<div class="' + className + '"><img' + window.aksrtGetLazyImageAttr('lazy_sider', src, 'aksrt-tilt-thumb') + ' alt=""></div>';
}
return "";
};
@@ -379,4 +375,4 @@
}
window.AksrtFrontend.register("aksrt-hero-slider", function () { initHeroSlider(); });
})();
})();
+1 -1
View File
@@ -597,7 +597,7 @@
var item = document.createElement('button');
item.type = 'button';
item.className = 'uc-transfer-user';
item.innerHTML = '<img src="' + (u.avatar || '') + '" alt="" class="uc-transfer-user__avatar"><span>' + (u.display_name || u.user_login) + '</span><span class="muted-2-color em09">@' + (u.user_login || '') + '</span>';
item.innerHTML = '<img' + window.aksrtGetLazyImageAttr('lazy_avatar', u.avatar || '', 'uc-transfer-user__avatar', 'sm') + ' alt=""><span>' + (u.display_name || u.user_login) + '</span><span class="muted-2-color em09">@' + (u.user_login || '') + '</span>';
item.addEventListener('click', function () {
if (recipientInput) recipientInput.value = String(u.id);
if (selected) selected.textContent = '已选择:' + (u.display_name || u.user_login);
+1 -1
View File
@@ -106,7 +106,7 @@
var currentZoom = 1;
var autoplayTimer = null;
var isAutoplay = false;
var EXCLUDE_SEL = '.no-imgbox,.no-lightbox,.avatar,.img-icon,.avatar-badge,.smilie-icon,.aksrt-avatar,.aksrt-lazy-skeleton';
var EXCLUDE_SEL = '.no-imgbox,.no-lightbox,.avatar,.img-icon,.avatar-badge,.smilie-icon,.aksrt-avatar';
var TRIGGER_SEL = '.entry-content img, .wp-posts-content img, .aksrt-lightbox-trigger img, [data-aksrt-lightbox] img, .imgbox-container img, .comment-content .box-img img, a[data-imgbox] img';
var CONTAINER_SEL = '.entry-content, .wp-posts-content, .aksrt-lightbox-trigger, [data-aksrt-lightbox], .imgbox-container, .comment-content';
var MAX_ZOOM_DESKTOP = 2;
+3 -26
View File
@@ -276,32 +276,9 @@
/** Generic remote-box / lazyload-action=ias (zibll-compatible). */
function bindRemoteBoxes(root) {
(root || document).querySelectorAll("[remote-box]").forEach(function (box) {
var form = box.closest("form");
if (form) {
form.addEventListener(
"mouseenter",
function () {
loadRemote(box);
},
{ once: true }
);
form.addEventListener(
"focusin",
function () {
loadRemote(box);
},
{ once: true }
);
}
if ("requestIdleCallback" in window) {
requestIdleCallback(function () {
loadRemote(box);
});
} else {
setTimeout(function () {
loadRemote(box);
}, 600);
}
if (box.dataset.aksrtRemoteBound === "1") return;
box.dataset.aksrtRemoteBound = "1";
box.addEventListener("click", function () { loadRemote(box); });
});
}
-48
View File
@@ -226,53 +226,6 @@
return wrapper;
}
function hydrateLazyImages(scope) {
var lazyImages = (scope || document).querySelectorAll('img.aksrt-lazy');
if (!lazyImages.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();
});
return;
}
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); 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);
});
}, { rootMargin: '200px 0px', threshold: 0.01 });
lazyImages.forEach(function (img) { observer.observe(img); });
}
/**
* Hydrate a panel after AJAX content injection.
* Sets data-view, re-binds lazy images, and dispatches events.
@@ -285,7 +238,6 @@
postsContainer.setAttribute('data-view', viewMode || getDefaultView());
}
hydrateLazyImages(panel);
dispatchRenderedEvent(panel, {
viewMode: viewMode || getDefaultView(),
panel: panel.getAttribute('data-home-tab-panel') || ''
+870
View File
@@ -0,0 +1,870 @@
//lazySizes
(function (window, factory) {
var lazySizes = factory(window, window.document, Date);
window.lazySizes = lazySizes;
if (typeof module == 'object' && module.exports) {
module.exports = lazySizes;
}
})(typeof window != 'undefined' ? window : {}, function l(window, document, Date) {
// Pass in the windoe Date function also for SSR because the Date class can be lost
'use strict';
/*jshint eqnull:true */
var lazysizes, lazySizesCfg;
(function () {
var prop;
var lazySizesDefaults = {
lazyClass: 'lazyload',
loadedClass: 'lazyloaded',
loadingClass: 'lazyloading',
preloadClass: 'lazypreload',
loadafterClass: 'lazyloadafter',
errorClass: 'lazyerror',
//strictClass: 'lazystrict',
autosizesClass: 'lazyautosizes',
srcAttr: 'data-src',
srcsetAttr: 'data-srcset',
sizesAttr: 'data-sizes',
//preloadAfterLoad: false,
minSize: 40,
customMedia: {},
init: true,
expFactor: 1.5,
hFac: 0.8,
loadMode: 2,
loadHidden: true,
ricTimeout: 0,
throttleDelay: 125,
};
lazySizesCfg = window.lazySizesConfig || window.lazysizesConfig || {};
for (prop in lazySizesDefaults) {
if (!(prop in lazySizesCfg)) {
lazySizesCfg[prop] = lazySizesDefaults[prop];
}
}
})();
if (!document || !document.getElementsByClassName) {
return {
init: function () {},
cfg: lazySizesCfg,
noSupport: true,
};
}
var docElem = document.documentElement;
var supportPicture = window.HTMLPictureElement;
var _addEventListener = 'addEventListener';
var _getAttribute = 'getAttribute';
/**
* Update to bind to window because 'this' becomes null during SSR
* builds.
*/
var addEventListener = window[_addEventListener].bind(window);
var setTimeout = window.setTimeout;
var requestAnimationFrame = window.requestAnimationFrame || setTimeout;
var requestIdleCallback = window.requestIdleCallback;
var regPicture = /^picture$/i;
var loadEvents = ['load', 'error', 'lazyincluded', '_lazyloaded'];
var regClassCache = {};
var forEach = Array.prototype.forEach;
var hasClass = function (ele, cls) {
if (!regClassCache[cls]) {
regClassCache[cls] = new RegExp('(\\s|^)' + cls + '(\\s|$)');
}
return regClassCache[cls].test(ele[_getAttribute]('class') || '') && regClassCache[cls];
};
var addClass = function (ele, cls) {
if (!hasClass(ele, cls)) {
ele.setAttribute('class', (ele[_getAttribute]('class') || '').trim() + ' ' + cls);
}
};
var removeClass = function (ele, cls) {
var reg;
if ((reg = hasClass(ele, cls))) {
ele.setAttribute('class', (ele[_getAttribute]('class') || '').replace(reg, ' '));
}
};
var addRemoveLoadEvents = function (dom, fn, add) {
var action = add ? _addEventListener : 'removeEventListener';
if (add) {
addRemoveLoadEvents(dom, fn);
}
loadEvents.forEach(function (evt) {
dom[action](evt, fn);
});
};
var triggerEvent = function (elem, name, detail, noBubbles, noCancelable) {
var event = document.createEvent('Event');
if (!detail) {
detail = {};
}
detail.instance = lazysizes;
event.initEvent(name, !noBubbles, !noCancelable);
event.detail = detail;
elem.dispatchEvent(event);
return event;
};
var updatePolyfill = function (el, full) {
var polyfill;
if (!supportPicture && (polyfill = window.picturefill || lazySizesCfg.pf)) {
if (full && full.src && !el[_getAttribute]('srcset')) {
el.setAttribute('srcset', full.src);
}
polyfill({ reevaluate: true, elements: [el] });
} else if (full && full.src) {
el.src = full.src;
}
};
var getCSS = function (elem, style) {
return (getComputedStyle(elem, null) || {})[style];
};
var getWidth = function (elem, parent, width) {
width = width || elem.offsetWidth;
while (width < lazySizesCfg.minSize && parent && !elem._lazysizesWidth) {
width = parent.offsetWidth;
parent = parent.parentNode;
}
return width;
};
var rAF = (function () {
var running, waiting;
var firstFns = [];
var secondFns = [];
var fns = firstFns;
var run = function () {
var runFns = fns;
fns = firstFns.length ? secondFns : firstFns;
running = true;
waiting = false;
while (runFns.length) {
runFns.shift()();
}
running = false;
};
var rafBatch = function (fn, queue) {
if (running && !queue) {
fn.apply(this, arguments);
} else {
fns.push(fn);
if (!waiting) {
waiting = true;
(document.hidden ? setTimeout : requestAnimationFrame)(run);
}
}
};
rafBatch._lsFlush = run;
return rafBatch;
})();
var rAFIt = function (fn, simple) {
return simple
? function () {
rAF(fn);
}
: function () {
var that = this;
var args = arguments;
rAF(function () {
fn.apply(that, args);
});
};
};
var throttle = function (fn) {
var running;
var lastTime = 0;
var gDelay = lazySizesCfg.throttleDelay;
var rICTimeout = lazySizesCfg.ricTimeout;
var run = function () {
running = false;
lastTime = Date.now();
fn();
};
var idleCallback =
requestIdleCallback && rICTimeout > 49
? function () {
requestIdleCallback(run, { timeout: rICTimeout });
if (rICTimeout !== lazySizesCfg.ricTimeout) {
rICTimeout = lazySizesCfg.ricTimeout;
}
}
: rAFIt(function () {
setTimeout(run);
}, true);
return function (isPriority) {
var delay;
if ((isPriority = isPriority === true)) {
rICTimeout = 33;
}
if (running) {
return;
}
running = true;
delay = gDelay - (Date.now() - lastTime);
if (delay < 0) {
delay = 0;
}
if (isPriority || delay < 9) {
idleCallback();
} else {
setTimeout(idleCallback, delay);
}
};
};
//based on http://modernjavascript.blogspot.de/2013/08/building-better-debounce.html
var debounce = function (func) {
var timeout, timestamp;
var wait = 99;
var run = function () {
timeout = null;
func();
};
var later = function () {
var last = Date.now() - timestamp;
if (last < wait) {
setTimeout(later, wait - last);
} else {
(requestIdleCallback || run)(run);
}
};
return function () {
timestamp = Date.now();
if (!timeout) {
timeout = setTimeout(later, wait);
}
};
};
var loader = (function () {
var preloadElems, isCompleted, resetPreloadingTimer, loadMode, started;
var eLvW, elvH, eLtop, eLleft, eLright, eLbottom, isBodyHidden;
var regImg = /^img$/i;
var regIframe = /^iframe$/i;
var supportScroll = 'onscroll' in window && !/(gle|ing)bot/.test(navigator.userAgent);
var shrinkExpand = 0;
var currentExpand = 0;
var isLoading = 0;
var lowRuns = -1;
var resetPreloading = function (e) {
isLoading--;
if (!e || isLoading < 0 || !e.target) {
isLoading = 0;
}
};
var isVisible = function (elem) {
if (isBodyHidden == null) {
isBodyHidden = getCSS(document.body, 'visibility') == 'hidden';
}
return isBodyHidden || !(getCSS(elem.parentNode, 'visibility') == 'hidden' && getCSS(elem, 'visibility') == 'hidden');
};
var isNestedVisible = function (elem, elemExpand) {
var outerRect;
var parent = elem;
var visible = isVisible(elem);
eLtop -= elemExpand;
eLbottom += elemExpand;
eLleft -= elemExpand;
eLright += elemExpand;
while (visible && (parent = parent.offsetParent) && parent != document.body && parent != docElem) {
visible = (getCSS(parent, 'opacity') || 1) > 0;
if (visible && getCSS(parent, 'overflow') != 'visible') {
outerRect = parent.getBoundingClientRect();
visible = eLright > outerRect.left && eLleft < outerRect.right && eLbottom > outerRect.top - 1 && eLtop < outerRect.bottom + 1;
}
}
return visible;
};
var checkElements = function () {
var eLlen, i, rect, autoLoadElem, loadedSomething, elemExpand, elemNegativeExpand, elemExpandVal, beforeExpandVal, defaultExpand, preloadExpand, hFac;
var lazyloadElems = lazysizes.elements;
if ((loadMode = lazySizesCfg.loadMode) && isLoading < 8 && (eLlen = lazyloadElems.length)) {
i = 0;
lowRuns++;
for (; i < eLlen; i++) {
if (!lazyloadElems[i] || lazyloadElems[i]._lazyRace) {
continue;
}
if (!supportScroll || (lazysizes.prematureUnveil && lazysizes.prematureUnveil(lazyloadElems[i]))) {
unveilElement(lazyloadElems[i]);
continue;
}
if (!(elemExpandVal = lazyloadElems[i][_getAttribute]('data-expand')) || !(elemExpand = elemExpandVal * 1)) {
elemExpand = currentExpand;
}
if (!defaultExpand) {
defaultExpand = !lazySizesCfg.expand || lazySizesCfg.expand < 1 ? (docElem.clientHeight > 500 && docElem.clientWidth > 500 ? 500 : 370) : lazySizesCfg.expand;
lazysizes._defEx = defaultExpand;
preloadExpand = defaultExpand * lazySizesCfg.expFactor;
hFac = lazySizesCfg.hFac;
isBodyHidden = null;
if (currentExpand < preloadExpand && isLoading < 1 && lowRuns > 2 && loadMode > 2 && !document.hidden) {
currentExpand = preloadExpand;
lowRuns = 0;
} else if (loadMode > 1 && lowRuns > 1 && isLoading < 6) {
currentExpand = defaultExpand;
} else {
currentExpand = shrinkExpand;
}
}
if (beforeExpandVal !== elemExpand) {
eLvW = innerWidth + elemExpand * hFac;
elvH = innerHeight + elemExpand;
elemNegativeExpand = elemExpand * -1;
beforeExpandVal = elemExpand;
}
rect = lazyloadElems[i].getBoundingClientRect();
if ((eLbottom = rect.bottom) >= elemNegativeExpand && (eLtop = rect.top) <= elvH && (eLright = rect.right) >= elemNegativeExpand * hFac && (eLleft = rect.left) <= eLvW && (eLbottom || eLright || eLleft || eLtop) && (lazySizesCfg.loadHidden || isVisible(lazyloadElems[i])) && ((isCompleted && isLoading < 3 && !elemExpandVal && (loadMode < 3 || lowRuns < 4)) || isNestedVisible(lazyloadElems[i], elemExpand))) {
unveilElement(lazyloadElems[i]);
loadedSomething = true;
if (isLoading > 9) {
break;
}
} else if (!loadedSomething && isCompleted && !autoLoadElem && isLoading < 4 && lowRuns < 4 && loadMode > 2 && (preloadElems[0] || lazySizesCfg.preloadAfterLoad) && (preloadElems[0] || (!elemExpandVal && (eLbottom || eLright || eLleft || eLtop || lazyloadElems[i][_getAttribute](lazySizesCfg.sizesAttr) != 'auto')))) {
autoLoadElem = preloadElems[0] || lazyloadElems[i];
}
}
if (autoLoadElem && !loadedSomething) {
unveilElement(autoLoadElem);
}
}
};
var throttledCheckElements = throttle(checkElements);
var switchLoadingClass = function (e) {
var elem = e.target;
if (elem._lazyCache) {
delete elem._lazyCache;
return;
}
resetPreloading(e);
addClass(elem, lazySizesCfg.loadedClass);
removeClass(elem, lazySizesCfg.loadingClass);
addRemoveLoadEvents(elem, rafSwitchLoadingClass);
triggerEvent(elem, 'lazyloaded');
//添加loadafterClass,防止后期二次触发动画
setTimeout(function () {
addClass(elem, lazySizesCfg.loadafterClass);
}, 700);
};
var rafedSwitchLoadingClass = rAFIt(switchLoadingClass);
var rafSwitchLoadingClass = function (e) {
rafedSwitchLoadingClass({ target: e.target });
};
var changeIframeSrc = function (elem, src) {
try {
elem.contentWindow.location.replace(src);
} catch (e) {
elem.src = src;
}
};
var handleSources = function (source) {
var customMedia;
var sourceSrcset = source[_getAttribute](lazySizesCfg.srcsetAttr);
if ((customMedia = lazySizesCfg.customMedia[source[_getAttribute]('data-media') || source[_getAttribute]('media')])) {
source.setAttribute('media', customMedia);
}
if (sourceSrcset) {
source.setAttribute('srcset', sourceSrcset);
}
};
var lazyUnveil = rAFIt(function (elem, detail, isAuto, sizes, isImg) {
var src, srcset, parent, isPicture, event, firesLoad;
if (!(event = triggerEvent(elem, 'lazybeforeunveil', detail)).defaultPrevented) {
if (sizes) {
if (isAuto) {
addClass(elem, lazySizesCfg.autosizesClass);
} else {
elem.setAttribute('sizes', sizes);
}
}
srcset = elem[_getAttribute](lazySizesCfg.srcsetAttr);
src = elem[_getAttribute](lazySizesCfg.srcAttr);
if (isImg) {
parent = elem.parentNode;
isPicture = parent && regPicture.test(parent.nodeName || '');
}
firesLoad = detail.firesLoad || ('src' in elem && (srcset || src || isPicture));
event = { target: elem };
addClass(elem, lazySizesCfg.loadingClass);
if (firesLoad) {
clearTimeout(resetPreloadingTimer);
resetPreloadingTimer = setTimeout(resetPreloading, 2500);
addRemoveLoadEvents(elem, rafSwitchLoadingClass, true);
}
if (isPicture) {
forEach.call(parent.getElementsByTagName('source'), handleSources);
}
if (srcset) {
elem.setAttribute('srcset', srcset);
} else if (src && !isPicture) {
if (regIframe.test(elem.nodeName)) {
changeIframeSrc(elem, src);
} else {
elem.src = src;
}
}
if (isImg && (srcset || isPicture)) {
updatePolyfill(elem, { src: src });
}
}
if (elem._lazyRace) {
delete elem._lazyRace;
}
removeClass(elem, lazySizesCfg.lazyClass);
rAF(function () {
// Part of this can be removed as soon as this fix is older: https://bugs.chromium.org/p/chromium/issues/detail?id=7731 (2015)
var isLoaded = elem.complete && elem.naturalWidth > 1;
if (!firesLoad || isLoaded) {
if (isLoaded) {
addClass(elem, 'ls-is-cached');
}
switchLoadingClass(event);
elem._lazyCache = true;
setTimeout(function () {
if ('_lazyCache' in elem) {
delete elem._lazyCache;
}
}, 9);
}
if (elem.loading == 'lazy') {
isLoading--;
}
}, true);
});
var unveilElement = function (elem) {
if (elem._lazyRace) {
return;
}
var detail;
var isImg = regImg.test(elem.nodeName);
//allow using sizes="auto", but don't use. it's invalid. Use data-sizes="auto" or a valid value for sizes instead (i.e.: sizes="80vw")
var sizes = isImg && (elem[_getAttribute](lazySizesCfg.sizesAttr) || elem[_getAttribute]('sizes'));
var isAuto = sizes == 'auto';
if ((isAuto || !isCompleted) && isImg && (elem[_getAttribute]('src') || elem.srcset) && !elem.complete && !hasClass(elem, lazySizesCfg.errorClass) && hasClass(elem, lazySizesCfg.lazyClass)) {
return;
}
detail = triggerEvent(elem, 'lazyunveilread').detail;
if (isAuto) {
autoSizer.updateElem(elem, true, elem.offsetWidth);
}
elem._lazyRace = true;
isLoading++;
lazyUnveil(elem, detail, isAuto, sizes, isImg);
};
var afterScroll = debounce(function () {
lazySizesCfg.loadMode = 3;
throttledCheckElements();
});
var altLoadmodeScrollListner = function () {
if (lazySizesCfg.loadMode == 3) {
lazySizesCfg.loadMode = 2;
}
afterScroll();
};
var onload = function () {
if (isCompleted) {
return;
}
if (Date.now() - started < 999) {
setTimeout(onload, 999);
return;
}
isCompleted = true;
lazySizesCfg.loadMode = 3;
throttledCheckElements();
addEventListener('scroll', altLoadmodeScrollListner, true);
};
return {
_: function () {
started = Date.now();
lazysizes.elements = document.getElementsByClassName(lazySizesCfg.lazyClass);
preloadElems = document.getElementsByClassName(lazySizesCfg.lazyClass + ' ' + lazySizesCfg.preloadClass);
addEventListener('scroll', throttledCheckElements, true);
addEventListener('resize', throttledCheckElements, true);
addEventListener('pageshow', function (e) {
if (e.persisted) {
var loadingElements = document.querySelectorAll('.' + lazySizesCfg.loadingClass);
if (loadingElements.length && loadingElements.forEach) {
requestAnimationFrame(function () {
loadingElements.forEach(function (img) {
if (img.complete) {
unveilElement(img);
}
});
});
}
}
});
if (window.MutationObserver) {
new MutationObserver(throttledCheckElements).observe(docElem, { childList: true, subtree: true, attributes: true });
} else {
docElem[_addEventListener]('DOMNodeInserted', throttledCheckElements, true);
docElem[_addEventListener]('DOMAttrModified', throttledCheckElements, true);
setInterval(throttledCheckElements, 999);
}
addEventListener('hashchange', throttledCheckElements, true);
//, 'fullscreenchange'
['focus', 'mouseover', 'click', 'load', 'transitionend', 'animationend'].forEach(function (name) {
document[_addEventListener](name, throttledCheckElements, true);
});
if (/d$|^c/.test(document.readyState)) {
onload();
} else {
addEventListener('load', onload);
document[_addEventListener]('DOMContentLoaded', throttledCheckElements);
setTimeout(onload, 20000);
}
if (lazysizes.elements.length) {
checkElements();
rAF._lsFlush();
} else {
throttledCheckElements();
}
},
checkElems: throttledCheckElements,
unveil: unveilElement,
_aLSL: altLoadmodeScrollListner,
};
})();
var autoSizer = (function () {
var autosizesElems;
var sizeElement = rAFIt(function (elem, parent, event, width) {
var sources, i, len;
elem._lazysizesWidth = width;
width += 'px';
elem.setAttribute('sizes', width);
if (regPicture.test(parent.nodeName || '')) {
sources = parent.getElementsByTagName('source');
for (i = 0, len = sources.length; i < len; i++) {
sources[i].setAttribute('sizes', width);
}
}
if (!event.detail.dataAttr) {
updatePolyfill(elem, event.detail);
}
});
var getSizeElement = function (elem, dataAttr, width) {
var event;
var parent = elem.parentNode;
if (parent) {
width = getWidth(elem, parent, width);
event = triggerEvent(elem, 'lazybeforesizes', { width: width, dataAttr: !!dataAttr });
if (!event.defaultPrevented) {
width = event.detail.width;
if (width && width !== elem._lazysizesWidth) {
sizeElement(elem, parent, event, width);
}
}
}
};
var updateElementsSizes = function () {
var i;
var len = autosizesElems.length;
if (len) {
i = 0;
for (; i < len; i++) {
getSizeElement(autosizesElems[i]);
}
}
};
var debouncedUpdateElementsSizes = debounce(updateElementsSizes);
return {
_: function () {
autosizesElems = document.getElementsByClassName(lazySizesCfg.autosizesClass);
addEventListener('resize', debouncedUpdateElementsSizes);
},
checkElems: debouncedUpdateElementsSizes,
updateElem: getSizeElement,
};
})();
var init = function () {
if (!init.i && document.getElementsByClassName) {
init.i = true;
autoSizer._();
loader._();
}
};
setTimeout(function () {
if (lazySizesCfg.init) {
init();
}
});
lazysizes = {
cfg: lazySizesCfg,
autoSizer: autoSizer,
loader: loader,
init: init,
uP: updatePolyfill,
aC: addClass,
rC: removeClass,
hC: hasClass,
fire: triggerEvent,
gW: getWidth,
rAF: rAF,
};
return lazysizes;
});
/**
* AKSRT integration for Zibll's lazySizes runtime.
* Normalizes dynamic markup without creating a second media loader.
*/
(function (window, document) {
'use strict';
function normalize(root) {
var scope = root && root.querySelectorAll ? root : document;
scope.querySelectorAll('img,iframe,video,[data-bg],[lazyload-action]').forEach(function (element) {
var hasLazySource = element.hasAttribute('data-src') || element.hasAttribute('data-srcset');
if (element.tagName === 'VIDEO' && element.querySelector('source[data-src],source[data-srcset]')) {
hasLazySource = true;
}
if ((hasLazySource || element.hasAttribute('data-bg') || element.hasAttribute('lazyload-action')) &&
!element.classList.contains('lazyloaded') && !element.classList.contains('lazyloading')) {
element.classList.add('lazyload');
}
});
}
function escapeAttribute(value) {
return String(value == null ? '' : value)
.replace(/&/g, '&amp;')
.replace(/"/g, '&quot;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;');
}
window.aksrtGetLazyImageAttr = function (key, src, className, size) {
var config = window.aksrtData || {};
var scopes = config.lazyScopes || {};
var classes = String(className || '').trim();
var realSrc = escapeAttribute(src);
if (!src || scopes[key] === false) {
return ' class="' + escapeAttribute(classes) + '" src="' + realSrc + '"';
}
var thumbs = config.lazyThumbs || {};
var placeholder = key === 'lazy_avatar'
? (config.lazyAvatar || thumbs.sm || '')
: (thumbs[size || 'default'] || thumbs.default || '');
return ' class="lazyload ' + escapeAttribute(classes) + '" src="' + escapeAttribute(placeholder) + '" data-src="' + realSrc + '"';
};
document.addEventListener('lazybeforeunveil', function (event) {
var element = event.target;
var action = element.getAttribute('lazyload-action');
window.setTimeout(function () {
if (action === 'ias') {
if (element.hasAttribute('remote-box')) {
element.click();
} else {
var trigger = element.matches('.ajax-next,.ias-btn')
? element
: element.querySelector('.ajax-next,.ias-btn');
if (trigger) {
trigger.setAttribute('no-scroll', 'true');
trigger.dataset.lazyAuto = '1';
trigger.click();
}
}
} else if (action === 'animated') {
var animation = element.getAttribute('data-animated');
if (animation) {
element.classList.add('animated', animation);
element.style.visibility = '';
}
}
}, 200);
var background = element.getAttribute('data-bg');
if (background) {
element.style.backgroundImage = 'url("' + background.replace(/"/g, '\\"') + '")';
}
if (element.tagName === 'VIDEO') {
var changed = false;
var poster = element.getAttribute('data-poster');
if (poster) {
element.setAttribute('poster', poster);
}
element.querySelectorAll('source[data-src],source[data-srcset]').forEach(function (source) {
var src = source.getAttribute('data-src');
var srcset = source.getAttribute('data-srcset');
if (src) {
source.setAttribute('src', src);
changed = true;
}
if (srcset) {
source.setAttribute('srcset', srcset);
changed = true;
}
});
if (changed) {
event.detail.firesLoad = true;
element.load();
}
}
});
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function () { normalize(document); });
} else {
normalize(document);
}
new MutationObserver(function (records) {
records.forEach(function (record) {
record.addedNodes.forEach(function (node) {
if (node.nodeType !== 1) return;
normalize(node);
});
});
}).observe(document.documentElement, { childList: true, subtree: true });
window.aksrtNormalizeLazyMedia = normalize;
})(window, document);
+2 -2
View File
@@ -81,7 +81,7 @@
html += '<strong class="aksrt-order-detail__hero-amount">' + formatMoney(order) + "</strong></div>";
html += '<div class="aksrt-order-detail__product">';
html += image
? '<img class="aksrt-order-detail__thumb" src="' + escapeHtml(image) + '" alt="">'
? '<img' + window.aksrtGetLazyImageAttr('lazy_posts_thumb', image, 'aksrt-order-detail__thumb') + ' alt="">'
: '<span class="aksrt-order-detail__thumb aksrt-order-detail__thumb--empty"><i class="fas fa-book-open"></i></span>';
html += '<div><strong class="aksrt-order-detail__product-title">' + escapeHtml(title) + "</strong>";
html += '<span class="aksrt-order-detail__product-meta">' + escapeHtml(order.product_type_label || "") + "</span></div></div>";
@@ -174,7 +174,7 @@
function cardHtml(order) {
var image = order.image
? '<img class="aksrt-orders-page__card-img" src="' + escapeHtml(order.image) + '" alt="">'
? '<img' + window.aksrtGetLazyImageAttr('lazy_posts_thumb', order.image, 'aksrt-orders-page__card-img') + ' alt="">'
: '<div class="aksrt-orders-page__card-art" aria-hidden="true"><i class="fas fa-book-open"></i></div>';
var countdown = Number(order.time_left || 0) > 0
? '<span class="aksrt-orders-page__countdown" data-aksrt-order-countdown="' + Number(order.time_left) + '"></span>'
+1 -1
View File
@@ -288,7 +288,7 @@
items.forEach(function (item) {
html += '<a class="aksrt-doc-index-card" href="' + this.escHtml(item.url) + '" data-cat-id="' + (item.cat_id || 0) + '">';
if (item.thumbnail) {
html += '<img class="aksrt-doc-index-card__thumb" src="' + this.escHtml(item.thumbnail) + '" alt="" loading="lazy">';
html += '<img' + window.aksrtGetLazyImageAttr('lazy_other', item.thumbnail, 'aksrt-doc-index-card__thumb') + ' alt="">';
}
html += '<div class="aksrt-doc-index-card__body">';
html += '<h3 class="aksrt-doc-index-card__title">' + this.escHtml(item.title) + '</h3>';
+7 -5
View File
@@ -17,6 +17,12 @@
return el;
}
function lazyImage(key, src, className, size) {
var template = document.createElement("template");
template.innerHTML = "<img" + window.aksrtGetLazyImageAttr(key, src, className, size) + ' alt="" decoding="async">';
return template.content.firstElementChild;
}
function append(parent, child) {
if (child) parent.appendChild(child);
return child;
@@ -299,11 +305,7 @@
var levelInfo = levels[String(level)] || {};
var levelHeader = node("div", "aksrt-vip-level-header");
if (levelInfo.img_icon) {
var levelIcon = node("img", "aksrt-vip-level-icon");
levelIcon.src = text(levelInfo.img_icon);
levelIcon.alt = "";
levelIcon.loading = "lazy";
levelIcon.decoding = "async";
var levelIcon = lazyImage("lazy_other", text(levelInfo.img_icon), "aksrt-vip-level-icon");
append(levelHeader, levelIcon);
}
append(levelHeader, node("div", "v-name font-bold", group.name || levelInfo.name || "VIP" + level));
+2 -2
View File
@@ -45,7 +45,7 @@
var icon = item && item.icon_url ? String(item.icon_url) : '';
var label = item && item.label ? String(item.label) : '';
if (icon) {
return '<img class="medal-icon img-icon' + (className ? ' ' + className : '') + '" src="' + escapeHtml(icon) + '" alt="' + escapeHtml(label) + '" title="' + escapeHtml(label) + '" loading="lazy" decoding="async">';
return '<img' + window.aksrtGetLazyImageAttr('lazy_other', icon, 'medal-icon img-icon' + (className ? ' ' + className : '')) + ' alt="' + escapeHtml(label) + '" title="' + escapeHtml(label) + '" decoding="async">';
}
return '<span class="medal-icon medal-icon--fa' + (className ? ' ' + className : '') + '"><i class="fas fa-award" aria-hidden="true"></i></span>';
}
@@ -131,7 +131,7 @@
return '<div class="medal-modal medal-modal--single">' +
'<div class="uc-badges-detail__head"><button type="button" class="uc-badges-back" data-aksrt-badges-back><i class="fas fa-angle-left" aria-hidden="true"></i> 返回列表</button></div>' +
'<div class="medal-single-card"><div class="medal-single-bg"><img class="fit-cover" src="' + escapeHtml((window.aksrtData && window.aksrtData.themeUri ? window.aksrtData.themeUri : '') + '/assets/img/medal/medal-background.svg') + '" alt=""></div><div class="medal-single-main">' +
'<div class="medal-single-card"><div class="medal-single-bg"><img' + window.aksrtGetLazyImageAttr('lazy_other', (window.aksrtData && window.aksrtData.themeUri ? window.aksrtData.themeUri : '') + '/assets/img/medal/medal-background.svg', 'fit-cover') + ' alt=""></div><div class="medal-single-main">' +
iconHtml(item) + '<div class="medal-single-name">' + escapeHtml(item.label) + '</div>' +
(item.desc ? '<div class="medal-single-desc muted-2-color">' + escapeHtml(item.desc) + '</div>' : '') + stateLine +
'</div></div>' + (action ? '<div class="medal-modal__actions">' + action + '</div>' : '') +
+26 -27
View File
@@ -118,24 +118,32 @@
if (message) message.hidden = false;
});
}
if (typeof window.DPlayer !== 'function') return;
var holder = document.createElement('div');
holder.className = 'aksrt-widget-video__player';
el.insertBefore(holder, fallback || el.firstChild);
try {
el.aksrtPlayer = new window.DPlayer({
container: holder,
autoplay: el.dataset.autoplay === '1' && !reducedMotion,
video: {
url: el.dataset.videoUrl || '',
pic: el.dataset.videoPoster || '',
type: videoType(el.dataset.videoUrl || '')
}
});
if (el.dataset.muted === '1' && el.aksrtPlayer.video) el.aksrtPlayer.video.muted = true;
if (fallback) fallback.hidden = true;
} catch (error) {
holder.remove();
function mountPlayer(event) {
if (typeof window.DPlayer !== 'function' || el.aksrtPlayer) return;
if (event) event.preventDefault();
var holder = document.createElement('div');
holder.className = 'aksrt-widget-video__player';
el.insertBefore(holder, fallback || el.firstChild);
try {
el.aksrtPlayer = new window.DPlayer({
container: holder,
autoplay: el.dataset.autoplay === '1' && !reducedMotion,
video: {
url: el.dataset.videoUrl || '',
pic: el.dataset.videoPoster || '',
type: videoType(el.dataset.videoUrl || '')
}
});
if (el.dataset.muted === '1' && el.aksrtPlayer.video) el.aksrtPlayer.video.muted = true;
if (fallback) fallback.hidden = true;
} catch (error) {
holder.remove();
}
}
if (fallback && fallback.classList.contains('lazyload')) {
fallback.addEventListener('lazybeforeunveil', mountPlayer, { once: true });
} else {
mountPlayer();
}
}
@@ -254,15 +262,6 @@
if (more) loadItems(container, Number(more.dataset.nextPage || 2), true);
if (pageButton) loadItems(container, Number(pageButton.dataset.widgetPage || 1), false);
});
if ('IntersectionObserver' in window) {
var observer = new IntersectionObserver(function (entries) {
entries.forEach(function (entry) {
var more = container.querySelector('.aksrt-widget-load-more[data-mode="infinite"]');
if (entry.isIntersecting && more) loadItems(container, Number(more.dataset.nextPage || 2), true);
});
}, { rootMargin: '240px' });
observer.observe(container);
}
}
function initTabs(tabs) {
+1 -1
View File
@@ -299,7 +299,7 @@ if ($_footer_conter === '') {
?>
<div class="footer-miniimg"<?php echo $mi_text !== '' ? ' title="' . esc_attr($mi_text) . '"' : ''; ?>>
<p>
<img src="<?php echo esc_url($mi_img); ?>" alt="<?php echo esc_attr($mi_text !== '' ? $mi_text : $blog_name); ?>" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $mi_img); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($mi_text !== '' ? $mi_text : $blog_name); ?>">
</p>
<?php if ($mi_text !== '') : ?>
<span class="opacity8 em09"><?php echo esc_html($mi_text); ?></span>
+1 -1
View File
@@ -192,7 +192,7 @@ add_action('init', function () {
if (empty($img['url'])) continue;
$alt = esc_attr($img['alt'] ?? '');
$url = esc_url($img['url']);
$slides .= '<div class="swiper-slide"><img src="' . $url . '" alt="' . $alt . '" loading="lazy"></div>';
$slides .= '<div class="swiper-slide"><img' . aksrt_get_lazy_attr('lazy_sider', (string) $url, '', aksrt_get_lazy_thumb('lg')) . ' alt="' . $alt . '"></div>';
}
if (empty($slides)) return '';
+4 -2
View File
@@ -115,9 +115,11 @@ if (!function_exists('aksrt_get_avatar_html')) {
'alt' => '',
'width' => (string) $size,
'height' => (string) $size,
'loading' => 'lazy',
];
$attrs = array_merge($defaults, $attrs);
unset($attrs['loading']);
$class = (string) ($attrs['class'] ?? $defaults['class']);
unset($attrs['class']);
$html_attrs = '';
foreach ($attrs as $name => $value) {
$name = sanitize_key((string) $name);
@@ -126,7 +128,7 @@ if (!function_exists('aksrt_get_avatar_html')) {
}
$html_attrs .= ' ' . $name . '="' . esc_attr((string) $value) . '"';
}
return '<img src="' . esc_url($url) . '"' . $html_attrs . ' />';
return '<img' . aksrt_get_lazy_attr('lazy_avatar', $url, $class, aksrt_get_default_avatar_url()) . $html_attrs . '>';
}
}
+1 -1
View File
@@ -453,7 +453,7 @@ if (!function_exists('aksrt_render_mini_post_item')) :
?>
<article class="<?php echo esc_attr(implode(' ', array_unique($classes))); ?>">
<a href="<?php echo esc_url($permalink); ?>" class="item-thumbnail" aria-label="<?php echo esc_attr($title); ?>">
<img class="fit-cover" src="<?php echo esc_url($thumb_url !== '' ? $thumb_url : $placeholder_url); ?>" alt="<?php echo esc_attr($title); ?>" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_posts_thumb', (string) ($thumb_url !== '' ? $thumb_url : $placeholder_url), 'fit-cover'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($title); ?>">
</a>
<div class="posts-mini-con">
<h4 class="item-heading">
+9 -9
View File
@@ -24,7 +24,7 @@ if (!function_exists('aksrt_graphic_card')) :
* @type string $text2 Secondary text.
* @type string $text3 Tertiary / badge text (HTML allowed for icon+count).
* @type string $more Extra absolute HTML (badge etc).
* @type bool $lazy Use aksrt-lazy data-src.
* @type bool $lazy Use the Zibll lazySizes contract.
* @type int|float $height_scale Padding-bottom % (0 = default CSS).
* @type int|float $mask_opacity 0–100 overlay opacity.
* @type string $hide pc|m|'' hide on device.
@@ -89,21 +89,21 @@ if (!function_exists('aksrt_graphic_card')) :
$link_target = sanitize_text_field((string) ($link['target'] ?? ''));
$lazy = !empty($args['lazy']);
$placeholder = get_template_directory_uri() . '/assets/img/placeholder.svg';
$media = '';
if ($video_url !== '' && !(function_exists('wp_is_mobile') && wp_is_mobile())) {
$poster = $img_url !== '' ? ' poster="' . esc_url($img_url) . '"' : '';
if ($lazy) {
$media = '<video autoplay loop muted playsinline class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($video_url) . '" src=""' . $poster . '></video>';
if ($lazy && aksrt_is_lazy('lazy_other')) {
$poster = $img_url !== '' ? ' data-poster="' . esc_url($img_url) . '"' : '';
$media = '<video autoplay loop muted playsinline class="fit-cover lazyload" data-src="' . esc_url($video_url) . '" src=""' . $poster . '></video>';
} else {
$poster = $img_url !== '' ? ' poster="' . esc_url($img_url) . '"' : '';
$media = '<video autoplay loop muted playsinline class="fit-cover" src="' . esc_url($video_url) . '"' . $poster . '></video>';
}
} elseif ($img_url !== '') {
$alt = (string) ($args['alt'] !== '' ? $args['alt'] : __('图片', 'aksrt'));
if ($lazy) {
$media = '<img class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($img_url) . '" src="' . esc_url($placeholder) . '" alt="' . esc_attr($alt) . '" loading="lazy" />';
$media = '<img' . aksrt_get_lazy_attr('lazy_other', $img_url, 'fit-cover') . ' alt="' . esc_attr($alt) . '">';
} else {
$media = '<img class="fit-cover" src="' . esc_url($img_url) . '" alt="' . esc_attr($alt) . '" loading="lazy" />';
$media = '<img class="fit-cover" src="' . esc_url($img_url) . '" alt="' . esc_attr($alt) . '">';
}
}
if ($media === '') {
@@ -228,7 +228,7 @@ if (!function_exists('aksrt_author_minicard')) :
? aksrt_get_user_home_url($user_id)
: get_author_posts_url($user_id);
$avatar_box = '<div class="avatar-img"><a href="' . esc_url($home) . '"><img class="avatar" src="' . esc_url($avatar_url) . '" alt="" loading="lazy" width="42" height="42" /></a></div>';
$avatar_box = '<div class="avatar-img"><a href="' . esc_url($home) . '"><img' . aksrt_get_lazy_attr('lazy_avatar', $avatar_url, 'avatar', aksrt_get_lazy_thumb('sm')) . ' alt="" width="42" height="42"></a></div>';
$name = function_exists('aksrt_get_user_name')
? aksrt_get_user_name([
@@ -260,7 +260,7 @@ if (!function_exists('aksrt_author_minicard')) :
$blur = '';
if ($blur_bg) {
$blur = '<div class="abs-blur-bg blur"><img src="' . esc_url($avatar_url) . '" alt="" loading="lazy" /></div>';
$blur = '<div class="abs-blur-bg blur"><img' . aksrt_get_lazy_attr('lazy_avatar', $avatar_url, '', aksrt_get_lazy_thumb('sm')) . ' alt=""></div>';
}
return '<div class="author-minicard radius8 relative-h ' . esc_attr($class) . '">'
+4 -4
View File
@@ -42,7 +42,7 @@ if (!function_exists('aksrt_icon_card')) :
if ($icon_img === '' && is_string($args['customize_icon']) && str_contains((string) $args['customize_icon'], '<')) {
$custom_html = wp_kses((string) $args['customize_icon'], [
'i' => ['class' => true, 'aria-hidden' => true],
'img' => ['src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true, 'loading' => true],
'img' => ['src' => true, 'data-src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true],
'span'=> ['class' => true],
]);
}
@@ -80,7 +80,7 @@ if (!function_exists('aksrt_icon_card')) :
if ($custom_html !== '') {
$icon_inner = $custom_html;
} elseif ($icon_img !== '') {
$icon_inner = '<img src="' . esc_url($icon_img) . '" alt="" loading="lazy" />';
$icon_inner = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_img, 'img-icon') . ' alt="">';
} else {
if ($icon_fa !== '' && !str_contains($icon_fa, 'fa-') && !str_contains($icon_fa, ' ')) {
$icon_fa = 'fa fa-' . $icon_fa;
@@ -181,7 +181,7 @@ if (!function_exists('aksrt_icon_cover_card')) :
if ($icon_img === '' && $custom_src !== '' && str_contains($custom_src, '<')) {
$custom_html = wp_kses($custom_src, [
'i' => ['class' => true, 'aria-hidden' => true],
'img' => ['src' => true, 'alt' => true, 'class' => true, 'loading' => true, 'width' => true, 'height' => true],
'img' => ['src' => true, 'data-src' => true, 'alt' => true, 'class' => true, 'width' => true, 'height' => true],
'span' => ['class' => true],
'svg' => ['class' => true, 'viewbox' => true, 'viewBox' => true, 'width' => true, 'height' => true, 'fill' => true, 'xmlns' => true, 'aria-hidden' => true],
'path' => ['d' => true, 'fill' => true, 'stroke' => true, 'stroke-width' => true],
@@ -235,7 +235,7 @@ if (!function_exists('aksrt_icon_cover_card')) :
if ($custom_html !== '') {
$icon_inner = $custom_html;
} elseif ($icon_img !== '') {
$icon_inner = '<img src="' . esc_url($icon_img) . '" alt="" loading="lazy" />';
$icon_inner = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_img, 'img-icon') . ' alt="">';
} else {
// zibll: zib_get_cfs_icon($args['icon'], 'em09') — keep FA class + em09.
if ($icon_fa !== '' && !str_contains($icon_fa, 'fa-') && !str_contains($icon_fa, ' ') && !str_starts_with($icon_fa, 'zibsvg-')) {
+7 -7
View File
@@ -99,7 +99,7 @@ if (!function_exists('aksrt_render_user_identity_chips')) {
if ($type !== '') {
$classes .= ' aksrt-identity-medal--' . $type;
}
$html .= '<img class="' . esc_attr($classes) . '" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$html .= '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, $classes) . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
$n++;
continue;
}
@@ -180,20 +180,20 @@ if (!function_exists('aksrt_get_user_name')) {
$auth_html = $icon_url !== ''
? '<img class="aksrt-identity-certification-icon img-icon ml3" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />'
? '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-identity-certification-icon img-icon ml3') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">'
: '<span class="badg badg-sm ml3 aksrt-identity-chip aksrt-identity-chip--success" title="' . esc_attr($title) . '"><i class="fa fa-check-circle" aria-hidden="true"></i> ' . esc_html($label) . '</span>';
} elseif ($type === 'level' && !empty($args['level']) && $level_html === '') {
if ($icon_url !== '') {
$level_html = '<img class="aksrt-user-level-icon img-icon ml3" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$level_html = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-user-level-icon img-icon ml3') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
} else {
// Text fallback mirrors zibll LV badge: small pill, never oversized.
$level_html = '<span class="badg badg-sm ml3 aksrt-user-level-badge" title="' . esc_attr($title) . '">' . esc_html($label) . '</span>';
}
} elseif ($type === 'badge' && !empty($args['medal']) && $medal_html === '' && !empty($signal['wear'])) {
if ($icon_url !== '') {
$medal_html = '<img class="medal-icon img-icon ml3 aksrt-identity-medal is-wear" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$medal_html = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'medal-icon img-icon ml3 aksrt-identity-medal is-wear') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
} else {
$medal_html = '<span class="badg badg-sm ml3 aksrt-identity-chip is-wear" title="' . esc_attr($title) . '"><i class="fa fa-award" aria-hidden="true"></i> ' . esc_html($label) . '</span>';
}
@@ -212,7 +212,7 @@ if (!function_exists('aksrt_get_user_name')) {
continue;
}
if ($icon_url !== '') {
$medal_html = '<img class="medal-icon img-icon ml3 aksrt-identity-medal" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$medal_html = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'medal-icon img-icon ml3 aksrt-identity-medal') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($title) . '" decoding="async">';
} else {
$medal_html = '<span class="badg badg-sm ml3 aksrt-identity-chip" title="' . esc_attr($title) . '"><i class="fa fa-award" aria-hidden="true"></i> ' . esc_html($label) . '</span>';
}
@@ -282,7 +282,7 @@ if (!function_exists('aksrt_render_user_medal_entry')) {
continue;
}
$label = sanitize_text_field((string) ($item['label'] ?? __('徽章', 'aksrt')));
$icons[] = '<img class="img-icon medal-icon aksrt-medal-entry__icon" src="' . $icon_url . '" alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" loading="lazy" decoding="async" />';
$icons[] = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'img-icon medal-icon aksrt-medal-entry__icon') . ' alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" decoding="async">';
if (count($icons) >= $limit) {
break 2;
}
@@ -409,7 +409,7 @@ if (!function_exists('aksrt_get_worn_medal_icon')) {
if ($icon !== '') {
$extra = $class !== '' ? ' ' . esc_attr($class) : '';
return '<img class="medal-icon img-icon ml3 aksrt-identity-medal is-wear' . $extra . '" src="' . $icon . '" alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" loading="lazy" decoding="async" />';
return '<img' . aksrt_get_lazy_attr('lazy_other', $icon, 'medal-icon img-icon ml3 aksrt-identity-medal is-wear' . $extra) . ' alt="' . esc_attr($label) . '" title="' . esc_attr($label) . '" decoding="async">';
}
// Text fallback (rare): small pill labelled with badge text.
+2 -2
View File
@@ -152,7 +152,7 @@ if (!function_exists('aksrt_links_box')) :
$dec = !empty($link['desc']) ? (string) $link['desc'] : '';
$rel = $nofollow ? ' rel="nofollow noopener noreferrer"' : ' rel="noopener noreferrer"';
$img_src = $src !== '' ? $src : $placeholder;
$img = '<img class="lazyload aksrt-lazy avatar" src="' . esc_url($placeholder) . '" data-src="' . esc_url($img_src) . '" alt="" loading="lazy">';
$img = '<img' . aksrt_get_lazy_attr('lazy_other', $img_src, 'avatar') . ' alt="">';
$data_dec = $dec !== ''
? ' title="' . esc_attr($title) . '" data-content="' . esc_attr($dec) . '"'
: ' data-content="' . esc_attr($title) . '"';
@@ -385,7 +385,7 @@ if (!function_exists('aksrt_link_get_search_cover')) :
. '<div class="tab-content">' . $type_con . '</div></div></div>';
return '<div class="page-cover theme-box radius8 main-shadow link-page-search-cover">'
. '<img class="fit-cover no-scale lazyload" src="' . esc_url($src) . '" data-src="' . esc_url($img) . '" alt="">'
. '<img' . aksrt_get_lazy_attr('lazy_cover', (string) $img, 'fit-cover no-scale', (string) $src) . ' alt="">'
. $search . '</div>';
}
endif;
+1 -1
View File
@@ -59,7 +59,7 @@ if (!function_exists('aksrt_get_null')) {
$style .= 'opacity:.7;';
$src = aksrt_null_image_url($img);
return '<div class="text-center aksrt-null ' . esc_attr($class) . '" style="padding:' . esc_attr($margin) . 'px 0;">'
. '<img class="no-imgbox aksrt-null__img" style="' . esc_attr($style) . '" src="' . esc_url($src) . '" alt="" loading="lazy" decoding="async">'
. '<img class="no-imgbox aksrt-null__img" style="' . esc_attr($style) . '" src="' . esc_url($src) . '" alt="" decoding="async">'
. $caption
. '</div>';
}
+11 -12
View File
@@ -1243,7 +1243,7 @@ if (!function_exists('aksrt_render_paid_gallery')) {
<div class="swiper-wrapper">
<?php foreach ($images as $img_url) : ?>
<div class="swiper-slide">
<img src="<?php echo esc_url($img_url); ?>" alt="" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $img_url, '', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<?php endforeach; ?>
</div>
@@ -1255,7 +1255,7 @@ if (!function_exists('aksrt_render_paid_gallery')) {
<!-- 未付费:仅首图模糊预览,不输出完整图库 URL 列表 -->
<div class="aksrt-paid-gallery__locked">
<div class="aksrt-paid-gallery__preview">
<img src="<?php echo esc_url((string) $images[0]); ?>" alt="" class="aksrt-gallery-locked" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $images[0], 'aksrt-gallery-locked', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<div class="aksrt-paid-gallery__overlay">
<i class="fas fa-images" aria-hidden="true"></i>
@@ -1316,16 +1316,15 @@ if (!function_exists('aksrt_render_paid_video')) {
<div class="aksrt-paid-video" data-post-id="<?php echo esc_attr((string) $post->ID); ?>">
<?php if ($has_access) : ?>
<!-- 已付费:视频播放器 -->
<div class="aksrt-paid-video__player">
<?php if (preg_match('/\.(mp4|webm|ogg)$/i', $video_url)) : ?>
<video controls preload="metadata" style="width:100%;border-radius:var(--radius-lg);">
<source src="<?php echo esc_url($video_url); ?>">
<?php esc_html_e('您的浏览器不支持视频播放。', 'aksrt'); ?>
</video>
<?php else : ?>
<div class="aksrt-paid-video__embed">
<iframe src="<?php echo esc_url($video_url); ?>" frameborder="0" allowfullscreen></iframe>
</div>
<div class="aksrt-paid-video__player">
<?php if (preg_match('/\.(mp4|webm|ogg)$/i', $video_url)) : ?>
<video controls preload="metadata"<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> style="width:100%;border-radius:var(--radius-lg);">
<?php esc_html_e('您的浏览器不支持视频播放。', 'aksrt'); ?>
</video>
<?php else : ?>
<div class="aksrt-paid-video__embed">
<iframe<?php echo aksrt_is_lazy('lazy_posts_content') ? ' class="lazyload" src="" data-src="' . esc_url($video_url) . '"' : ' src="' . esc_url($video_url) . '"'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> frameborder="0" allowfullscreen></iframe>
</div>
<?php endif; ?>
</div>
<?php else : ?>
+2 -4
View File
@@ -494,15 +494,13 @@ if (!function_exists('aksrt_render_related_graphic_card')) :
$views = function_exists('aksrt_get_post_views') ? (int) aksrt_get_post_views($post->ID) : 0;
$views_label = function_exists('aksrt_format_number') ? aksrt_format_number($views) : number_format_i18n($views);
$img_attrs = function_exists('aksrt_lazy_img_attrs')
? aksrt_lazy_img_attrs($thumb, 'cover', 'fit-cover')
: 'class="fit-cover" src="' . esc_url($thumb) . '" loading="lazy"';
$img_attrs = aksrt_get_lazy_attr('lazy_cover', (string) $thumb, 'fit-cover', aksrt_get_lazy_thumb('lg'));
$html = '<div class="swiper-slide mr10">';
$html .= '<div class="graphic style-3 mb10">';
$html .= '<a href="' . esc_url((string) $url) . '" class="radius8" title="' . esc_attr($title) . '">';
$html .= '<div class="graphic-img" style="padding-bottom:70%">';
$html .= '<img ' . $img_attrs . ' alt="' . esc_attr($title) . '">';
$html .= '<img' . $img_attrs . ' alt="' . esc_attr($title) . '">';
$html .= '<div class="abs-center left-bottom graphic-text">';
$html .= '<div class="text1 text-ellipsis">' . esc_html($title) . '</div>';
$html .= '<div class="text3 muted-2-color em09"><span class="item">' . esc_html($time) . '</span>';
+4 -6
View File
@@ -119,7 +119,7 @@ if (!function_exists('aksrt_single_render_cover')) :
<?php else : ?>
<div class="graphic mb20 single-cover single-cover--slide imgbox-container" style="padding-bottom:calc(<?php echo esc_attr((string) $img_scale); ?>% + 50px);">
<?php foreach ($slides as $idx => $slide_url) : ?>
<img src="<?php echo esc_url($slide_url); ?>" alt="" class="fit-cover" style="<?php echo $idx === 0 ? '' : 'display:none;'; ?>" loading="<?php echo $idx === 0 ? 'eager' : 'lazy'; ?>">
<img<?php echo aksrt_get_lazy_attr('lazy_sider', (string) $slide_url, 'fit-cover', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" style="<?php echo $idx === 0 ? '' : 'display:none;'; ?>">
<?php endforeach; ?>
<?php echo $overlay; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
</div>
@@ -130,13 +130,11 @@ if (!function_exists('aksrt_single_render_cover')) :
endif;
// Image cover (default).
$img_attrs = function_exists('aksrt_lazy_img_attrs')
? aksrt_lazy_img_attrs((string) $ctx['cover_url'], 'cover', 'fit-cover')
: 'class="fit-cover" src="' . esc_url((string) $ctx['cover_url']) . '" loading="eager"';
$img_attrs = aksrt_get_lazy_attr('lazy_cover', (string) $ctx['cover_url'], 'fit-cover', aksrt_get_lazy_thumb('lg'));
?>
<div class="single-head-cover">
<div class="graphic mb20 single-cover imgbox-container" style="padding-bottom:calc(<?php echo esc_attr((string) $img_scale); ?>% + 50px);">
<img <?php echo $img_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr(wp_strip_all_tags(get_the_title())); ?>">
<img<?php echo $img_attrs; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr(wp_strip_all_tags(get_the_title())); ?>">
<div class="abs-center left-bottom single-cover-con">
<h1 class="article-title title-h-left"><?php echo $title_html; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></h1>
<?php if ($crumbs !== '') : ?>
@@ -480,7 +478,7 @@ if (!function_exists('aksrt_single_render_author_card')) :
?>
<a class="item mr10 mb10" href="<?php echo esc_url(get_permalink($rp)); ?>" style="display:block;width:46%;">
<?php if ($thumb) : ?>
<img class="fit-cover radius8" src="<?php echo esc_url($thumb); ?>" alt="" loading="lazy" decoding="async" style="width:100%;aspect-ratio:16/10;object-fit:cover;" />
<img<?php echo aksrt_get_lazy_attr('lazy_posts_thumb', (string) $thumb, 'fit-cover radius8'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" decoding="async" style="width:100%;aspect-ratio:16/10;object-fit:cover;">
<?php endif; ?>
<div class="em09 mt6 text-ellipsis"><?php echo esc_html(get_the_title($rp)); ?></div>
</a>
+1 -2
View File
@@ -137,8 +137,7 @@ function aksrt_render_slider(array $args = []): string {
}
if ($image) {
$html .= '<img class="swiper-lazy fit-cover" data-src="' . esc_url($image) . '" src="' . esc_url($image) . '" alt="' . esc_attr($alt) . '" loading="lazy">';
$html .= '<div class="swiper-lazy-preloader"></div>';
$html .= '<img' . aksrt_get_lazy_attr('lazy_sider', (string) $image, 'fit-cover', aksrt_get_lazy_thumb('lg')) . ' alt="' . esc_attr($alt) . '">';
}
if ($link) {
+1 -1
View File
@@ -125,7 +125,7 @@ if (!function_exists('aksrt_render_user_card_posts')) :
echo '<div class="swiper-slide mr10">';
echo '<a class="aksrt-more-post-card" href="' . esc_url(get_permalink($rp)) . '">';
if ($thumb) {
echo '<span class="aksrt-more-post-card__thumb"><img class="fit-cover" src="' . esc_url($thumb) . '" alt="" loading="lazy" decoding="async" /></span>';
echo '<span class="aksrt-more-post-card__thumb"><img' . aksrt_get_lazy_attr('lazy_posts_thumb', (string) $thumb, 'fit-cover') . ' alt="" decoding="async"></span>';
}
echo '<span class="aksrt-more-post-card__body">';
echo '<span class="aksrt-more-post-card__title text-ellipsis">' . esc_html($title) . '</span>';
+1 -1
View File
@@ -364,7 +364,7 @@ function aksrt_render_vip_badge(int $user_id = 0, string $size = 'sm'): string {
$icon_url = esc_url((string) ($vip_settings['levels'][$level]['img_icon'] ?? ''));
}
$icon = $icon_url !== ''
? '<img class="aksrt-vip-badge__icon" src="' . $icon_url . '" alt="" loading="lazy" decoding="async" />'
? '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-vip-badge__icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
return '<span class="aksrt-vip-badge aksrt-vip-badge--gold ' . esc_attr($size_class . ' ' . $level_class) . '" title="' . esc_attr($badge_text) . '">' . $icon . '</span>';
+9 -9
View File
@@ -88,12 +88,9 @@ if (!function_exists('aksrt_render_comment_smilie')) :
if (!isset($map[$lookup])) {
return '[g=' . esc_html($raw) . ']';
}
return sprintf(
'<img class="smilie-icon" src="%1$s" alt="%2$s" title="%2$s" width="30" height="30" loading="lazy" decoding="async" data-smilie="%3$s" />',
esc_url($map[$lookup]),
esc_attr('[' . $lookup . ']'),
esc_attr($lookup)
);
$label = esc_attr('[' . $lookup . ']');
return '<img' . aksrt_get_lazy_attr('lazy_comment', (string) $map[$lookup], 'smilie-icon', aksrt_get_lazy_thumb('sm'))
. ' alt="' . $label . '" title="' . $label . '" width="30" height="30" decoding="async" data-smilie="' . esc_attr($lookup) . '">';
}
endif;
@@ -103,9 +100,12 @@ if (!function_exists('aksrt_render_comment_content')) :
*/
function aksrt_render_comment_content(string $content): string {
// [img=url]
$rendered = preg_replace(
$rendered = preg_replace_callback(
'/\[img=(https?:\/\/[^\s\[\]]+)\]/i',
'<img class="box-img comment-inline-img" src="$1" alt="' . esc_attr__('评论图片', 'aksrt') . '" loading="lazy" decoding="async" />',
static function (array $matches): string {
return '<img' . aksrt_get_lazy_attr('lazy_comment', (string) $matches[1], 'box-img comment-inline-img', aksrt_get_lazy_thumb('lg'))
. ' alt="' . esc_attr__('评论图片', 'aksrt') . '" decoding="async">';
},
$content
);
// [code]...[/code]
@@ -134,7 +134,7 @@ if (!function_exists('aksrt_render_comment_content')) :
'title' => true,
'width' => true,
'height' => true,
'loading' => true,
'data-src' => true,
'decoding' => true,
'data-smilie' => true,
'data-src' => true,
+1 -1
View File
@@ -45,7 +45,7 @@ if (!function_exists('aksrt_get_input_expand_but')) :
$map = function_exists('aksrt_comment_smilie_map') ? aksrt_comment_smilie_map() : [];
$icons = '';
foreach ($map as $key => $url) {
$icons .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img src="' . esc_url($url) . '" alt="[' . esc_attr((string) $key) . ']" width="28" height="28" loading="lazy" /></a>';
$icons .= '<a class="smilie-icon" href="javascript:;" data-smilie="' . esc_attr((string) $key) . '"><img' . aksrt_get_lazy_attr('lazy_comment', (string) $url, '', aksrt_get_lazy_thumb('sm')) . ' alt="[' . esc_attr((string) $key) . ']" width="28" height="28"></a>';
}
$but = '<a class="but btn-input-expand input-smilie mr6" href="javascript:;" data-toggle-class="open" data-target=".dropdown-smilie-wrap" title="' . esc_attr__('表情', 'aksrt') . '"><i class="fa fa-fw fa-smile-o" aria-hidden="true"></i><span class="hide-sm">' . esc_html__('表情', 'aksrt') . '</span></a>';
$drop = '<div class="dropdown-smilie-wrap relative dropup"><div class="dropdown-smilie scroll-y mini-scrollbar dropdown-menu">' . $icons . '</div></div>';
+4 -4
View File
@@ -148,7 +148,7 @@ if (!function_exists('aksrt_header_user_box_html')) :
if ($user_id > 0) {
$user = $ctx['current_user'] instanceof WP_User ? $ctx['current_user'] : wp_get_current_user();
$display_name = $user->display_name ?: $user->user_login;
$avatar = get_avatar($user_id, 44, '', esc_attr($display_name), ['loading' => 'lazy']);
$avatar = aksrt_get_avatar_html($user_id, 44, ['alt' => $display_name]);
$desc = (string) ($ctx['user_desc'] ?? '');
$vip_badge = function_exists('aksrt_render_vip_badge') ? aksrt_render_vip_badge($user_id, 'sm') : '';
// Level and certification icons ride inline to the right of the display name.
@@ -167,7 +167,7 @@ if (!function_exists('aksrt_header_user_box_html')) :
$icon_url = esc_url((string) ($signal['icon_url'] ?? ''));
$title = (string) ($signal['title'] ?? $signal['label'] ?? '');
if ($icon_url !== '' && $title !== '') {
$certification_badge = '<img class="aksrt-identity-certification-icon img-icon ml3" src="' . $icon_url . '" alt="" title="' . esc_attr($title) . '" loading="lazy" decoding="async" />';
$certification_badge = '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-identity-certification-icon img-icon ml3') . ' alt="" title="' . esc_attr($title) . '" decoding="async">';
}
break;
}
@@ -329,7 +329,7 @@ if (!function_exists('aksrt_menu_button')) :
$user_sub = '<div class="padding-10">' . aksrt_header_user_box_html($ctx) . '</div>';
if ('2' === $layout) {
if ($user_id > 0) {
$avatar = get_avatar($user_id, 36, '', '', ['loading' => 'lazy', 'class' => 'avatar']);
$avatar = aksrt_get_avatar_html($user_id, 36, ['class' => 'avatar']);
$sign_but = '<li><a href="javascript:;" class="navbar-avatar">' . $avatar . '</a><ul class="sub-menu">'
. $user_sub . '</ul></li>';
} else {
@@ -340,7 +340,7 @@ if (!function_exists('aksrt_menu_button')) :
}
} else {
$trigger = $user_id > 0
? get_avatar($user_id, 36, '', '', ['loading' => 'lazy'])
? aksrt_get_avatar_html($user_id, 36)
: '<i class="fas fa-user" aria-hidden="true"></i>';
$cls = $user_id > 0 ? 'navbar-avatar' : 'btn signin-loader';
$dot = ($user_id > 0 && (int) ($ctx['unread_count'] ?? 0) > 0)
-24
View File
@@ -342,30 +342,6 @@ if (!function_exists('aksrt_renderer_resolve_images')) {
}
}
if (!function_exists('aksrt_renderer_lazyload_config')) {
/**
* Small lazyload config subset for post cards.
*
* @return array<string,mixed>
*/
function aksrt_renderer_lazyload_config(): array {
if (class_exists('\AKSRT\Settings\Settings')) {
$lazy = \AKSRT\Settings\Settings::get_lazyload_config();
return [
'enabled' => !empty($lazy['enabled']) && !empty($lazy['posts_thumb_enabled']),
'placeholder_url' => (string) ($lazy['placeholder_url'] ?? ''),
'blur' => !empty($lazy['blur']),
];
}
return [
'enabled' => false,
'placeholder_url' => '',
'blur' => false,
];
}
}
if (!function_exists('aksrt_renderer_thumb_ratio_value')) {
/**
* Convert ratio tokens like 4:3 to CSS aspect ratio values.
+5 -4
View File
@@ -169,10 +169,11 @@ if (!function_exists('aksrt_renderer_mini')) {
$thumb_html = '';
$target_attr = !empty($cfg['target_blank']) ? ' target="_blank"' : '';
if ($cfg['show_thumb'] && !empty($data['has_img'])) {
$lazy = $data['lazy'];
$thumb_img = !empty($lazy['enabled']) && !empty($data['has_real_img'])
? '<span class="aksrt-skeleton"></span><img class="' . (!empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover') . ' aksrt-lazy lazyload" data-src="' . esc_url($data['img_url']) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="' . esc_attr($data['title']) . '">'
: '<img class="fit-cover" src="' . esc_url($data['img_url']) . '" alt="' . esc_attr($data['title']) . '"' . (!empty($data['has_real_img']) ? ' loading="lazy"' : '') . '>';
$fit_class = !empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover';
$thumb_attr = !empty($cfg['thumb_lazy'])
? aksrt_get_lazy_attr('lazy_posts_thumb', (string) $data['img_url'], $fit_class)
: ' class="' . esc_attr($fit_class) . '" src="' . esc_url($data['img_url']) . '"';
$thumb_img = '<img' . $thumb_attr . ' alt="' . esc_attr($data['title']) . '">';
$thumb_html = '<a href="' . esc_url($data['permalink']) . '" class="item-thumbnail" aria-label="' . esc_attr($data['title']) . '"' . $target_attr . '>' . $thumb_img . '</a>';
}
+7 -19
View File
@@ -20,9 +20,6 @@ if (!function_exists('aksrt_renderer_collect_post_data')) {
return [];
}
$lazy = aksrt_renderer_lazyload_config();
$lazy['enabled'] = !empty($lazy['enabled']) && !empty($cfg['thumb_lazy']);
$images = aksrt_renderer_resolve_images($post_id, $cfg);
$gallery_images = array_slice($images['gallery'], 0, $cfg['multi_thumb_limit']);
$is_mult_thumb = !empty($cfg['multi_thumb_enabled'])
@@ -71,7 +68,6 @@ if (!function_exists('aksrt_renderer_collect_post_data')) {
'resource_strip' => $resource_strip,
'is_resource' => function_exists('aksrt_is_resource_post') ? aksrt_is_resource_post($post_id) : false,
'is_sticky' => is_sticky($post_id),
'lazy' => $lazy,
'thumb_ratio_css' => aksrt_renderer_thumb_ratio_value((string) $cfg['thumb_ratio']),
'thumb_ratio_key' => (string) $cfg['thumb_ratio'],
];
@@ -110,19 +106,17 @@ if (!function_exists('aksrt_renderer_thumb')) {
return '';
}
$lazy = $data['lazy'];
$img = (string) $data['img_url'];
$title = (string) $data['title'];
$href = (string) $data['permalink'];
$is_sticky = !empty($data['is_sticky']);
$has_real_img = !empty($data['has_real_img']);
if ($has_real_img && !empty($lazy['enabled'])) {
$img_html = '<span class="aksrt-skeleton"></span>'
. '<img class="' . (!empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover') . ' aksrt-lazy lazyload" data-src="' . esc_url($img) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="' . esc_attr($title) . '">';
} else {
$img_html = '<img class="' . (!empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover') . '" src="' . esc_url($img) . '" alt="' . esc_attr($title) . '"' . ($has_real_img ? ' loading="lazy"' : '') . '>';
}
$fit_class = !empty($cfg['thumb_fit']) && $cfg['thumb_fit'] === 'contain' ? 'fit-contain' : 'fit-cover';
$img_attr = !empty($cfg['thumb_lazy'])
? aksrt_get_lazy_attr('lazy_posts_thumb', $img, $fit_class)
: ' class="' . esc_attr($fit_class) . '" src="' . esc_url($img) . '"';
$img_html = '<img' . $img_attr . ' alt="' . esc_attr($title) . '">';
$sticky_html = ($is_sticky && !empty($cfg['badge_show']))
? '<badge class="img-badge left jb-red">' . esc_html__('置顶', 'aksrt') . '</badge>'
@@ -164,17 +158,11 @@ if (!function_exists('aksrt_renderer_mult_thumb')) {
return '';
}
$lazy = $data['lazy'];
$html = '<a class="thumb-items contain" href="' . esc_url($data['permalink']) . '" aria-label="' . esc_attr($data['title']) . '">';
foreach (array_slice($data['gallery_images'], 0, 4) as $image) {
$html .= '<span>';
if (!empty($lazy['enabled'])) {
$html .= '<span class="aksrt-skeleton"></span>'
. '<img class="fit-cover aksrt-lazy lazyload" data-src="' . esc_url($image) . '" src="' . esc_url($lazy['placeholder_url']) . '" alt="">';
} else {
$html .= '<img class="fit-cover" src="' . esc_url($image) . '" alt="" loading="lazy">';
}
$html .= '<img' . aksrt_get_lazy_attr('lazy_posts_thumb', (string) $image, 'fit-cover') . ' alt="">';
$html .= '</span>';
}
@@ -277,7 +265,7 @@ if (!function_exists('aksrt_renderer_meta')) {
$left = [];
if (!empty($cfg['show_author'])) {
$left[] = '<item class="meta-author flex ac"><img src="' . esc_url($data['avatar_url']) . '" alt="" class="avatar-mini" width="20" height="20" loading="lazy"><name class="meta-name">' . esc_html($data['author_name']) . '</name></item>';
$left[] = '<item class="meta-author flex ac"><img' . aksrt_get_lazy_attr('lazy_avatar', (string) $data['avatar_url'], 'avatar-mini', aksrt_get_lazy_thumb('sm')) . ' alt="" width="20" height="20"><name class="meta-name">' . esc_html($data['author_name']) . '</name></item>';
}
if (!empty($cfg['show_date'])) {
$left[] = '<item class="meta-time">' . esc_html($data['time_ago']) . '</item>';
+2 -4
View File
@@ -187,10 +187,8 @@ function aksrt_render_slider_markup(array $slides, array $args = array()) {
<div class="swiper-slide"<?php if (! empty($slide['link'])) : ?> data-link="<?php echo esc_url($slide['link']); ?>"<?php endif; ?>>
<div class="hero__slide-bg">
<?php if (! empty($slide['image'])) : ?>
<img
src="<?php echo esc_url($slide['image']); ?>"
<img<?php echo aksrt_get_lazy_attr('lazy_sider', (string) $slide['image'], 'fit-cover', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
alt="<?php echo esc_attr($slide['title'] ?: get_bloginfo('name')); ?>"
loading="<?php echo 0 === $index ? 'eager' : 'lazy'; ?>"
decoding="async"
>
<?php else : ?>
@@ -451,6 +449,6 @@ function aksrt_get_adaptive_theme_img(string $white_src = '', string $dark_src =
}
$this_src = $is_dark ? $dark_src : $white_src;
return '<img src="' . esc_url($this_src) . '" white-src="' . esc_url($white_src) . '" dark-src="' . esc_url($dark_src) . '" alt="' . esc_attr($alt) . '"' . ($more !== '' ? ' ' . $more : '') . ' loading="lazy">';
return '<img' . aksrt_get_lazy_attr('lazy_other', (string) $this_src) . ' white-src="' . esc_url($white_src) . '" dark-src="' . esc_url($dark_src) . '" alt="' . esc_attr($alt) . '"' . ($more !== '' ? ' ' . $more : '') . '>';
}
endif;
@@ -109,9 +109,8 @@ if (!function_exists('aksrt_render_pagination')) {
data-max-pages="<?php echo esc_attr((string) $max_pages); ?>"
data-query-context="<?php echo esc_attr($query_context); ?>"
data-query-vars="<?php echo esc_attr(wp_json_encode($query_vars)); ?>"
data-render-config="<?php echo esc_attr(wp_json_encode($render_config)); ?>"
data-lazyload-action="ias">
<div class="next-page ajax-next aksrt-load-more-btn" lazyload-action="ias" role="button" tabindex="0">
data-render-config="<?php echo esc_attr(wp_json_encode($render_config)); ?>">
<div class="next-page ajax-next aksrt-load-more-btn<?php echo $pagination_mode === 'infinite' ? ' lazyload' : ''; ?>"<?php echo $pagination_mode === 'infinite' ? ' lazyload-action="ias"' : ''; ?> role="button" tabindex="0">
<?php echo esc_html($trigger_text); ?>
</div>
<div class="aksrt-loading-indicator" style="display:none;" aria-hidden="true">
@@ -175,66 +174,176 @@ function aksrt_auto_image_alt(string $content): string {
add_filter('the_content', 'aksrt_auto_image_alt', 999);
/**
* 懒加载 per-scope 开关判断
* Detect search-engine crawlers that must receive real image URLs.
*
* 检查总开关 + 指定 scope 开关。
*
* @param string $scope avatar|content|comment|private|slider|cover|other|widget
* @return bool
* @return string|false Matched crawler name, or false.
*/
function aksrt_is_lazyload_enabled(string $scope = 'other'): bool {
if (!class_exists('\AKSRT\Settings\Settings')) return true; // 默认开
$cfg = \AKSRT\Settings\Settings::get_lazyload_config();
if (!$cfg['enabled']) return false;
return !empty($cfg[$scope] ?? true);
function aksrt_is_crawler() {
static $crawler = null;
if ($crawler !== null) {
return $crawler;
}
$bots = [
'Baidu' => 'baiduspider', 'Google Bot' => 'google', '360spider' => '360spider',
'Sogou' => 'spider', 'soso.com' => 'sosospider', 'MSN' => 'msnbot',
'Alex' => 'ia_archiver', 'Lycos' => 'lycos', 'Ask Jeeves' => 'jeeves',
'Altavista' => 'scooter', 'AllTheWeb' => 'fast-webcrawler', 'Inktomi' => 'slurp@inktomi',
'Turnitin.com' => 'turnitinbot', 'Technorati' => 'technorati', 'Yahoo' => 'yahoo',
'Findexa' => 'findexa', 'NextLinks' => 'findlinks', 'Gais' => 'gaisbo',
'WiseNut' => 'zyborg', 'WhoisSource' => 'surveybot', 'Bloglines' => 'bloglines',
'BlogSearch' => 'blogsearch', 'PubSub' => 'pubsub', 'Syndic8' => 'syndic8',
'RadioUserland' => 'userland', 'Gigabot' => 'gigabot', 'Become.com' => 'become.com',
'Yandex' => 'yandex',
];
$user_agent = strtolower((string) ($_SERVER['HTTP_USER_AGENT'] ?? ''));
$crawler = false;
foreach ($bots as $name => $needle) {
if ($user_agent !== '' && stripos($user_agent, $needle) !== false) {
$crawler = $name;
break;
}
}
return $crawler;
}
/**
* 返回 img 标签的 lazy-loading 属性字符串
*
* 当 scope 启用懒加载时:class="aksrt-lazy" + data-src(需配合 skeleton 使用)
* 当 scope 禁用时:loading="lazy"(浏览器原生)
*
* @param string $url 图片 URL
* @param string $scope 场景名
* @param string $extra_class 额外 CSS 类
* @return string HTML 属性字符串
* Determine whether one Zibll-style lazy-loading scope is enabled.
*/
function aksrt_lazy_img_attrs(string $url, string $scope = 'other', string $extra_class = ''): string {
if (empty($url)) return '';
if (aksrt_is_lazyload_enabled($scope)) {
$cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_lazyload_config() : [];
$placeholder = $cfg['placeholder_url'] ?? '';
$animation = $cfg['animation'] ?? 'blur';
$cls = trim('fit-cover aksrt-lazy ' . $extra_class);
$attrs = sprintf('class="%s" data-src="%s" data-lazy-animation="%s"', esc_attr($cls), esc_url($url), esc_attr($animation));
if ($placeholder) {
$attrs .= sprintf(' src="%s"', esc_url($placeholder));
}
return $attrs;
}
// 原生 lazy
$cls = trim('fit-cover ' . $extra_class);
return sprintf('class="%s" src="%s" loading="lazy"', esc_attr($cls), esc_url($url));
function aksrt_is_lazy(string $key, bool $default = false): bool {
if (aksrt_is_crawler()) {
return false;
}
$defaults = [
'lazy_posts_thumb' => true,
'lazy_avatar' => true,
'lazy_posts_content' => false,
'lazy_comment' => true,
'lazy_private' => true,
'lazy_sider' => true,
'lazy_cover' => true,
'lazy_other' => true,
];
$default = array_key_exists($key, $defaults) ? $defaults[$key] : $default;
if (!class_exists('\AKSRT\Settings\Settings')) {
return $default;
}
return (bool) \AKSRT\Settings\Settings::get_value($key, $default);
}
/**
* 返回条件懒加载 loading 属性字符串
*
* 当指定 scope 启用懒加载时返回 loading="lazy",否则返回空字符串。
*
* @param string $scope 场景名 (cover|other 等)
* @return string HTML 属性字符串
* Return the configured lazy placeholder or a bundled size variant.
*/
function aksrt_lazy_loading(string $scope = 'other'): string {
if (function_exists('aksrt_is_lazyload_enabled') && aksrt_is_lazyload_enabled($scope)) {
return ' loading="lazy"';
}
return '';
function aksrt_get_lazy_thumb(string $size = ''): string {
$configured = $size === '' && class_exists('\AKSRT\Settings\Settings')
? (string) \AKSRT\Settings\Settings::get_value('thumbnail', '')
: '';
if ($configured !== '') {
return $configured;
}
$suffix = $size !== '' ? '-' . sanitize_key($size) : '';
return get_template_directory_uri() . '/assets/img/thumbnail' . $suffix . '.svg';
}
/**
* Build the only supported lazy-media attribute set.
*/
function aksrt_get_lazy_attr(string $key, string $src, string $class = '', string $lazy_src = ''): string {
$class = trim($class);
if ($src === '') {
return ' class="' . esc_attr($class) . '" src=""';
}
if (!aksrt_is_lazy($key)) {
return ' class="' . esc_attr($class) . '" src="' . esc_url($src) . '"';
}
$lazy_src = $lazy_src !== '' ? $lazy_src : aksrt_get_lazy_thumb();
return ' class="lazyload ' . esc_attr($class) . '" src="' . esc_url($lazy_src) . '" data-src="' . esc_url($src) . '"';
}
/**
* Remove Zibll-style lazy attributes from a rendered image string.
*/
function aksrt_str_remove_lazy(string $html = ''): string {
$pattern = "/<img(.*?)src=('|\")(.*?)('|\") data-src=('|\")(.*?)('|\")(.*?)>/i";
$replacement = '<img$1src=$5$6$7$8>';
return (string) preg_replace($pattern, $replacement, str_replace('lazyload', '', $html));
}
/**
* Convert post-content images to the same lazySizes contract as Zibll.
*/
function aksrt_lazy_content_images(string $content): string {
if ((is_admin() && !wp_doing_ajax()) || !aksrt_is_lazy('lazy_posts_content')) {
return $content;
}
$placeholder = esc_url(aksrt_get_lazy_thumb('lg'));
$content = (string) preg_replace(
"/<img(.*?)src=('|\")([^>]*).(bmp|gif|jpeg|jpg|png|ico|tiff|svg|webp)('|\")(.*?)>/i",
'<img$1src="' . $placeholder . '" data-src=$2$3.$4$5 $6>',
$content
);
return (string) preg_replace(
"/<img(.*?)srcset=('|\")([^>]*)('|\")(.*?)>/i",
'<img$1data-srcset=$2$3$4 $5>',
$content
);
}
add_filter('the_content', 'aksrt_lazy_content_images', 10);
/**
* Route WordPress-generated attachment images through the same lazySizes path.
*
* @param array<string,string> $attr Image attributes.
* @param WP_Post $attachment Attachment post.
* @return array<string,string>
*/
function aksrt_lazy_attachment_attributes(array $attr, $attachment): array {
unset($attr['loading'], $attr['fetchpriority']);
if ((is_admin() && !wp_doing_ajax()) || empty($attr['src']) || !empty($attr['data-src'])) {
return $attr;
}
$key = 'lazy_other';
$placeholder_size = '';
$attachment_id = is_object($attachment) ? (int) $attachment->ID : 0;
if ($attachment_id > 0 && $attachment_id === (int) get_post_thumbnail_id()) {
$key = is_singular() ? 'lazy_cover' : 'lazy_posts_thumb';
$placeholder_size = is_singular() ? 'lg' : '';
}
if (!aksrt_is_lazy($key)) {
return $attr;
}
$attr['data-src'] = (string) $attr['src'];
$attr['src'] = aksrt_get_lazy_thumb($placeholder_size);
if (!empty($attr['srcset'])) {
$attr['data-srcset'] = (string) $attr['srcset'];
unset($attr['srcset']);
}
$attr['class'] = trim('lazyload ' . (string) ($attr['class'] ?? ''));
return $attr;
}
add_filter('wp_get_attachment_image_attributes', 'aksrt_lazy_attachment_attributes', 10, 2);
/**
* Convert avatars produced directly by WordPress into the avatar lazy scope.
*/
function aksrt_lazy_avatar_html(string $avatar): string {
$avatar = (string) preg_replace('/\sloading=("|\')[^"\']*("|\')/i', '', $avatar);
if ((is_admin() && !wp_doing_ajax()) || !aksrt_is_lazy('lazy_avatar') || str_contains($avatar, 'data-src=')) {
return $avatar;
}
$avatar = preg_replace('/\ssrc=("|\')([^"\']+)("|\')/i', ' src="' . esc_url(aksrt_get_default_avatar_url()) . '" data-src="$2"', $avatar, 1);
if (str_contains($avatar, 'class="')) {
return str_replace('class="', 'class="lazyload ', (string) $avatar);
}
return str_replace('<img ', '<img class="lazyload" ', (string) $avatar);
}
add_filter('get_avatar', 'aksrt_lazy_avatar_html', 20);
// The theme uses lazySizes exclusively; WordPress must not add a native lazy path.
add_filter('wp_lazy_loading_enabled', '__return_false');
// ================================================================
// §8.1 Global capability check helper
// ================================================================
@@ -406,4 +515,3 @@ if (!function_exists('aksrt_render_footer_tabbar_single_extend')) :
endif;
}
endif;
@@ -52,7 +52,7 @@ if ($vip_level >= 1 && !empty($vip_settings['levels'][$vip_level]['name'])) {
$level_icon_url = esc_url((string) ($vip_settings['levels'][$vip_level]['img_icon'] ?? ''));
$level_icon = $level_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $level_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $level_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
if (class_exists('\AKSRT\Settings\Settings')) {
$paid_display = \AKSRT\Settings\Settings::get_paid_content_settings();
@@ -63,7 +63,7 @@ $day_max = \AKSRT\User\Level::day_max();
<div class="uc-level-road__item<?php echo esc_attr($state); ?>">
<div class="uc-level-road__icon">
<?php $icon = \AKSRT\User\Level::get_level_icon_url($level); ?>
<?php if ($icon !== '') : ?><img src="<?php echo esc_url($icon); ?>" alt="" loading="lazy"><?php else : ?><span>LV<?php echo esc_html((string) $level); ?></span><?php endif; ?>
<?php if ($icon !== '') : ?><img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $icon); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt=""><?php else : ?><span>LV<?php echo esc_html((string) $level); ?></span><?php endif; ?>
</div>
<strong><?php echo esc_html($name); ?></strong>
<small><?php echo esc_html((string) $need); ?> EXP</small>
@@ -48,7 +48,7 @@ if ($vip_level > 0) {
$sidebar_level = $vip_level > 0 ? $vip_level : $expired_level;
$sidebar_icon_url = esc_url((string) ($vip_levels[$sidebar_level]['img_icon'] ?? ''));
$sidebar_icon = $sidebar_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $sidebar_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $sidebar_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
?>
<a class="uc-sidebar-vip" href="<?php echo esc_url($vip_url); ?>" data-tab="vip">
@@ -92,7 +92,7 @@ if ($level > 0) {
$status_icon_url = esc_url((string) ($levels[$vip_level_number]['img_icon'] ?? ''));
$status_icon = $status_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $status_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $status_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown"></i>';
$status_html = '<div class="uc-vip-status" role="status">'
. '<div class="uc-vip-status__heading">'
@@ -124,7 +124,7 @@ foreach ([1, 2] as $lv) {
$vip_attr = $lv;
$lv_icon_url = esc_url((string) ($levels[$lv]['img_icon'] ?? ''));
$lv_icon = $lv_icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $lv_icon_url . '" alt="" loading="lazy" decoding="async">'
? '<img' . aksrt_get_lazy_attr('lazy_other', $lv_icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-crown" aria-hidden="true"></i>';
if (str_starts_with($btn_type, 'renew_')) {
$renew_lv = (int) substr($btn_type, 6);
+15 -30
View File
@@ -20,8 +20,21 @@ class GlobalSchema {
'version' => '1.0.0',
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'performance', 'title' => '性能优化', 'fields' => [
['key' => 'lazyload_enabled', 'label' => '图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'performance', 'title' => '图像异步懒加载', 'fields' => [
['key' => 'lazy_posts_thumb', 'label' => '文章缩略图懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_avatar', 'label' => '头像懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_posts_content', 'label' => '文章内容图片懒加载', 'type' => 'switch', 'default' => false],
['key' => 'lazy_comment', 'label' => '评论内容图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_private', 'label' => '私信聊天图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_sider', 'label' => '幻灯片图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_cover', 'label' => '封面图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_other', 'label' => '其它图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazy_animation', 'label' => '懒加载动画效果', 'type' => 'select', 'default' => 'blur', 'options' => [
['label' => '淡出淡入', 'value' => 'fade'],
['label' => '高斯模糊', 'value' => 'blur'],
['label' => '放大缩小', 'value' => 'scale'],
]],
['key' => 'thumbnail', 'label' => '懒加载预载图', 'type' => 'media', 'default' => get_template_directory_uri() . '/assets/img/thumbnail.svg'],
]],
['key' => 'filing', 'title' => '备案信息', 'fields' => [
['key' => 'icp_filing', 'label' => 'ICP 备案号', 'type' => 'input', 'default' => ''],
@@ -93,34 +106,6 @@ class GlobalSchema {
]],
],
],
'lazyload' => [
'key' => 'lazyload',
'title' => '懒加载设置',
'version' => '1.0.0',
'option_key' => 'aksrt_settings',
'groups' => [
['key' => 'basic', 'title' => '懒加载开关', 'fields' => [
['key' => 'lazyload_enabled', 'label' => '图像异步懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_animation', 'label' => '懒加载动画效果', 'type' => 'select', 'default' => 'blur', 'options' => [
['label' => '淡出淡入', 'value' => 'fade'],
['label' => '高斯模糊', 'value' => 'blur'],
['label' => '放大缩小', 'value' => 'scale'],
]],
['key' => 'lazyload_placeholder', 'label' => '懒加载预载图', 'type' => 'media', 'default' => ''],
['key' => 'lazyload_blur', 'label' => '模糊预览', 'type' => 'switch', 'default' => true],
]],
['key' => 'scope', 'title' => '懒加载范围', 'fields' => [
['key' => 'lazyload_avatar', 'label' => '头像懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_content', 'label' => '文章内容图片懒加载', 'type' => 'switch', 'default' => false],
['key' => 'lazyload_comment', 'label' => '评论内容图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_private', 'label' => '私信聊天图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_slider', 'label' => '幻灯片图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_cover', 'label' => '封面图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_other', 'label' => '其它图片懒加载', 'type' => 'switch', 'default' => true],
['key' => 'lazyload_widget', 'label' => '小工具图片懒加载', 'type' => 'switch', 'default' => true],
]],
],
],
'layout' => [
'key' => 'layout',
'title' => '显示&布局',
+1 -1
View File
@@ -164,7 +164,7 @@ trait VipServiceModal {
$icon_url = esc_url((string) ($levels[$level]['img_icon'] ?? ''));
$icon = $icon_url !== ''
? '<img class="aksrt-vip-level-icon" src="' . $icon_url . '" alt="" loading="lazy" decoding="async" />'
? '<img' . aksrt_get_lazy_attr('lazy_other', $icon_url, 'aksrt-vip-level-icon') . ' alt="" decoding="async">'
: '<i class="fas fa-gem" aria-hidden="true"></i>';
$html = '<div class="vip-card pointer level-' . $level . ' vip-theme' . $level . $cls . '" vip-level="' . $level . '">';
$html .= '<div class="vip-baicon" aria-hidden="true">' . $icon . '</div>';
+8
View File
@@ -39,6 +39,14 @@ trait ScriptsPart1b {
);
wp_enqueue_style('aksrt-style', get_stylesheet_uri(), ['bootstrap5'], $version);
$lazy_animation = class_exists('\AKSRT\Settings\Settings')
? (string) \AKSRT\Settings\Settings::get_value('lazy_animation', 'blur')
: 'blur';
if ($lazy_animation === 'fade') {
wp_add_inline_style('aksrt-style', '.lazyloaded{--lazy-animation:lazy_fade!important;}');
} elseif ($lazy_animation === 'scale') {
wp_add_inline_style('aksrt-style', '.lazyloaded{--lazy-animation:lazy_scale!important;}');
}
$core_bundle = get_template_directory() . '/assets/css/build/core.min.css';
if (file_exists($core_bundle)) {
+29 -6
View File
@@ -90,11 +90,21 @@ trait ScriptsPart1c {
true
);
// Zibll lazySizes is the only media lazy-loading runtime.
$lazysizes_js = get_template_directory() . '/assets/js/lazysizes.js';
wp_enqueue_script(
'aksrt-lazysizes',
$base_uri . '/assets/js/lazysizes.js',
[],
file_exists($lazysizes_js) ? (string) filemtime($lazysizes_js) : $version,
true
);
// Rehydrate system — must load before aksrt-script so AksrtFrontend is available
wp_enqueue_script(
'aksrt-rehydrate',
$base_uri . '/assets/js/rehydrate.js',
[],
['aksrt-lazysizes'],
file_exists(get_template_directory() . '/assets/js/rehydrate.js')
? (string) filemtime(get_template_directory() . '/assets/js/rehydrate.js')
: $version,
@@ -597,13 +607,26 @@ trait ScriptsPart1c {
'floatActionsId' => 'float-right-btns',
'tabbarId' => 'footer-tabbar',
],
'themeUri' => get_template_directory_uri(),
'codeHighlight' => class_exists('\AKSRT\Settings\Settings')
'themeUri' => get_template_directory_uri(),
'lazyScopes' => [
'lazy_posts_thumb' => aksrt_is_lazy('lazy_posts_thumb'),
'lazy_avatar' => aksrt_is_lazy('lazy_avatar'),
'lazy_posts_content' => aksrt_is_lazy('lazy_posts_content'),
'lazy_comment' => aksrt_is_lazy('lazy_comment'),
'lazy_private' => aksrt_is_lazy('lazy_private'),
'lazy_sider' => aksrt_is_lazy('lazy_sider'),
'lazy_cover' => aksrt_is_lazy('lazy_cover'),
'lazy_other' => aksrt_is_lazy('lazy_other'),
],
'lazyThumbs' => [
'default' => aksrt_get_lazy_thumb(),
'sm' => aksrt_get_lazy_thumb('sm'),
'lg' => aksrt_get_lazy_thumb('lg'),
],
'lazyAvatar' => aksrt_get_default_avatar_url(),
'codeHighlight' => class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_code_highlight_config()
: ['enabled' => true, 'lightTheme' => 'enlighter', 'darkTheme' => 'monokai', 'lineNumbers' => false, 'showButtons' => true, 'maxHeight' => 500],
'lazyload' => class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_lazyload_config()
: ['enabled' => true, 'animation' => 'blur', 'placeholder_url' => '', 'blur' => true],
'systemNotice' => class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_system_notice_config()
: ['enabled' => false],
+2 -2
View File
@@ -143,7 +143,7 @@ class NavWalker extends \Walker_Nav_Menu {
? '<div class="img-badg-box"><span class="badg badg-sm ' . esc_attr((string) ($args['badge_class'] ?? '')) . '">'
. esc_html((string) $args['badge']) . '</span></div>'
: '';
$img_html = '<div class="img-box hover-zoom-img"><img src="' . esc_url((string) $args['img']) . '" alt="" loading="lazy">' . $badge . '</div>';
$img_html = '<div class="img-box hover-zoom-img"><img' . aksrt_get_lazy_attr('lazy_other', (string) $args['img']) . ' alt="">' . $badge . '</div>';
$title_html = $title !== '' ? '<div class="title mt10 text-ellipsis">' . esc_html($title) . '</div>' : '';
return '<div class="menu-graphic-card-item"><a href="' . $link_url . '"' . $link_target . '>'
. $img_html . $title_html . '</a></div>';
@@ -201,7 +201,7 @@ class NavWalker extends \Walker_Nav_Menu {
$icon = aksrt_render_menu_icon((string) $args['icon'], true);
}
if (!empty($args['img_icon'])) {
$icon = '<img class="menu-item-icon mr3 fa-fw" src="' . esc_url((string) $args['img_icon']) . '" alt="" loading="lazy">';
$icon = '<img' . aksrt_get_lazy_attr('lazy_other', (string) $args['img_icon'], 'menu-item-icon mr3 fa-fw') . ' alt="">';
}
$title_html = $icon . $title;
$class = trim(($class ? $class . ' ' : '') . 'link-item');
-37
View File
@@ -271,43 +271,6 @@ trait FacadeBulk {
/**
* 获取懒加载配置
*
* 返回 schema 定义的全部字段:全局开关、动画、占位图、模糊预览、
* 以及 8 项粒度范围开关。
*
* @return array {enabled, animation, placeholder_url, blur, avatar, content, comment, private, slider, cover, other, widget}
*/
public static function get_lazyload_config(): array {
$s = self::get_all();
// placeholder 兼容:schema 存 lazyload_placeholder,REST/Vue 存 lazyload_placeholder_url
$placeholder = '';
if (!empty($s['lazyload_placeholder'])) {
$placeholder = $s['lazyload_placeholder'];
} elseif (!empty($s['lazyload_placeholder_url'])) {
$placeholder = $s['lazyload_placeholder_url'];
}
return [
'enabled' => !isset($s['lazyload_enabled']) || !empty($s['lazyload_enabled']),
'animation' => $s['lazyload_animation'] ?? 'blur',
'placeholder_url' => (string) $placeholder,
'blur' => !isset($s['lazyload_blur']) || !empty($s['lazyload_blur']),
'avatar' => !isset($s['lazyload_avatar']) || !empty($s['lazyload_avatar']),
'content' => !empty($s['lazyload_content']),
'comment' => !isset($s['lazyload_comment']) || !empty($s['lazyload_comment']),
'private' => !isset($s['lazyload_private']) || !empty($s['lazyload_private']),
'slider' => !isset($s['lazyload_slider']) || !empty($s['lazyload_slider']),
'cover' => !isset($s['lazyload_cover']) || !empty($s['lazyload_cover']),
'other' => !isset($s['lazyload_other']) || !empty($s['lazyload_other']),
'widget' => !isset($s['lazyload_widget']) || !empty($s['lazyload_widget']),
];
}
/**
* 获取备案配置。
* @return array {icp_enabled, icp_filing, police_enabled, police_filing}
+1 -1
View File
@@ -156,7 +156,7 @@ class Level {
$name = self::get_level_name($level);
$icon = self::get_level_icon_url($level);
if ($icon !== '') {
return '<img class="aksrt-user-level-icon img-icon ' . esc_attr($class) . '" src="' . esc_url($icon) . '" alt="' . esc_attr($name) . '" title="' . esc_attr($name) . '" loading="lazy" decoding="async">';
return '<img' . aksrt_get_lazy_attr('lazy_other', $icon, 'aksrt-user-level-icon img-icon ' . $class) . ' alt="' . esc_attr($name) . '" title="' . esc_attr($name) . '" decoding="async">';
}
return '<span class="badg badg-sm aksrt-user-level-badge ' . esc_attr($class) . '" title="' . esc_attr($name) . '">LV' . esc_html((string) $level) . '</span>';
}
+1 -1
View File
@@ -151,7 +151,7 @@ final class FormRenderer {
private static function upload(string $id, string $name, string $value): void {
echo '<div class="aksrt-widget-upload">';
if ($value !== '') {
echo '<img src="' . esc_url($value) . '" alt="" loading="lazy">';
echo '<img src="' . esc_url($value) . '" alt="">';
}
echo '<input class="widefat" type="url" id="' . esc_attr($id) . '" name="' . esc_attr($name) . '" value="' . esc_attr($value) . '">';
echo '<button type="button" class="button aksrt-widget-upload__choose">' . esc_html__('选择媒体', 'aksrt') . '</button> <button type="button" class="button-link-delete aksrt-widget-upload__remove">' . esc_html__('移除', 'aksrt') . '</button></div>';
+3 -1
View File
@@ -90,6 +90,8 @@ final class PostRenderer {
return $html . '</nav>';
}
$label = $mode === 'infinite' ? __('继续加载', 'aksrt') : __('加载更多', 'aksrt');
return '<button class="aksrt-widget-load-more" type="button" data-next-page="' . (int) ($page + 1) . '" data-mode="' . esc_attr($mode) . '">' . esc_html($label) . '</button>';
$class = $mode === 'infinite' ? 'aksrt-widget-load-more ias-btn lazyload' : 'aksrt-widget-load-more';
$action = $mode === 'infinite' ? ' lazyload-action="ias"' : '';
return '<button class="' . $class . '"' . $action . ' type="button" data-next-page="' . (int) ($page + 1) . '" data-mode="' . esc_attr($mode) . '">' . esc_html($label) . '</button>';
}
}
+7 -4
View File
@@ -20,12 +20,11 @@ final class RendererHelpers {
return $link['target'] === '_blank' ? ' target="_blank" rel="noopener noreferrer"' : '';
}
public static function image(string $url, string $alt = '', string $class = ''): string {
public static function image(string $url, string $alt = '', string $class = '', string $key = 'lazy_other', string $lazy_src = ''): string {
if ($url === '') {
return '';
}
return '<img' . ($class !== '' ? ' class="' . esc_attr($class) . '"' : '')
. ' src="' . esc_url($url) . '" alt="' . esc_attr($alt) . '" loading="lazy">';
return '<img' . aksrt_get_lazy_attr($key, $url, $class, $lazy_src) . ' alt="' . esc_attr($alt) . '">';
}
public static function lines(string $value): array {
@@ -49,7 +48,11 @@ final class RendererHelpers {
}
$media .= self::image((string) ($item['image'] ?? ''), $title, 'aksrt-media-card__image');
if (!empty($item['video'])) {
$media .= '<video class="aksrt-media-card__video" src="' . esc_url((string) $item['video']) . '" muted loop playsinline preload="metadata"></video>';
$video = esc_url((string) $item['video']);
$video_attr = aksrt_is_lazy('lazy_other')
? ' class="aksrt-media-card__video lazyload" src="" data-src="' . $video . '"'
: ' class="aksrt-media-card__video" src="' . $video . '"';
$media .= '<video' . $video_attr . ' muted loop playsinline preload="metadata"></video>';
}
$body = '<span class="aksrt-media-card__body"><strong>' . esc_html($title) . '</strong>';
if (!empty($item['description'])) {
+12 -2
View File
@@ -67,14 +67,24 @@ final class GeneralRenderer {
return RendererHelpers::empty_state(__('请配置视频地址', 'aksrt'));
}
$ratio = (string) $i['ratio'];
return '<div class="aksrt-widget-video aksrt-widget-video--' . esc_attr(str_replace(':', '-', $ratio)) . '" data-video-url="' . $url . '" data-video-poster="' . esc_url((string) $i['poster']) . '" data-autoplay="' . (!empty($i['autoplay']) ? '1' : '0') . '" data-muted="' . (!empty($i['muted']) ? '1' : '0') . '"><video controls playsinline preload="metadata"' . (!empty($i['autoplay']) ? ' autoplay' : '') . (!empty($i['muted']) ? ' muted' : '') . (!empty($i['poster']) ? ' poster="' . esc_url((string) $i['poster']) . '"' : '') . '><source src="' . $url . '"></video><p class="aksrt-widget-media-error" role="alert" aria-live="assertive" hidden>' . esc_html__('视频加载失败,请稍后重试。', 'aksrt') . '</p></div>';
if (aksrt_is_lazy('lazy_other')) {
$video_attr = ' class="lazyload" src="" data-src="' . $url . '"';
$poster_attr = !empty($i['poster']) ? ' data-poster="' . esc_url((string) $i['poster']) . '"' : '';
} else {
$video_attr = ' src="' . $url . '"';
$poster_attr = !empty($i['poster']) ? ' poster="' . esc_url((string) $i['poster']) . '"' : '';
}
return '<div class="aksrt-widget-video aksrt-widget-video--' . esc_attr(str_replace(':', '-', $ratio)) . '" data-video-url="' . $url . '" data-video-poster="' . esc_url((string) $i['poster']) . '" data-autoplay="' . (!empty($i['autoplay']) ? '1' : '0') . '" data-muted="' . (!empty($i['muted']) ? '1' : '0') . '"><video controls playsinline preload="metadata"' . $video_attr . $poster_attr . (!empty($i['autoplay']) ? ' autoplay' : '') . (!empty($i['muted']) ? ' muted' : '') . '></video><p class="aksrt-widget-media-error" role="alert" aria-live="assertive" hidden>' . esc_html__('视频加载失败,请稍后重试。', 'aksrt') . '</p></div>';
}
private static function render_embed(array $i): string {
if (empty($i['url'])) {
return RendererHelpers::empty_state(__('请配置嵌入地址', 'aksrt'));
}
return '<div class="aksrt-widget-embed" style="--aksrt-embed-ratio:' . esc_attr((string) (float) $i['ratio']) . '%"><iframe src="' . esc_url((string) $i['url']) . '" loading="lazy" referrerpolicy="strict-origin-when-cross-origin"' . (!empty($i['allow_fullscreen']) ? ' allowfullscreen' : '') . ' title="' . esc_attr__('嵌入内容', 'aksrt') . '"></iframe></div>';
$src_attr = aksrt_is_lazy('lazy_other')
? ' class="lazyload" src="" data-src="' . esc_url((string) $i['url']) . '"'
: ' src="' . esc_url((string) $i['url']) . '"';
return '<div class="aksrt-widget-embed" style="--aksrt-embed-ratio:' . esc_attr((string) (float) $i['ratio']) . '%"><iframe' . $src_attr . ' referrerpolicy="strict-origin-when-cross-origin"' . (!empty($i['allow_fullscreen']) ? ' allowfullscreen' : '') . ' title="' . esc_attr__('嵌入内容', 'aksrt') . '"></iframe></div>';
}
private static function render_media_cards(array $i): string {
+10 -4
View File
@@ -16,13 +16,19 @@ final class SliderRenderer {
continue;
}
$link = RendererHelpers::link((array) ($slide['link'] ?? []));
$media = !empty($slide['background_video'])
? '<video src="' . esc_url((string) $slide['background_video']) . '" muted loop playsinline preload="metadata"></video>'
: RendererHelpers::image((string) $slide['background'], (string) ($slide['title'] ?? ''), 'swiper-lazy');
if (!empty($slide['background_video'])) {
$video = esc_url((string) $slide['background_video']);
$video_attr = aksrt_is_lazy('lazy_sider')
? ' class="lazyload" src="" data-src="' . $video . '"'
: ' src="' . $video . '"';
$media = '<video' . $video_attr . ' muted loop playsinline preload="metadata"></video>';
} else {
$media = RendererHelpers::image((string) $slide['background'], (string) ($slide['title'] ?? ''), '', 'lazy_sider', aksrt_get_lazy_thumb('lg'));
}
$layers = '';
foreach ((array) ($slide['layers'] ?? []) as $layer) {
if (!empty($layer['image'])) {
$layers .= '<img class="aksrt-slide-layer" src="' . esc_url((string) $layer['image']) . '" alt="" data-swiper-parallax="' . (int) ($layer['parallax'] ?? 0) . '" data-swiper-parallax-scale="' . esc_attr((string) ((float) ($layer['scale'] ?? 100) / 100)) . '">';
$layers .= '<img' . aksrt_get_lazy_attr('lazy_sider', (string) $layer['image'], 'aksrt-slide-layer', aksrt_get_lazy_thumb('lg')) . ' alt="" data-swiper-parallax="' . (int) ($layer['parallax'] ?? 0) . '" data-swiper-parallax-scale="' . esc_attr((string) ((float) ($layer['scale'] ?? 100) / 100)) . '">';
}
}
$copy = '<div class="aksrt-slide-copy is-' . esc_attr((string) ($slide['text_align'] ?? 'left-bottom')) . '"><h3>' . esc_html((string) ($slide['title'] ?? '')) . '</h3><p>' . esc_html((string) ($slide['description'] ?? '')) . '</p></div>';
+1 -1
View File
@@ -237,7 +237,7 @@ if (!$messages_base) {
<div class="aksrt-pm__item<?php echo !empty($conv['unread']) ? ' is-unread' : ''; ?>"
data-conv-id="<?php echo esc_attr((string) ($conv['id'] ?? '')); ?>"
data-other-id="<?php echo esc_attr((string) ($conv['other_user_id'] ?? '')); ?>">
<img class="aksrt-pm__avatar" src="<?php echo esc_url((string) ($conv['other_avatar'] ?? '')); ?>" alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('avatar') : ' loading="lazy"'; ?> />
<img<?php echo aksrt_get_lazy_attr('lazy_private', (string) ($conv['other_avatar'] ?? ''), 'aksrt-pm__avatar', aksrt_get_lazy_thumb('sm')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
<div class="aksrt-pm__info">
<div class="aksrt-pm__name">
<?php echo esc_html((string) ($conv['other_name'] ?? '')); ?>
+1 -2
View File
@@ -35,9 +35,8 @@ if (empty($images)) return;
class="content-gallery__link"
<?php echo $lightbox ? 'data-lightbox="gallery"' : ''; ?>
data-caption="<?php echo esc_attr($caption); ?>">
<img src="<?php echo esc_url($src); ?>"
<img<?php echo aksrt_get_lazy_attr('lazy_posts_content', (string) $src, 'content-gallery__img', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
alt="<?php echo esc_attr($alt); ?>"
class="content-gallery__img"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('content') : ' loading="lazy"'; ?>
width="<?php echo esc_attr($img['width'] ?? 800); ?>"
height="<?php echo esc_attr($img['height'] ?? 600); ?>">
</a>
+31 -174
View File
@@ -1,174 +1,31 @@
<?php
/**
* Post Card / List Item Template — Unified Wrapper (v4.0)
*
* This template delegates to the unified shared renderer (aksrt_render_post).
* It preserves backward compatibility for callers using get_template_part().
*
* @package AKSRT
* @since 4.0.0
*/
defined('ABSPATH') || exit;
// If the shared renderer is available, delegate entirely
if (function_exists('aksrt_render_post')) {
$args = isset($args) && is_array($args) ? $args : [];
// Resolve layout mode from query var or args
$forced_layout = (string) get_query_var('aksrt_post_card_layout', '');
$mode = 'card';
if (is_string($forced_layout) && in_array($forced_layout, ['card', 'list', 'grid-cms'], true)) {
$mode = $forced_layout;
} elseif (!empty($args['mode']) && in_array($args['mode'], ['card', 'list', 'grid-cms', 'mini'], true)) {
$mode = $args['mode'];
} elseif (function_exists('aksrt_get_post_flow') && aksrt_get_post_flow(get_the_ID()) === 'cms') {
$mode = 'grid-cms';
} elseif (class_exists('\AKSRT\Settings\Settings')) {
$archive_layout = \AKSRT\Settings\Settings::get_archive_layout();
$mode = in_array($archive_layout, ['card', 'list', 'grid-cms'], true) ? $archive_layout : 'card';
}
// Resolve scene context
$scene = (string) get_query_var('aksrt_post_card_scene', '');
$context = ($scene === 'home' || is_front_page() || (is_home() && !is_paged())) ? 'home' : 'archive';
$config = array_merge($args, [
'mode' => $mode,
'context' => $context,
]);
echo aksrt_render_post($config); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
return;
}
// ============================================================
// Fallback: self-contained rendering when shared renderer unavailable
// ============================================================
$args = isset($args) && is_array($args) ? $args : [];
$lazy_cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_lazyload_config() : ['enabled' => false, 'placeholder_url' => ''];
$lazy_on = !empty($lazy_cfg['enabled']);
$placeholder_url = !empty($lazy_cfg['placeholder_url']) ? (string) $lazy_cfg['placeholder_url'] : (get_template_directory_uri() . '/assets/img/placeholder.svg');
$forced_layout = (string) get_query_var('aksrt_post_card_layout', '');
$layout = 'card';
if (is_string($forced_layout) && in_array($forced_layout, ['card', 'list', 'masonry', 'grid-cms'], true)) {
$layout = $forced_layout;
} elseif (function_exists('aksrt_get_post_flow') && aksrt_get_post_flow(get_the_ID()) === 'cms') {
$layout = 'grid-cms';
} elseif (class_exists('\AKSRT\Settings\Settings')) {
$layout = \AKSRT\Settings\Settings::get_archive_layout();
}
$post_id = get_the_ID();
$author_id = get_the_author_meta('ID');
$author = get_the_author();
$avatar_url = get_avatar_url($author_id, ['size' => 40]);
$time_ago = human_time_diff(get_the_time('U'), current_time('timestamp')) . __('前', 'aksrt');
$excerpt = wp_trim_words(get_the_excerpt(), 'list' === $layout ? 30 : 20, '...');
$tags = get_the_tags() ?: [];
$categories = get_the_category() ?: [];
$comment_count = (int) get_comments_number();
$views = function_exists('aksrt_get_post_views') ? aksrt_get_post_views($post_id) : 0;
$is_sticky = is_sticky($post_id);
$title_html = isset($args['title_html']) ? (string) $args['title_html'] : get_the_title();
$resource_badge = function_exists('aksrt_resource_card_badge_text') ? aksrt_resource_card_badge_text($post_id) : '';
$img_url = '';
if (has_post_thumbnail()) {
$img_url = get_the_post_thumbnail_url($post_id, 'medium_large');
} elseif (function_exists('aksrt_get_first_content_image_url')) {
$img_url = (string) aksrt_get_first_content_image_url($post_id);
}
$has_img = !empty($img_url);
$scene = (string) get_query_var('aksrt_post_card_scene', '');
$is_home_scene = $scene === 'home' || is_front_page() || (is_home() && !is_paged());
$category_limit = $is_home_scene ? 1 : 3;
$tag_limit = $is_home_scene ? 2 : 3;
// Badges HTML
ob_start();
?>
<div class="item-tags scroll-x no-scrollbar">
<?php if ($resource_badge !== '') : ?>
<a rel="nofollow" href="<?php echo esc_url(get_permalink($post_id) . '#posts-pay'); ?>" class="meta-pay but jb-yellow"><?php echo esc_html($resource_badge); ?></a>
<?php endif; ?>
<?php foreach (array_slice($categories, 0, $category_limit) as $category) : ?>
<a href="<?php echo esc_url(get_category_link($category->term_id)); ?>" class="but"><i class="far fa-folder-open" aria-hidden="true"></i> <?php echo esc_html($category->name); ?></a>
<?php endforeach; ?>
<?php foreach (array_slice($tags, 0, $tag_limit) as $tag) : ?>
<a href="<?php echo esc_url(get_tag_link($tag->term_id)); ?>" class="but"># <?php echo esc_html($tag->name); ?></a>
<?php endforeach; ?>
</div>
<?php
$badges_html = trim((string) ob_get_clean());
// Meta HTML
ob_start();
?>
<div class="item-meta muted-2-color flex jsb ac">
<item class="meta-author flex ac">
<img src="<?php echo esc_url($avatar_url); ?>" alt="" class="avatar-mini" width="20" height="20" loading="lazy">
<name class="meta-name"><?php echo esc_html($author); ?></name>
<item class="meta-time"><?php echo esc_html($time_ago); ?></item>
</item>
<div class="meta-right">
<item class="meta-view"><i class="fas fa-eye" aria-hidden="true"></i> <?php echo esc_html(function_exists('aksrt_format_number') ? aksrt_format_number($views) : (string) $views); ?></item>
<item class="meta-view"><i class="fas fa-comment" aria-hidden="true"></i> <?php echo esc_html((string) $comment_count); ?></item>
</div>
</div>
<?php
$meta_html = trim((string) ob_get_clean());
if ('list' === $layout) : ?>
<article <?php post_class('posts-item list ajax-item'); ?>>
<div class="item-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php if ($has_img && $lazy_on) : ?>
<span class="aksrt-skeleton"></span>
<img class="fit-cover aksrt-lazy" data-src="<?php echo esc_url($img_url); ?>" src="<?php echo esc_url($placeholder_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
<?php elseif ($has_img) : ?>
<img class="fit-cover" src="<?php echo esc_url($img_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
<?php else : ?>
<img class="fit-cover" src="<?php echo esc_url($placeholder_url); ?>" alt="">
<?php endif; ?>
</a>
<?php if ($is_sticky) : ?>
<span class="img-badge left badge-sticky"><?php esc_html_e('置顶', 'aksrt'); ?></span>
<?php endif; ?>
</div>
<div class="item-body">
<h2 class="item-heading"><a href="<?php the_permalink(); ?>"><?php echo wp_kses_post($title_html); ?></a></h2>
<p class="item-excerpt"><?php echo wp_kses_post(esc_html($excerpt)); ?></p>
<?php echo $badges_html; ?>
<?php echo $meta_html; ?>
</div>
</article>
<?php else : ?>
<article <?php post_class('posts-item card ajax-item' . ($is_home_scene ? ' posts-item--home' : '')); ?>>
<div class="item-thumbnail">
<a href="<?php the_permalink(); ?>">
<?php if ($has_img && $lazy_on) : ?>
<span class="aksrt-skeleton"></span>
<img class="fit-cover aksrt-lazy" data-src="<?php echo esc_url($img_url); ?>" src="<?php echo esc_url($placeholder_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
<?php elseif ($has_img) : ?>
<img class="fit-cover" src="<?php echo esc_url($img_url); ?>" alt="<?php echo esc_attr(get_the_title()); ?>">
<?php else : ?>
<img class="fit-cover" src="<?php echo esc_url($placeholder_url); ?>" alt="">
<?php endif; ?>
</a>
<?php if ($is_sticky) : ?>
<span class="img-badge left badge-sticky"><?php esc_html_e('置顶', 'aksrt'); ?></span>
<?php endif; ?>
</div>
<div class="item-body">
<h2 class="item-heading"><a href="<?php the_permalink(); ?>"><?php echo wp_kses_post($title_html); ?></a></h2>
<?php echo $badges_html; ?>
<?php echo $meta_html; ?>
</div>
</article>
<?php endif; ?>
<?php
/**
* Post card wrapper for the unified renderer.
*
* @package AKSRT
*/
defined('ABSPATH') || exit;
$args = isset($args) && is_array($args) ? $args : [];
$forced_layout = (string) get_query_var('aksrt_post_card_layout', '');
$mode = 'card';
if (in_array($forced_layout, ['card', 'list', 'grid-cms'], true)) {
$mode = $forced_layout;
} elseif (!empty($args['mode']) && in_array($args['mode'], ['card', 'list', 'grid-cms', 'mini'], true)) {
$mode = (string) $args['mode'];
} elseif (function_exists('aksrt_get_post_flow') && aksrt_get_post_flow(get_the_ID()) === 'cms') {
$mode = 'grid-cms';
} elseif (class_exists('\AKSRT\Settings\Settings')) {
$archive_layout = \AKSRT\Settings\Settings::get_archive_layout();
$mode = in_array($archive_layout, ['card', 'list', 'grid-cms'], true) ? $archive_layout : 'card';
}
$scene = (string) get_query_var('aksrt_post_card_scene', '');
$context = ($scene === 'home' || is_front_page() || (is_home() && !is_paged())) ? 'home' : 'archive';
echo aksrt_render_post(array_merge($args, [
'mode' => $mode,
'context' => $context,
])); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
+1 -1
View File
@@ -24,7 +24,7 @@ $excerpt = wp_trim_words(get_the_excerpt(), 30, '...');
<a href="<?php the_permalink(); ?>" class="aksrt-doc-index-card">
<?php if ($thumb) : ?>
<div class="aksrt-doc-index-card__thumb">
<img src="<?php echo esc_url($thumb); ?>" alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $thumb); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<?php else : ?>
<div class="aksrt-doc-index-card__icon">
@@ -70,12 +70,9 @@ $swiper_config = [
<div class="<?php echo esc_attr($slide_classes); ?>"<?php if (!empty($slide['link'])) : ?> data-link="<?php echo esc_url($slide['link']); ?>" data-target="<?php echo esc_attr($link_target); ?>"<?php endif; ?>>
<div class="banner-module__slide-bg">
<?php if (!empty($slide['image'])) : ?>
<img
src="<?php echo esc_url($slide['image']); ?>"
<img<?php echo aksrt_get_lazy_attr('lazy_sider', (string) $slide['image'], 'fit-cover', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
alt="<?php echo esc_attr($slide['title'] ?: get_bloginfo('name')); ?>"
loading="<?php echo 0 === $index ? 'eager' : 'lazy'; ?>"
decoding="async"
class="fit-cover"
>
<?php else : ?>
<div class="banner-module__slide-fallback"></div>
@@ -23,10 +23,7 @@ $show_dates = !isset($cfg['show_dates']) || !empty($cfg['show_dates']);
if (empty($cat_ids)) return;
// 懒加载配置
$lazy_cfg = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Settings::get_lazyload_config() : ['enabled' => false, 'placeholder_url' => ''];
$lazy_on = !empty($lazy_cfg['enabled']);
$placeholder = $lazy_cfg['placeholder_url'] ?: (get_template_directory_uri() . '/assets/img/placeholder.svg');
$placeholder = aksrt_get_lazy_thumb('lg');
// 组装卡片数据
$cards = [];
@@ -84,12 +81,7 @@ if (empty($cards)) return;
<?php if ($show_views && $card['views'] > 0) : ?>
<span class="cat-card__views"><?php echo esc_html(function_exists('aksrt_format_number') ? aksrt_format_number($card['views']) : number_format_i18n($card['views'])); ?></span>
<?php endif; ?>
<?php if ($lazy_on) : ?>
<span class="aksrt-skeleton"></span>
<img class="cat-card__cover aksrt-lazy" data-src="<?php echo esc_url($card['cover']); ?>" src="<?php echo esc_url($placeholder); ?>" alt="<?php echo esc_attr($card['term']->name); ?>">
<?php else : ?>
<img class="cat-card__cover" src="<?php echo esc_url($card['cover']); ?>" alt="<?php echo esc_attr($card['term']->name); ?>">
<?php endif; ?>
<img<?php echo aksrt_get_lazy_attr('lazy_cover', (string) $card['cover'], 'cat-card__cover', $placeholder); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($card['term']->name); ?>">
</div>
<div class="cat-card__info">
<div>
@@ -32,7 +32,7 @@ if (empty($friend_links)) return;
<li>
<a href="<?php echo esc_url($url); ?>" target="_blank" rel="noopener noreferrer external" class="home-module__friend-card">
<?php if ($logo) : ?>
<img src="<?php echo esc_url($logo); ?>" alt="" class="home-module__friend-avatar"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $logo, 'home-module__friend-avatar'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
<?php endif; ?>
<div class="home-module__friend-meta">
<strong><?php echo esc_html($name); ?></strong>
+13 -11
View File
@@ -377,16 +377,18 @@ if (!empty($hero_banners)) :
}
// Background media (zibll order: video > image).
$s_background = '';
if ($use_video) {
$poster = $image_url !== '' ? ' poster="' . esc_url($image_url) . '"' : '';
$s_background = '<video autoplay loop muted playsinline class="fit-cover radius8" src="' . esc_url($video_url) . '"' . $poster . '></video><div class="absolute"></div>';
} elseif ($image_url !== '') {
$s_background = '<img class="fit-cover radius8' . ($index > 0 ? ' lazyload swiper-lazy' : '') . '"'
. ($index > 0
? ' data-src="' . esc_url($image_url) . '" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7"'
: ' src="' . esc_url($image_url) . '"')
. ' alt="' . esc_attr($img_alt) . '">';
$s_background = '';
if ($use_video) {
if (aksrt_is_lazy('lazy_sider')) {
$poster = $image_url !== '' ? ' data-poster="' . esc_url($image_url) . '"' : '';
$video_src = ' class="fit-cover radius8 lazyload" src="" data-src="' . esc_url($video_url) . '"';
} else {
$poster = $image_url !== '' ? ' poster="' . esc_url($image_url) . '"' : '';
$video_src = ' class="fit-cover radius8" src="' . esc_url($video_url) . '"';
}
$s_background = '<video autoplay loop muted playsinline' . $video_src . $poster . '></video><div class="absolute"></div>';
} elseif ($image_url !== '') {
$s_background = '<img' . aksrt_get_lazy_attr('lazy_sider', $image_url, 'fit-cover radius8', aksrt_get_lazy_thumb('lg')) . ' alt="' . esc_attr($img_alt) . '">';
} else {
continue;
}
@@ -403,7 +405,7 @@ if (!empty($hero_banners)) :
if ($layer_image === '') {
continue;
}
$layer_img = '<img class="radius8 lazyload swiper-lazy" data-src="' . esc_url($layer_image) . '" src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7" alt="' . esc_attr($img_alt) . '">';
$layer_img = '<img' . aksrt_get_lazy_attr('lazy_sider', $layer_image, 'radius8', aksrt_get_lazy_thumb('lg')) . ' alt="' . esc_attr($img_alt) . '">';
$layer_parallax = isset($layer['parallax']) ? (int) $layer['parallax'] : 0;
$layer_attr = $layer_parallax ? ' data-swiper-parallax="' . $layer_parallax . '%"' : '';
$layer_class = !empty($layer['free_size']) ? ' slide-layer' : '';
@@ -38,7 +38,7 @@ if (empty($items)) return;
?>
<<?php echo esc_attr($card_tag); ?> class="aksrt-highlight-card"<?php echo $card_attrs; ?>>
<?php if ($item_image !== '') : ?>
<img class="aksrt-highlight-card__image" src="<?php echo esc_url($item_image); ?>" alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $item_image, 'aksrt-highlight-card__image'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
<?php elseif ($item_icon !== '') : ?>
<div class="aksrt-highlight-card__icon"><i class="<?php echo esc_attr($item_icon); ?>"></i></div>
<?php endif; ?>
+1 -1
View File
@@ -57,7 +57,7 @@ if (empty($categories)) {
<a href="<?php echo esc_url($cat_link); ?>" class="home-module__more-link">
<?php if ($cover) : ?>
<div class="home-module__more-cover">
<img src="<?php echo esc_url($cover); ?>" alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $cover); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
</div>
<?php else : ?>
<div class="home-module__more-cover home-module__more-cover--placeholder">
@@ -40,7 +40,7 @@ if (empty($items)) return;
?>
<<?php echo esc_attr($tag); ?> class="aksrt-marquee__item"<?php echo $attrs; ?>>
<?php if ($image !== '') : ?>
<img src="<?php echo esc_url($image); ?>" alt="<?php echo esc_attr($name); ?>"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $image); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($name); ?>">
<?php else : ?>
<span><?php echo esc_html($name); ?></span>
<?php endif; ?>
@@ -36,7 +36,7 @@ if (empty($products)) return;
<a href="<?php echo esc_url($p_url ?: '#'); ?>" class="aksrt-product-card">
<?php if ($p_image !== '') : ?>
<div class="aksrt-product-card__image">
<img src="<?php echo esc_url($p_image); ?>" alt="<?php echo esc_attr($p_title); ?>"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $p_image); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($p_title); ?>">
</div>
<?php endif; ?>
<div class="aksrt-product-card__body">
+1 -1
View File
@@ -65,7 +65,7 @@ if (empty($users)) {
?>
<div class="home-module__user-card">
<a href="<?php echo esc_url($profile); ?>" class="home-module__user-link">
<img src="<?php echo esc_url($avatar); ?>" alt="" class="home-module__user-avatar"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_avatar', (string) $avatar, 'home-module__user-avatar', aksrt_get_lazy_thumb('sm')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
<strong class="home-module__user-name"><?php echo esc_html($display); ?></strong>
</a>
<?php if ($bio) : ?>
+1 -1
View File
@@ -185,7 +185,7 @@ if ($is_need_purchase && $user_amount > 0) {
<div class="resource-download-box__body">
<?php if ($has_thumbnail) : ?>
<div class="resource-download-box__thumb-col">
<img class="resource-download-box__thumb" src="<?php echo esc_url($thumbnail); ?>" alt="<?php echo esc_attr(get_the_title()); ?>"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('other') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_other', (string) $thumbnail, 'resource-download-box__thumb'); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr(get_the_title()); ?>">
<?php if ($pay_type_badge) : ?>
<div class="resource-download-box__pay-tag"><?php echo $pay_type_badge; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?></div>
<?php endif; ?>
+1 -1
View File
@@ -54,7 +54,7 @@ extract($args, EXTR_SKIP); // phpcs:ignore WordPress.PHP.DontExtract.extract_ext
<a class="uh-follow__item" href="<?php echo esc_url($profile); ?>">
<span class="uh-follow__avatar">
<?php if ($avatar !== '') : ?>
<img src="<?php echo esc_url($avatar); ?>" alt="" width="48" height="48" loading="lazy">
<img<?php echo aksrt_get_lazy_attr('lazy_avatar', (string) $avatar, 'avatar', aksrt_get_lazy_thumb('sm')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="" width="48" height="48">
<?php else : ?>
<?php echo get_avatar($uid, 48); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?>
<?php endif; ?>
+1 -3
View File
@@ -62,9 +62,7 @@ $pm_url = ($pm_enabled && $messages_url !== '')
<div class="aksrt-author-hero<?php echo $show_cover ? '' : ' aksrt-author-hero--no-cover'; ?>">
<?php if ($show_cover) : ?>
<div class="aksrt-author-hero__cover">
<img class="aksrt-author-hero__cover-img"
src="<?php echo esc_url($bg_url ? $bg_url : get_theme_file_uri('assets/img/person_background.png')); ?>"
alt=""<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('cover') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_cover', (string) ($bg_url ? $bg_url : get_theme_file_uri('assets/img/person_background.png')), 'aksrt-author-hero__cover-img', aksrt_get_lazy_thumb('lg')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="">
<div class="aksrt-author-hero__cover-mask"></div>
<?php if ($follower_count > 0) : ?>
<div class="aksrt-author-hero__cover-metas" aria-label="<?php esc_attr_e('主页数据', 'aksrt'); ?>">
+1 -1
View File
@@ -41,7 +41,7 @@ $show_credits = class_exists('\AKSRT\Settings\Settings') ? \AKSRT\Settings\Setti
?>
<div class="aksrt-profile-card aksrt-profile-card--shortcode">
<a class="aksrt-profile-card__avatar" href="<?php echo esc_url($home_url); ?>">
<img src="<?php echo esc_url($avatar); ?>" alt="<?php echo esc_attr($user->display_name); ?>" width="64" height="64"<?php echo function_exists('aksrt_lazy_loading') ? aksrt_lazy_loading('avatar') : ' loading="lazy"'; ?>>
<img<?php echo aksrt_get_lazy_attr('lazy_avatar', (string) $avatar, 'avatar', aksrt_get_lazy_thumb('sm')); // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped ?> alt="<?php echo esc_attr($user->display_name); ?>" width="64" height="64">
</a>
<div class="aksrt-profile-card__body">
<a class="aksrt-profile-card__name" href="<?php echo esc_url($home_url); ?>"><?php echo esc_html($user->display_name); ?></a>
@@ -0,0 +1,138 @@
'use strict';
const assert = require('node:assert/strict');
const { spawnSync } = require('node:child_process');
const fs = require('node:fs');
const path = require('node:path');
const test = require('node:test');
const root = path.resolve(__dirname, '..', '..');
const read = (file) => fs.readFileSync(path.join(root, file), 'utf8');
const lazyDefaults = {
lazy_posts_thumb: true,
lazy_avatar: true,
lazy_posts_content: false,
lazy_comment: true,
lazy_private: true,
lazy_sider: true,
lazy_cover: true,
lazy_other: true,
lazy_animation: 'blur',
};
function phpHarness(body, values = {}, userAgent = 'Mozilla/5.0') {
const helper = path.join(root, 'inc/helpers/template-tags/pagination-permissions.php');
const code = `
define('ABSPATH', __DIR__);
$_SERVER['HTTP_USER_AGENT'] = ${JSON.stringify(userAgent)};
function add_filter() {}
function add_action() {}
function is_admin() { return false; }
function wp_doing_ajax() { return false; }
function sanitize_key($value) { return preg_replace('/[^a-z0-9_\\-]/', '', strtolower($value)); }
function esc_attr($value) { return htmlspecialchars((string) $value, ENT_QUOTES); }
function esc_url($value) { return (string) $value; }
function get_template_directory_uri() { return 'https://theme.test'; }
function aksrt_get_default_avatar_url() { return 'https://theme.test/default-avatar.png'; }
eval('namespace AKSRT\\\\Settings; class Settings { public static $values = []; public static function get_value($key, $default = null) { return array_key_exists($key, self::$values) ? self::$values[$key] : $default; } }');
\\AKSRT\\Settings\\Settings::$values = json_decode(${JSON.stringify(JSON.stringify(values))}, true);
require ${JSON.stringify(helper)};
${body}
`;
const result = spawnSync('php', ['-r', code], { cwd: root, encoding: 'utf8' });
assert.equal(result.status, 0, result.stderr || result.stdout);
return result.stdout.trim();
}
function sourceFiles(directory) {
const output = [];
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
if (entry.name === '.git' || entry.name === '.claude' || entry.name === 'build' || entry.name === 'vendor' || entry.name === 'node_modules' || entry.name === 'third-party') continue;
if (/\.min\.(?:js|css)$/.test(entry.name)) continue;
const full = path.join(directory, entry.name);
if (entry.isDirectory()) output.push(...sourceFiles(full));
else if (/\.(?:php|js|vue|css)$/.test(entry.name)) output.push(full);
}
return output;
}
test('admin schemas expose the ten Zibll lazy fields and defaults', () => {
const php = read('src/Admin/Schema/GlobalSchema.php');
const vue = read('assets/admin/src/schema/sections/global/common.js');
for (const [key, value] of Object.entries(lazyDefaults)) {
const literal = typeof value === 'string' ? `'${value}'` : String(value);
assert.match(php, new RegExp(`'key'\\s*=>\\s*'${key}'[\\s\\S]*?'default'\\s*=>\\s*${literal}`));
assert.match(vue, new RegExp(`${key}:\\s*${literal}`));
}
assert.match(php, /'key'\s*=>\s*'thumbnail'[\s\S]*?thumbnail\.svg/);
assert.match(vue, /thumbnail:\s*defaultThumbnail/);
});
test('PHP helpers emit placeholder/data-src, direct src, and crawler bypass', () => {
const enabled = phpHarness("echo aksrt_get_lazy_attr('lazy_posts_thumb', 'https://cdn.test/post.webp', 'fit-cover');");
assert.match(enabled, /class="lazyload fit-cover"/);
assert.match(enabled, /src="https:\/\/theme\.test\/assets\/img\/thumbnail\.svg"/);
assert.match(enabled, /data-src="https:\/\/cdn\.test\/post\.webp"/);
const disabled = phpHarness("echo aksrt_get_lazy_attr('lazy_posts_thumb', 'https://cdn.test/post.webp', 'fit-cover');", { lazy_posts_thumb: false });
assert.equal(disabled, 'class="fit-cover" src="https://cdn.test/post.webp"');
const crawler = phpHarness("echo aksrt_get_lazy_attr('lazy_posts_thumb', 'https://cdn.test/post.webp', 'fit-cover');", {}, 'Googlebot/2.1');
assert.equal(crawler, 'class="fit-cover" src="https://cdn.test/post.webp"');
const empty = phpHarness("echo aksrt_get_lazy_attr('lazy_other', '', 'media');");
assert.equal(empty, 'class="media" src=""');
});
test('content, avatar, and responsive image paths follow one contract', () => {
const content = phpHarness(`
$html = '<img class="hero" src="https://cdn.test/photo.jpg" srcset="https://cdn.test/photo-2x.jpg 2x">';
echo aksrt_lazy_content_images($html);
`, { lazy_posts_content: true });
assert.match(content, /thumbnail-lg\.svg/);
assert.match(content, /data-src="https:\/\/cdn\.test\/photo\.jpg"/);
assert.match(content, /data-srcset="https:\/\/cdn\.test\/photo-2x\.jpg 2x"/);
assert.doesNotMatch(content, /\ssrcset=/);
const avatar = phpHarness("echo aksrt_lazy_avatar_html('<img class=\"avatar\" src=\"https://cdn.test/avatar.png\" loading=\"lazy\">');");
assert.match(avatar, /class="lazyload avatar"/);
assert.match(avatar, /src="https:\/\/theme\.test\/default-avatar\.png"/);
assert.match(avatar, /data-src="https:\/\/cdn\.test\/avatar\.png"/);
assert.doesNotMatch(avatar, /loading=/);
});
test('one lazySizes runtime owns dynamic media, backgrounds, videos, and IAS', () => {
const runtime = read('assets/js/lazysizes.js');
const scripts = read('src/Core/ScriptsPart1c.php');
const pagination = read('assets/js/core/pagination.js');
const widgets = read('assets/widgets/frontend.js');
assert.match(scripts, /'aksrt-lazysizes'/);
assert.match(scripts, /'aksrt-rehydrate'[\s\S]*?\['aksrt-lazysizes'\]/);
assert.match(runtime, /lazybeforeunveil/);
assert.match(runtime, /source\[data-src\],source\[data-srcset\]/);
assert.match(runtime, /data-bg/);
assert.match(runtime, /lazyload-action/);
assert.match(runtime, /element\.hasAttribute\('remote-box'\)[\s\S]*?element\.click\(\)/);
assert.doesNotMatch(pagination, /IntersectionObserver|new Image\(/);
assert.doesNotMatch(widgets, /IntersectionObserver/);
});
test('legacy lazy identifiers and theme-native loading attributes are gone', () => {
const files = sourceFiles(root).filter((file) => !file.endsWith('lazyload-contract.test.cjs'));
const source = files.map((file) => fs.readFileSync(file, 'utf8')).join('\n');
const forbidden = [
'data-' + 'lazy-animation',
'lazyload_' + 'enabled',
'get_' + 'lazyload_config',
'aksrt_' + 'lazy_img_attrs',
'aksrt_' + 'lazy_loading',
];
for (const token of forbidden) assert.equal(source.includes(token), false, token);
assert.doesNotMatch(source, /aksrt-lazy(?!sizes)/);
assert.doesNotMatch(source, /aksrt-loaded/);
assert.doesNotMatch(source, /loading=["'](?:lazy|eager)["']/);
assert.doesNotMatch(source, /\.loading\s*=\s*["'](?:lazy|eager)["']/);
assert.doesNotMatch(source, /setAttribute\(\s*["']loading["']/);
});