fix: 修复目录无法加载和移动端侧边栏无法点击的问题

- header.php: 修改 wp_enqueue_script 在头部加载 jQuery 和插件
- sidebar.php: 使用轮询机制等待 jQuery 和 headIndex 加载完成后再初始化目录
This commit is contained in:
2026-01-11 21:09:58 +08:00
parent 924f39caa7
commit 4fe10c84d7
2 changed files with 11 additions and 27 deletions

View File

@@ -271,7 +271,7 @@
wp_enqueue_style("style", $GLOBALS['assets_path'] . "/style.css", null, $GLOBALS['theme_version']); wp_enqueue_style("style", $GLOBALS['assets_path'] . "/style.css", null, $GLOBALS['theme_version']);
// 集成外部资源备用机制 // 集成外部资源备用机制
wp_enqueue_script("resource_loader", $GLOBALS['assets_path'] . "/assets/vendor/external/resource-loader.js", null, $GLOBALS['theme_version']); wp_enqueue_script("resource_loader", $GLOBALS['assets_path'] . "/assets/vendor/external/resource-loader.js", null, $GLOBALS['theme_version'], false);
if (get_option('argon_disable_googlefont') != 'true') { if (get_option('argon_disable_googlefont') != 'true') {
// 使用备用机制加载Google Fonts // 使用备用机制加载Google Fonts
@@ -284,8 +284,8 @@
</script>'; </script>';
} }
// 加载 argon_js_merged包含 jQuery 和其他库) // 加载 argon_js_merged包含 jQuery 和其他库)- 在头部加载以确保后续脚本可用
wp_enqueue_script("argon_js_merged", $GLOBALS['assets_path'] . "/assets/argon_js_merged.js", null, $GLOBALS['theme_version']); wp_enqueue_script("argon_js_merged", $GLOBALS['assets_path'] . "/assets/argon_js_merged.js", null, $GLOBALS['theme_version'], false);
?> ?>

View File

@@ -431,15 +431,12 @@ $author_desc = get_option('argon_sidebar_author_description');
<div id="leftbar_catalog"></div> <div id="leftbar_catalog"></div>
<script type="text/javascript"> <script type="text/javascript">
// 延迟执行,等待 footer 重新注册插件 // 桌面端目录初始化 - 等待 jQuery 和 headIndex 插件加载完成
(function() { (function initDesktopCatalog() {
var retryCount = 0; // 检查 jQuery 和 headIndex 是否都已加载
var maxRetries = 50; // 最多重试 5 秒
function initCatalog() {
// 检查 jQuery 和 headIndex 插件是否都准备好
if (typeof jQuery !== 'undefined' && typeof jQuery.fn.headIndex === 'function') { if (typeof jQuery !== 'undefined' && typeof jQuery.fn.headIndex === 'function') {
jQuery(document).headIndex({ jQuery(document).ready(function($) {
$(document).headIndex({
articleWrapSelector: '#post_content', articleWrapSelector: '#post_content',
indexBoxSelector: '#leftbar_catalog', indexBoxSelector: '#leftbar_catalog',
subItemBoxClass: "index-subItem-box", subItemBoxClass: "index-subItem-box",
@@ -447,23 +444,10 @@ $author_desc = get_option('argon_sidebar_author_description');
linkClass: "index-link", linkClass: "index-link",
offset: 80, offset: 80,
}); });
} else {
retryCount++;
if (retryCount < maxRetries) {
setTimeout(initCatalog, 100);
} else {
console.error('[Sidebar] 插件初始化超时headIndex 可能未正确加载');
}
}
}
// 等待 DOM ready 后开始尝试初始化
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', function() {
setTimeout(initCatalog, 100); // 额外延迟 100ms
}); });
} else { } else {
setTimeout(initCatalog, 100); // 额外延迟 100ms // 如果还没加载完成,等待后重试
setTimeout(initDesktopCatalog, 50);
} }
})(); })();
</script> </script>