From 2b3b2850f9875f52a5dd2ad2e5dd847e433e187f Mon Sep 17 00:00:00 2001 From: zqlit Date: Mon, 25 May 2026 15:01:18 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E4=BB=A3=E7=A0=81=E6=8A=98?= =?UTF-8?q?=E5=8F=A0bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- themes/Ying/assets/js/modules/mypjax.js | 16 ++++++++++------ themes/Ying/assets/js/modules/utils.js | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/themes/Ying/assets/js/modules/mypjax.js b/themes/Ying/assets/js/modules/mypjax.js index 4791ff5c..7a0e47b0 100644 --- a/themes/Ying/assets/js/modules/mypjax.js +++ b/themes/Ying/assets/js/modules/mypjax.js @@ -94,21 +94,25 @@ document.addEventListener("pjax:success", function () { }); // pjax加载完成 +// 代码折叠初始化 — 独立监听器,确保不被其他初始化错误影响 +document.addEventListener("pjax:complete", function () { + setTimeout(function() { + if (typeof window.initCodeFold === 'function') window.initCodeFold(); + }, 200); +}); + document.addEventListener("pjax:complete", function () { // pjax完成动画 if (typeof NProgress !== 'undefined') { NProgress.done(); } - + // 重载一些js样式调整 pjax_reload(); - + // 初始化代码复制 if (typeof initCodeCopy === 'function') initCodeCopy(); - - // 初始化代码折叠 - if (typeof initCodeFold === 'function') initCodeFold(); - + // 初始化段落评论 if (typeof window.initParagraphComments === 'function') { try { diff --git a/themes/Ying/assets/js/modules/utils.js b/themes/Ying/assets/js/modules/utils.js index 9aaa66fa..e84bf0f2 100644 --- a/themes/Ying/assets/js/modules/utils.js +++ b/themes/Ying/assets/js/modules/utils.js @@ -88,9 +88,9 @@ window.initCodeFold = function() { var pre = block.querySelector('pre'); if (!pre) return; - // Use pre's content height; 0 means layout not ready, wrap conservatively + // Use pre's content height; 0 means layout not ready, skip var contentHeight = pre.scrollHeight || block.scrollHeight; - if (contentHeight && contentHeight <= 360) return; + if (!contentHeight || contentHeight <= 360) return; var wrapper = document.createElement('div'); wrapper.className = 'code-fold-container collapsed'; @@ -137,7 +137,7 @@ window.initCodeCopy = function() { pre.addEventListener('mouseenter', function() { btn.style.opacity = '1'; }); pre.addEventListener('mouseleave', function() { btn.style.opacity = '0'; }); - if (window.isMobile()) { btn.style.opacity = '1'; } + if (typeof window.isMobile === 'function' && window.isMobile()) { btn.style.opacity = '1'; } btn.addEventListener('click', function(e) { e.stopPropagation();