From e1039dcee40850c88cdbd7893ce0339a360bf0b8 Mon Sep 17 00:00:00 2001
From: nanhaoluo <3075912108@qq.com>
Date: Mon, 12 Jan 2026 15:17:52 +0800
Subject: [PATCH] =?UTF-8?q?feat:=20=E7=A7=BB=E9=99=A4=20lazyload=20?=
=?UTF-8?q?=E6=8F=92=E4=BB=B6=EF=BC=8C=E6=94=B9=E7=94=A8=E6=B5=8F=E8=A7=88?=
=?UTF-8?q?=E5=99=A8=E5=8E=9F=E7=94=9F=E6=87=92=E5=8A=A0=E8=BD=BD?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
argontheme.js | 88 ++--------------------------
functions.php | 26 +++-----
header.php | 17 +-----
single.php | 2 +-
style.css | 11 +---
template-parts/content-preview-1.php | 10 +---
template-parts/content-preview-2.php | 10 +---
template-parts/content-preview-3.php | 10 +---
template-parts/emotion-keyboard.php | 2 +-
9 files changed, 22 insertions(+), 154 deletions(-)
diff --git a/argontheme.js b/argontheme.js
index af5cc5b..3906a85 100644
--- a/argontheme.js
+++ b/argontheme.js
@@ -1425,7 +1425,7 @@ if (argonConfig.waterflow_columns != "1") {
timeout: 5000
});
//插入新评论
- result.html = result.html.replace(//g, "").replace(/<(\/).noscript>/g, "");
+ result.html = result.html.replace(/<(\/).noscript>/g, "");
let parentID = result.parentID;
if (parentID == "" || parentID == null){
parentID = 0;
@@ -1611,7 +1611,7 @@ if (argonConfig.waterflow_columns != "1") {
}
//发送成功,替换原评论
- result.new_comment = result.new_comment.replace(/
/g, "").replace(/<(\/).noscript>/g, "");
+ result.new_comment = result.new_comment.replace(/<(\/).noscript>/g, "");
$("#comment-" + editID + " .comment-item-text").html(result.new_comment);
$("#comment-" + editID + " .comment-item-source").html(result.new_comment_source);
if ($("#comment-" + editID + " .comment-info .comment-edited").length == 0){
@@ -1857,20 +1857,16 @@ $(document).on("click" , ".comment-upvote" , function(){
});
/*评论表情面板*/
function lazyloadStickers(){
- if (typeof $.fn.lazyload !== 'function') return;
- $(".emotion-keyboard .emotion-group:not(d-none) .emotion-item > img.lazyload").lazyload({threshold: 500, effect: "fadeIn"}).removeClass("lazyload");
- $("html").trigger("scroll");
+ // 原生懒加载无需额外处理
}
$(document).on("click" , "#comment_emotion_btn" , function(){
$("#comment_emotion_btn").toggleClass("comment-emotion-keyboard-open");
- lazyloadStickers();
});
$(document).on("click" , ".emotion-keyboard .emotion-group-name" , function(){
$(".emotion-keyboard .emotion-group-name.active").removeClass("active");
$(this).addClass("active");
$(".emotion-keyboard .emotion-group:not(d-none)").addClass("d-none");
$(".emotion-keyboard .emotion-group[index='" + $(this).attr("index") + "']").removeClass("d-none");
- lazyloadStickers();
});
function inputInsertText(text, input){
$(input).focus();
@@ -2043,9 +2039,6 @@ $(document).on("submit" , ".post-password-form" , function(){
foldLongComments();
calcHumanTimesOnPage();
panguInit();
- if (typeof $.fn.lazyload === 'function') {
- $(".comment-item-text .comment-sticker.lazyload").lazyload(argonConfig.lazyload).removeClass("lazyload");
- }
},
error : function(){
window.location.href = url;
@@ -2077,9 +2070,6 @@ $(document).on("submit" , ".post-password-form" , function(){
foldLongComments();
calcHumanTimesOnPage();
panguInit();
- if (typeof $.fn.lazyload === 'function') {
- $(".comment-item-text .comment-sticker.lazyload").lazyload(argonConfig.lazyload).removeClass("lazyload");
- }
},
error : function(){
window.location.href = url;
@@ -2179,76 +2169,10 @@ $.fancybox.defaults.i18n = {
}
};
-/*Lazyload*/
+/*Lazyload - 已改用浏览器原生 loading="lazy"*/
function lazyloadInit(){
- if (argonConfig.lazyload == false){
- return;
- }
- // 检查 lazyload 插件是否已加载
- if (typeof $.fn.lazyload !== 'function') {
- // 插件未加载,延迟重试
- setTimeout(lazyloadInit, 100);
- return;
- }
- var lazyloadEffect = argonConfig.lazyload.effect;
- if (lazyloadEffect == "none"){
- lazyloadEffect = undefined;
- }
-
- // 文章内图片和相关文章缩略图
- $("article img.lazyload:not(.lazyload-loaded) , .related-post-thumbnail.lazyload:not(.lazyload-loaded) , .shuoshuo-preview-container img.lazyload:not(.lazyload-loaded)").lazyload({
- threshold: argonConfig.lazyload.threshold,
- effect: lazyloadEffect,
- load: function () {
- $(this).addClass("lazyload-loaded");
- $(this).parent().removeClass("lazyload-container-unload");
- }
- });
-
- // 文章特色图片 - 确保加载后显示
- $(".post-thumbnail.lazyload:not(.lazyload-loaded)").each(function() {
- var $img = $(this);
- var originalSrc = $img.attr("data-original");
-
- if (originalSrc) {
- // 创建一个新图片对象来预加载
- var img = new Image();
- img.onload = function() {
- $img.attr("src", originalSrc);
- $img.addClass("lazyload-loaded");
- $img.css("opacity", "1");
- $img.parent().removeClass("lazyload-container-unload");
- waterflowInit();
- };
- img.onerror = function() {
- // 图片加载失败,隐藏图片容器
- $img.closest(".post-header-with-thumbnail").removeClass("post-header-with-thumbnail");
- $img.remove();
- waterflowInit();
- };
- img.src = originalSrc;
- }
- });
-
- // 也保留原有的 lazyload 调用作为备用
- $(".post-thumbnail.lazyload:not(.lazyload-loaded)").lazyload({
- threshold: argonConfig.lazyload.threshold,
- effect: lazyloadEffect,
- load: function () {
- $(this).addClass("lazyload-loaded");
- $(this).css("opacity", "1");
- $(this).parent().removeClass("lazyload-container-unload");
- waterflowInit();
- }
- });
-
- $(".comment-item-text .comment-sticker.lazyload").lazyload({
- threshold: argonConfig.lazyload.threshold,
- effect: lazyloadEffect,
- load: function(){
- $(this).removeClass("lazyload");
- }
- });
+ // 原生懒加载无需 JS 初始化
+ // 保留此函数以兼容可能的外部调用
}
lazyloadInit();
diff --git a/functions.php b/functions.php
index 88a5fca..5bbebdb 100644
--- a/functions.php
+++ b/functions.php
@@ -989,7 +989,7 @@ function argon_get_comment_text($comment_ID = 0, $args = array()) {
if (!isset($emotion['src']) || mb_strlen($emotion['src']) == 0){
continue;
}
- $comment_text = str_replace(':' . $emotion['code'] . ':', "
", $comment_text);
+ $comment_text = str_replace(':' . $emotion['code'] . ':', "
", $comment_text);
}
}
}
@@ -2262,35 +2262,23 @@ function get_banner_background_url(){
return $url;
}
}
-//Lazyload 对
标签预处理以加载 Lazyload
+//原生懒加载:对
标签添加 loading="lazy" 属性
function argon_lazyload($content){
- $lazyload_loading_style = get_option('argon_lazyload_loading_style');
- if ($lazyload_loading_style == ''){
- $lazyload_loading_style = 'none';
- }
- $lazyload_loading_style = "lazyload-style-" . $lazyload_loading_style;
-
if(!is_feed() && !is_robots() && !is_home()){
- $content = preg_replace('/
)|(<\/img>))/i',"
/i',"
" , $content);
- $content = preg_replace('/
/i',"
" , $content);
+ // 为没有 loading 属性的图片添加 loading="lazy"
+ $content = preg_replace('/
]*)>/i', '
', $content);
}
return $content;
}
function argon_fancybox($content){
if(!is_feed() && !is_robots() && !is_home()){
- if (get_option('argon_enable_lazyload') != 'false'){
- $content = preg_replace('/
)|>|(<\/img>))/i',"