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',"
$0
" , $content); - }else{ - $content = preg_replace('/)|>|(<\/img>))/i',"
$0
" , $content); - } + $content = preg_replace('/)|>|(<\/img>))/i',"
$0
" , $content); } return $content; } function the_content_filter($content){ - if (get_option('argon_enable_lazyload') != 'false'){ - $content = argon_lazyload($content); - } + // 始终使用原生懒加载 + $content = argon_lazyload($content); if (get_option('argon_enable_fancybox') != 'false' && get_option('argon_enable_zoomify') == 'false'){ $content = argon_fancybox($content); } diff --git a/header.php b/header.php index 7c9e365..931b642 100644 --- a/header.php +++ b/header.php @@ -333,21 +333,8 @@ pangu: "", - - - lazyload: { - - threshold: , - - effect: "" - - }, - - - - lazyload: false, - - + // 原生懒加载已启用,无需 JS lazyload 配置 + lazyload: false, fold_long_comments: , diff --git a/single.php b/single.php index 41e195e..f1ff4ba 100644 --- a/single.php +++ b/single.php @@ -185,7 +185,7 @@ if ($hasThumbnail){ - echo ''; + echo ''; } diff --git a/style.css b/style.css index b1c3303..480b26e 100644 --- a/style.css +++ b/style.css @@ -4096,16 +4096,9 @@ html.filter-grayscale { } -.post-thumbnail.lazyload { - +/* 图片加载过渡效果 */ +.post-thumbnail { transition: opacity 0.3s ease 0s; - -} - -.post-thumbnail.lazyload.lazyload-loaded { - - opacity: 1 !important; - } .single .post-thumbnail, diff --git a/template-parts/content-preview-1.php b/template-parts/content-preview-1.php index 77ea948..95feae7 100644 --- a/template-parts/content-preview-1.php +++ b/template-parts/content-preview-1.php @@ -8,15 +8,7 @@ $thumbnail_url = argon_get_post_thumbnail(); - if (get_option('argon_enable_lazyload') != 'false'){ - - echo "thumbnail"; - - }else{ - - echo ""; - - } + echo "thumbnail"; echo "
"; diff --git a/template-parts/content-preview-2.php b/template-parts/content-preview-2.php index fa4d310..1a7f168 100644 --- a/template-parts/content-preview-2.php +++ b/template-parts/content-preview-2.php @@ -8,15 +8,7 @@ $thumbnail_url = argon_get_post_thumbnail(); - if (get_option('argon_enable_lazyload') != 'false'){ - - echo "thumbnail"; - - }else{ - - echo ""; - - } + echo "thumbnail"; } diff --git a/template-parts/content-preview-3.php b/template-parts/content-preview-3.php index 81df340..c6a9040 100644 --- a/template-parts/content-preview-3.php +++ b/template-parts/content-preview-3.php @@ -8,15 +8,7 @@ $thumbnail_url = argon_get_post_thumbnail(); - if (get_option('argon_enable_lazyload') != 'false'){ - - echo "thumbnail"; - - }else{ - - echo ""; - - } + echo "thumbnail"; echo ""; diff --git a/template-parts/emotion-keyboard.php b/template-parts/emotion-keyboard.php index 593a5c8..dcbdf63 100644 --- a/template-parts/emotion-keyboard.php +++ b/template-parts/emotion-keyboard.php @@ -21,7 +21,7 @@ echo "
" . esc_html($emotion['text']) . "
"; } if ($emotion['type'] == 'sticker'){ - echo "
"; + echo "
"; } } if (isset($group['description'])){