进行了一些小修复

This commit is contained in:
2026-08-26 12:10:06 +08:00
parent 90b3ccb006
commit dc14c29878
15 changed files with 11720 additions and 4354 deletions
+44 -202
View File
@@ -20,18 +20,6 @@ trait ScriptsPart1c {
* Fonts / FA / global JS stack / aksrtData (split from enqueue_public).
*/
private function enqueue_public_fonts_js_and_data($base_uri, $core_dep, $deps, $is_fixed_homepage, $is_home_or_archive, $is_single_post, $is_single_resource, $version): void {
$notyf_css = get_template_directory() . '/assets/css/frontend/notyf.css';
wp_enqueue_style(
'aksrt-notyf',
$base_uri . '/assets/css/frontend/notyf.css',
[$core_dep, '_fontawesome'],
file_exists($notyf_css) ? (string) filemtime($notyf_css) : $version
);
// ===== 7. JS =====
$needs_post_list_media = wp_style_is('aksrt-post-card', 'enqueued');
$runtime_uri = $base_uri . '/assets';
$runtime_loader_path = get_template_directory() . '/assets/js/runtime/loader.js';
$runtime_main_path = get_template_directory() . '/assets/js/runtime/main.min.js';
@@ -95,26 +83,15 @@ trait ScriptsPart1c {
]
);
$lazy_image_attr_path = get_template_directory() . '/assets/js/lazy-image-attr.js';
$public_runtime_path = get_template_directory() . '/assets/js/build/public.js';
wp_enqueue_script(
'aksrt-lazy-image-attr',
$base_uri . '/assets/js/lazy-image-attr.js',
'aksrt-runtime',
$base_uri . '/assets/js/build/public.js',
['loader_js'],
file_exists($lazy_image_attr_path) ? (string) filemtime($lazy_image_attr_path) : $version,
file_exists($public_runtime_path) ? (string) filemtime($public_runtime_path) : $version,
true
);
// AKSRT-only modules register after the legacy loader; navigation is owned by main.min.js.
wp_enqueue_script(
'aksrt-rehydrate',
$base_uri . '/assets/js/rehydrate.js',
['loader_js', 'aksrt-lazy-image-attr'],
file_exists(get_template_directory() . '/assets/js/rehydrate.js')
? (string) filemtime(get_template_directory() . '/assets/js/rehydrate.js')
: $version,
true
);
// AJAX 调试(WP_DEBUG 或 ?aksrt_ajax_debug=1):记录所有失败的
// jQuery ajax / fetch 请求,用于定位 vendor main.min.js 的 400 "0" 来源。
if (function_exists('aksrt_ajax_debug_enabled') && aksrt_ajax_debug_enabled()) {
@@ -122,114 +99,19 @@ trait ScriptsPart1c {
wp_enqueue_script(
'aksrt-ajax-debug',
$base_uri . '/assets/js/core/ajax-debug.js',
['loader_js'],
['aksrt-runtime'],
file_exists($ajax_debug_path) ? (string) filemtime($ajax_debug_path) : $version,
true
);
}
if ($needs_post_list_media) {
$grade_js = get_template_directory() . '/assets/js/grade.min.js';
wp_enqueue_script(
'aksrt-grade',
$base_uri . '/assets/js/grade.min.js',
[],
file_exists($grade_js) ? (string) filemtime($grade_js) : $version,
true
);
}
$notyf_js = get_template_directory() . '/assets/js/notyf.js';
wp_enqueue_script(
'aksrt-notyf',
$base_uri . '/assets/js/notyf.js',
['jquery'],
file_exists($notyf_js) ? (string) filemtime($notyf_js) : $version,
true
);
// Runtime infrastructure: tbquire / confirm / scrollTopTo / [data-*] declarative
$runtime_js = get_template_directory() . '/assets/js/aksrt-runtime.js';
if (file_exists($runtime_js)) {
wp_enqueue_script(
'aksrt-runtime',
$base_uri . '/assets/js/aksrt-runtime.js',
['aksrt-rehydrate', 'aksrt-notyf'],
(string) filemtime($runtime_js),
true
);
}
// Follow toggle: delegated [data-aksrt-follow] handler; the buttons render on
// user home / user center / single author bar and user cards anywhere.
// Depends on aksrt-runtime because aksrtData (REST root + nonce) is localized
// onto that handle and follow.js reads it at parse time.
$follow_js = get_template_directory() . '/assets/js/follow.js';
if (file_exists($follow_js)) {
wp_enqueue_script(
'aksrt-follow',
$base_uri . '/assets/js/follow.js',
['aksrt-notyf', 'aksrt-runtime'],
(string) filemtime($follow_js),
true
);
}
// Core modules (split from main.js) — register with AksrtFrontend
$core_modules = [
'aksrt-core-article' => 'article.js',
'aksrt-core-comments' => 'comments.js',
'aksrt-core-comment-fixed' => 'comment-fixed-input.js',
'aksrt-core-comment-move' => 'comment-move-form.js',
// Shared legacy-parity list/modal engines (before pagination consumers).
'aksrt-core-ajax-list' => 'ajax-list.js',
'aksrt-core-modal-telemetry' => 'modal-telemetry.js',
'aksrt-core-request' => 'request.js',
'aksrt-core-modal-cache' => 'modal-cache.js',
'aksrt-core-modal-state' => 'modal-state.js',
'aksrt-core-modal-runtime' => 'modal-runtime.js',
'aksrt-core-modal-triggers' => 'modal-triggers.js',
'aksrt-core-pagination' => 'pagination.js',
'aksrt-core-archive' => 'archive.js',
'aksrt-core-footer-tabbar' => 'footer-tabbar.js',
'aksrt-core-misc' => 'misc.js',
];
$core_handles = [];
foreach ($core_modules as $handle => $file) {
$path = get_template_directory() . '/assets/js/core/' . $file;
if (file_exists($path)) {
// Depend on aksrt-runtime so window.aksrtData (localized below) is available.
$deps = ['aksrt-rehydrate', 'aksrt-runtime'];
if ($handle === 'aksrt-core-misc' && $needs_post_list_media) {
$deps[] = 'aksrt-grade';
} elseif ($handle === 'aksrt-core-modal-runtime') {
$deps = array_merge($deps, [
'aksrt-core-modal-telemetry',
'aksrt-core-request',
'aksrt-core-modal-cache',
'aksrt-core-modal-state',
]);
} elseif ($handle === 'aksrt-core-modal-triggers') {
$deps[] = 'aksrt-core-modal-runtime';
}
wp_enqueue_script(
$handle,
$base_uri . '/assets/js/core/' . $file,
$deps,
(string) filemtime($path),
true
);
$core_handles[] = $handle;
}
}
// Code block enhancements (copy button + language label)
$precode_js = get_template_directory() . '/assets/js/precode.js';
if (file_exists($precode_js)) {
if (is_singular() && file_exists($precode_js)) {
wp_enqueue_script(
'aksrt-precode',
$base_uri . '/assets/js/precode.js',
[],
['aksrt-runtime'],
(string) filemtime($precode_js),
true
);
@@ -237,11 +119,15 @@ trait ScriptsPart1c {
// Input field enhancements (auto-resize, counter, validation)
$input_expand_js = get_template_directory() . '/assets/js/input-expand.js';
if (file_exists($input_expand_js)) {
$needs_input_enhancements = is_singular()
|| (bool) get_query_var('aksrt_sign')
|| (bool) get_query_var('aksrt_user_center')
|| (bool) get_query_var('aksrt_author_identifier');
if ($needs_input_enhancements && file_exists($input_expand_js)) {
wp_enqueue_script(
'aksrt-input-expand',
$base_uri . '/assets/js/input-expand.js',
[],
['aksrt-runtime'],
(string) filemtime($input_expand_js),
true
);
@@ -261,11 +147,11 @@ trait ScriptsPart1c {
// Section navs: article TOC / scrollspy
$section_navs_js = get_template_directory() . '/assets/js/section-navs.js';
if (file_exists($section_navs_js)) {
if (is_singular() && file_exists($section_navs_js)) {
wp_enqueue_script(
'aksrt-section-navs',
$base_uri . '/assets/js/section-navs.js',
['aksrt-rehydrate', 'aksrt-runtime'],
['aksrt-runtime'],
(string) filemtime($section_navs_js),
true
);
@@ -273,92 +159,35 @@ trait ScriptsPart1c {
// Video player (MP4/HLS/FLV)
$video_player_js = get_template_directory() . '/assets/js/video-player.js';
if (file_exists($video_player_js)) {
if (is_singular() && file_exists($video_player_js)) {
wp_enqueue_script(
'aksrt-video-player',
$base_uri . '/assets/js/video-player.js',
[],
['aksrt-runtime'],
(string) filemtime($video_player_js),
true
);
}
// Image color extraction
$color_extract_js = get_template_directory() . '/assets/js/color-extract.js';
if (file_exists($color_extract_js)) {
wp_enqueue_script(
'aksrt-color-extract',
$base_uri . '/assets/js/color-extract.js',
[],
(string) filemtime($color_extract_js),
true
);
}
// ===== 全局 UI 增强(骨架屏、悬停动效、灯箱、滚动感知)=====
$enhancements_css = get_template_directory() . '/assets/css/frontend/enhancements.css';
if (file_exists($enhancements_css)) {
wp_enqueue_style(
'aksrt-enhancements',
$base_uri . '/assets/css/frontend/enhancements.css',
[$core_dep],
(string) filemtime($enhancements_css)
);
}
$enhancements_js = get_template_directory() . '/assets/js/enhancements.js';
if (file_exists($enhancements_js)) {
wp_enqueue_script(
'aksrt-enhancements',
$base_uri . '/assets/js/enhancements.js',
['loader_js'],
(string) filemtime($enhancements_js),
true
);
}
$enhancements2_js = get_template_directory() . '/assets/js/enhancements2.js';
if (file_exists($enhancements2_js)) {
wp_enqueue_script(
'aksrt-enhancements2',
$base_uri . '/assets/js/enhancements2.js',
['loader_js'],
(string) filemtime($enhancements2_js),
true
);
}
// Reward (打赏)
$reward_js = get_template_directory() . '/assets/js/reward.js';
if (file_exists($reward_js)) {
if (($is_single_post || $is_single_resource) && file_exists($reward_js)) {
wp_enqueue_script(
'aksrt-reward',
$base_uri . '/assets/js/reward.js',
['loader_js', 'aksrt-core-request'],
['aksrt-runtime'],
(string) filemtime($reward_js),
true
);
}
// Effects (count-up, countdown, marquee, tilt, FPS detection)
$effects_js = get_template_directory() . '/assets/js/effects.js';
if (file_exists($effects_js)) {
wp_enqueue_script(
'aksrt-effects',
$base_uri . '/assets/js/effects.js',
['loader_js'],
(string) filemtime($effects_js),
true
);
}
// Yiyan (一言轮播)
$yiyan_js = get_template_directory() . '/assets/js/yiyan.js';
if (file_exists($yiyan_js)) {
if (($is_single_post || $is_single_resource) && file_exists($yiyan_js)) {
wp_enqueue_script(
'aksrt-yiyan',
$base_uri . '/assets/js/yiyan.js',
[],
['aksrt-runtime'],
(string) filemtime($yiyan_js),
true
);
@@ -366,8 +195,16 @@ trait ScriptsPart1c {
// Frontend translate (默认关)
// Content protection (copy notice / right-click / F12)
$content_protect = class_exists('\AKSRT\Settings\Settings')
? [
'enabled' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_enabled', false),
'copy' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_copy_notice', false),
'right_click' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_right_click', false),
'devtools' => (bool) \AKSRT\Settings\Settings::get_value('content_protect_f12', false),
]
: [];
$content_protect_js = get_template_directory() . '/assets/js/content-protect.js';
if (file_exists($content_protect_js)) {
if (in_array(true, $content_protect, true) && file_exists($content_protect_js)) {
wp_enqueue_script(
'aksrt-content-protect',
$base_uri . '/assets/js/content-protect.js',
@@ -378,8 +215,13 @@ trait ScriptsPart1c {
}
// Site notice popup (global, controlled by Settings)
$site_notice_config = class_exists('\AKSRT\Settings\Settings')
? \AKSRT\Settings\Settings::get_system_notice_config()
: [];
$site_notice_enabled = !empty($site_notice_config['enabled'])
&& trim((string) ($site_notice_config['content'] ?? '')) !== '';
$site_notice_css = get_template_directory() . '/assets/css/frontend/site-notice.css';
if (file_exists($site_notice_css)) {
if ($site_notice_enabled && file_exists($site_notice_css)) {
wp_enqueue_style(
'aksrt-site-notice',
$base_uri . '/assets/css/frontend/site-notice.css',
@@ -388,11 +230,11 @@ trait ScriptsPart1c {
);
}
$site_notice_js = get_template_directory() . '/assets/js/site-notice.js';
if (file_exists($site_notice_js)) {
if ($site_notice_enabled && file_exists($site_notice_js)) {
wp_enqueue_script(
'aksrt-site-notice',
$base_uri . '/assets/js/site-notice.js',
[],
['aksrt-runtime'],
(string) filemtime($site_notice_js),
true
);
@@ -400,11 +242,11 @@ trait ScriptsPart1c {
// One state machine owns modal and /sign/ authentication.
$auth_js = get_template_directory() . '/assets/js/auth.js';
if (file_exists($auth_js)) {
if ((!is_user_logged_in() || (bool) get_query_var('aksrt_sign')) && file_exists($auth_js)) {
wp_enqueue_script(
'aksrt-auth',
$base_uri . '/assets/js/auth.js',
['aksrt-notyf', 'aksrt-runtime'],
['aksrt-runtime'],
(string) filemtime($auth_js),
true
);
@@ -415,7 +257,7 @@ trait ScriptsPart1c {
wp_enqueue_script(
'aksrt-homepage-fixed',
$base_uri . '/assets/js/homepage-fixed.js',
['loader_js'],
['aksrt-runtime'],
file_exists($homepage_js_path) ? (string) filemtime($homepage_js_path) : $version,
true
);
@@ -429,7 +271,7 @@ trait ScriptsPart1c {
wp_enqueue_script(
'aksrt-comment-tools',
$base_uri . '/assets/js/comment-tools.js',
['loader_js', 'aksrt-core-comment-fixed', 'aksrt-core-comment-move'],
['aksrt-runtime'],
file_exists($comment_tools_path) ? (string) filemtime($comment_tools_path) : $version,
true
);
@@ -452,7 +294,7 @@ trait ScriptsPart1c {
wp_enqueue_script(
'aksrt-comment-ajax',
$base_uri . '/assets/js/comment-ajax.js',
['loader_js', 'aksrt-core-comments'],
['aksrt-runtime'],
(string) filemtime($comment_ajax_path),
true
);
@@ -465,7 +307,7 @@ trait ScriptsPart1c {
wp_enqueue_script(
'aksrt-page-template',
$base_uri . '/assets/js/page-template.js',
['loader_js'],
['aksrt-runtime'],
(string) filemtime($page_template_path),
true
);