修复代码折叠bug

This commit is contained in:
zqlit committed 2026-05-25 15:01:18 +08:00
1 parent 9774eeac12
commit 06a5f3da4d
2 files changed
+10 -6

No files matched your search

+7 -3
View File
@@ -94,6 +94,13 @@ document.addEventListener("pjax:success", function () {
}); });
// pjax加载完成 // pjax加载完成
// 代码折叠初始化 — 独立监听器,确保不被其他初始化错误影响
document.addEventListener("pjax:complete", function () {
setTimeout(function() {
if (typeof window.initCodeFold === 'function') window.initCodeFold();
}, 200);
});
document.addEventListener("pjax:complete", function () { document.addEventListener("pjax:complete", function () {
// pjax完成动画 // pjax完成动画
if (typeof NProgress !== 'undefined') { if (typeof NProgress !== 'undefined') {
@@ -106,9 +113,6 @@ document.addEventListener("pjax:complete", function () {
// 初始化代码复制 // 初始化代码复制
if (typeof initCodeCopy === 'function') initCodeCopy(); if (typeof initCodeCopy === 'function') initCodeCopy();
// 初始化代码折叠
if (typeof initCodeFold === 'function') initCodeFold();
// 初始化段落评论 // 初始化段落评论
if (typeof window.initParagraphComments === 'function') { if (typeof window.initParagraphComments === 'function') {
try { try {
+3 -3
View File
@@ -88,9 +88,9 @@ window.initCodeFold = function() {
var pre = block.querySelector('pre'); var pre = block.querySelector('pre');
if (!pre) return; 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; var contentHeight = pre.scrollHeight || block.scrollHeight;
if (contentHeight && contentHeight <= 360) return; if (!contentHeight || contentHeight <= 360) return;
var wrapper = document.createElement('div'); var wrapper = document.createElement('div');
wrapper.className = 'code-fold-container collapsed'; wrapper.className = 'code-fold-container collapsed';
@@ -137,7 +137,7 @@ window.initCodeCopy = function() {
pre.addEventListener('mouseenter', function() { btn.style.opacity = '1'; }); pre.addEventListener('mouseenter', function() { btn.style.opacity = '1'; });
pre.addEventListener('mouseleave', function() { btn.style.opacity = '0'; }); 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) { btn.addEventListener('click', function(e) {
e.stopPropagation(); e.stopPropagation();