diff --git a/argontheme.js b/argontheme.js
index de64085..a93b5cd 100644
--- a/argontheme.js
+++ b/argontheme.js
@@ -5,115 +5,115 @@
// ========== 兼容性修复 ==========
// 确保 Prism 和 autoloader 存在
if (typeof window.Prism === 'undefined') {
- window.Prism = {
- highlightAll: function() {},
- highlightElement: function() {},
- plugins: {}
- };
+ window.Prism = {
+ highlightAll: function () { },
+ highlightElement: function () { },
+ plugins: {}
+ };
}
if (typeof window.Prism.plugins === 'undefined') {
- window.Prism.plugins = {};
+ window.Prism.plugins = {};
}
if (typeof window.Prism.plugins.autoloader === 'undefined') {
- window.Prism.plugins.autoloader = {
- languages_path: '',
- use_minified: true
- };
+ window.Prism.plugins.autoloader = {
+ languages_path: '',
+ use_minified: true
+ };
}
// 确保 Zoomify 存在
if (typeof window.Zoomify === 'undefined') {
- window.Zoomify = function() {};
- window.Zoomify.DEFAULTS = {};
+ window.Zoomify = function () { };
+ window.Zoomify.DEFAULTS = {};
}
// 确保 jQuery 插件存在
if (typeof jQuery !== 'undefined') {
- (function($) {
- // 确保 easing 函数存在(防止其他插件覆盖 jQuery 后丢失)
- if (typeof $.easing === 'undefined') {
- $.easing = {};
- }
- if (typeof $.easing.easeOutCirc === 'undefined') {
- $.easing.easeOutCirc = function(x) {
- return Math.sqrt(1 - Math.pow(x - 1, 2));
- };
- }
- if (typeof $.easing.easeOutExpo === 'undefined') {
- $.easing.easeOutExpo = function(x) {
- return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
- };
- }
+ (function ($) {
+ // 确保 easing 函数存在(防止其他插件覆盖 jQuery 后丢失)
+ if (typeof $.easing === 'undefined') {
+ $.easing = {};
+ }
+ if (typeof $.easing.easeOutCirc === 'undefined') {
+ $.easing.easeOutCirc = function (x) {
+ return Math.sqrt(1 - Math.pow(x - 1, 2));
+ };
+ }
+ if (typeof $.easing.easeOutExpo === 'undefined') {
+ $.easing.easeOutExpo = function (x) {
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
+ };
+ }
- if (!$.fn._argonInit) {
- $.fn._argonInit = $.fn.init;
- $.fn.init = function(selector, context, root) {
- // 修复空选择器、特殊字符和中文标点导致的语法错误
- if (typeof selector === 'string') {
- let trimmed = selector.trim();
- // 检查是否为空或只有 # 符号
- if (trimmed === '' || trimmed === '#') {
- return new $.fn._argonInit();
- }
- // 检查是否包含中文标点(可能导致语法错误)
- if (/[;,。:!?]/.test(trimmed)) {
- console.warn('[Argon] Invalid selector with Chinese punctuation:', selector);
- return new $.fn._argonInit();
- }
- // 检查 ID 选择器是否有效(#后面必须有内容)
- if (/^#\s*$/.test(trimmed)) {
- return new $.fn._argonInit();
- }
- }
- return $.fn._argonInit.call(this, selector, context, root);
- };
- $.fn.init.prototype = $.fn;
- }
-
- // 确保 zoomify 插件存在
- if (typeof $.fn.zoomify === 'undefined') {
- $.fn.zoomify = function() { return this; };
- }
-
- // 确保 fancybox 存在
- if (typeof $.fancybox === 'undefined') {
- $.fancybox = {
- defaults: {
- transitionEffect: 'slide',
- buttons: [],
- lang: 'zh_CN',
- i18n: {}
- },
- open: function() {},
- close: function() {}
- };
- }
- if (typeof $.fancybox.defaults === 'undefined') {
- $.fancybox.defaults = {
- transitionEffect: 'slide',
- buttons: [],
- lang: 'zh_CN',
- i18n: {}
- };
- }
-
- // 确保 pjax 存在
- if (typeof $.pjax === 'undefined') {
- $.pjax = function() {};
- $.pjax.defaults = {
- timeout: 10000,
- container: [],
- fragment: []
- };
- }
- if (typeof $.pjax.defaults === 'undefined') {
- $.pjax.defaults = {
- timeout: 10000,
- container: [],
- fragment: []
- };
- }
- })(jQuery);
+ if (!$.fn._argonInit) {
+ $.fn._argonInit = $.fn.init;
+ $.fn.init = function (selector, context, root) {
+ // 修复空选择器、特殊字符和中文标点导致的语法错误
+ if (typeof selector === 'string') {
+ let trimmed = selector.trim();
+ // 检查是否为空或只有 # 符号
+ if (trimmed === '' || trimmed === '#') {
+ return new $.fn._argonInit();
+ }
+ // 检查是否包含中文标点(可能导致语法错误)
+ if (/[;,。:!?]/.test(trimmed)) {
+ console.warn('[Argon] Invalid selector with Chinese punctuation:', selector);
+ return new $.fn._argonInit();
+ }
+ // 检查 ID 选择器是否有效(#后面必须有内容)
+ if (/^#\s*$/.test(trimmed)) {
+ return new $.fn._argonInit();
+ }
+ }
+ return $.fn._argonInit.call(this, selector, context, root);
+ };
+ $.fn.init.prototype = $.fn;
+ }
+
+ // 确保 zoomify 插件存在
+ if (typeof $.fn.zoomify === 'undefined') {
+ $.fn.zoomify = function () { return this; };
+ }
+
+ // 确保 fancybox 存在
+ if (typeof $.fancybox === 'undefined') {
+ $.fancybox = {
+ defaults: {
+ transitionEffect: 'slide',
+ buttons: [],
+ lang: 'zh_CN',
+ i18n: {}
+ },
+ open: function () { },
+ close: function () { }
+ };
+ }
+ if (typeof $.fancybox.defaults === 'undefined') {
+ $.fancybox.defaults = {
+ transitionEffect: 'slide',
+ buttons: [],
+ lang: 'zh_CN',
+ i18n: {}
+ };
+ }
+
+ // 确保 pjax 存在
+ if (typeof $.pjax === 'undefined') {
+ $.pjax = function () { };
+ $.pjax.defaults = {
+ timeout: 10000,
+ container: [],
+ fragment: []
+ };
+ }
+ if (typeof $.pjax.defaults === 'undefined') {
+ $.pjax.defaults = {
+ timeout: 10000,
+ container: [],
+ fragment: []
+ };
+ }
+ })(jQuery);
}
// ==========================================================================
@@ -132,10 +132,10 @@ if (typeof jQuery !== 'undefined') {
// ==========================================================================
// ========== 原有代码 ==========
-if (typeof(argonConfig) == "undefined"){
+if (typeof (argonConfig) == "undefined") {
var argonConfig = {};
}
-if (typeof(argonConfig.wp_path) == "undefined"){
+if (typeof (argonConfig.wp_path) == "undefined") {
argonConfig.wp_path = "/";
}
@@ -376,19 +376,19 @@ translation['zh_TW'] = {
"全屏": "全屏",
"退出全屏": "退出全屏",
};
-function __(text){
+function __(text) {
let lang = argonConfig.language;
- if (typeof(translation[lang]) == "undefined"){
+ if (typeof (translation[lang]) == "undefined") {
return text;
}
- if (typeof(translation[lang][text]) == "undefined"){
+ if (typeof (translation[lang][text]) == "undefined") {
return text;
}
return translation[lang][text];
}
/*根据滚动高度改变顶栏透明度 */
-!function(){
+!function () {
let toolbar = document.getElementById("navbar-main");
let $bannerContainer = $("#banner_container");
let $content = $("#content");
@@ -400,26 +400,26 @@ function __(text){
startTransitionHeight = $bannerContainer.offset().top - 75;
endTransitionHeight = $content.offset().top - 75;
- $(window).resize(function(){
+ $(window).resize(function () {
startTransitionHeight = $bannerContainer.offset().top - 75;
endTransitionHeight = $content.offset().top - 75;
});
- function changeToolbarTransparency(){
+ function changeToolbarTransparency() {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if (scrollTop < startTransitionHeight){
+ if (scrollTop < startTransitionHeight) {
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), 0)', 'important');
toolbar.style.setProperty('box-shadow', 'none');
- if (argonConfig.toolbar_blur){
+ if (argonConfig.toolbar_blur) {
toolbar.style.setProperty('backdrop-filter', 'blur(0px)');
}
toolbar.classList.add("navbar-ontop");
return;
}
- if (scrollTop > endTransitionHeight){
+ if (scrollTop > endTransitionHeight) {
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), ' + maxOpacity + ')', 'important');
toolbar.style.setProperty('box-shadow', '');
- if (argonConfig.toolbar_blur){
+ if (argonConfig.toolbar_blur) {
toolbar.style.setProperty('backdrop-filter', 'blur(16px)');
}
toolbar.classList.remove("navbar-ontop");
@@ -428,30 +428,30 @@ function __(text){
let transparency = (scrollTop - startTransitionHeight) / (endTransitionHeight - startTransitionHeight) * maxOpacity;
toolbar.style.setProperty('background-color', 'rgba(var(--toolbar-color), ' + transparency, 'important');
toolbar.style.setProperty('box-shadow', '');
- if (argonConfig.toolbar_blur){
- if ((scrollTop - startTransitionHeight) / (endTransitionHeight - startTransitionHeight) > 0.3){
+ if (argonConfig.toolbar_blur) {
+ if ((scrollTop - startTransitionHeight) / (endTransitionHeight - startTransitionHeight) > 0.3) {
toolbar.style.setProperty('backdrop-filter', 'blur(16px)');
- }else{
+ } else {
toolbar.style.setProperty('backdrop-filter', 'blur(0px)');
}
}
toolbar.classList.remove("navbar-ontop");
}
- function changeToolbarOnTopClass(){
+ function changeToolbarOnTopClass() {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if (scrollTop < 30){
+ if (scrollTop < 30) {
toolbar.classList.add("navbar-no-blur");
- }else{
+ } else {
toolbar.classList.remove("navbar-no-blur");
}
}
if ($("html").hasClass("no-banner")) {
changeToolbarOnTopClass();
// 使用节流优化滚动事件性能
- const throttledChangeToolbarOnTopClass = argonEventManager ?
- argonEventManager.throttle(changeToolbarOnTopClass, 16) :
+ const throttledChangeToolbarOnTopClass = argonEventManager ?
+ argonEventManager.throttle(changeToolbarOnTopClass, 16) :
changeToolbarOnTopClass;
- document.addEventListener("scroll", throttledChangeToolbarOnTopClass, {passive: true});
+ document.addEventListener("scroll", throttledChangeToolbarOnTopClass, { passive: true });
return;
}
if (argonConfig.headroom == "absolute") {
@@ -461,37 +461,37 @@ function __(text){
if ($("html").hasClass("toolbar-blur")) {
argonConfig.toolbar_blur = true;
maxOpacity = 0.65;
- }else{
+ } else {
argonConfig.toolbar_blur = false;
}
changeToolbarTransparency();
// 使用节流优化滚动事件性能
- const throttledChangeToolbarTransparency = argonEventManager ?
- argonEventManager.throttle(changeToolbarTransparency, 16) :
+ const throttledChangeToolbarTransparency = argonEventManager ?
+ argonEventManager.throttle(changeToolbarTransparency, 16) :
changeToolbarTransparency;
- document.addEventListener("scroll", throttledChangeToolbarTransparency, {passive: true});
+ document.addEventListener("scroll", throttledChangeToolbarTransparency, { passive: true });
}();
/*搜索*/
-function searchPosts(word){
- if ($(".search-result").length > 0){
+function searchPosts(word) {
+ if ($(".search-result").length > 0) {
let url = new URL(window.location.href);
url.searchParams.set("s", word);
$.pjax({
url: url.href
});
- }else{
+ } else {
$.pjax({
url: argonConfig.wp_path + "?s=" + encodeURI(word)
});
}
}
/*顶栏搜索*/
-$(document).on("click" , "#navbar_search_input_container" , function(){
+$(document).on("click", "#navbar_search_input_container", function () {
$(this).addClass("open");
$("#navbar_search_input").focus();
});
-$(document).on("blur" , "#navbar_search_input_container" , function(){
+$(document).on("blur", "#navbar_search_input_container", function () {
// 如果有文字则保持has-text类
if ($("#navbar_search_input").val().trim() !== "") {
$(this).addClass("has-text");
@@ -501,7 +501,7 @@ $(document).on("blur" , "#navbar_search_input_container" , function(){
$(this).removeClass("open");
});
// 监听输入变化来切换has-text类
-$(document).on("input" , "#navbar_search_input" , function(){
+$(document).on("input", "#navbar_search_input", function () {
var container = $("#navbar_search_input_container");
if ($(this).val().trim() !== "") {
container.addClass("has-text");
@@ -509,12 +509,12 @@ $(document).on("input" , "#navbar_search_input" , function(){
container.removeClass("has-text");
}
});
-$(document).on("keydown" , "#navbar_search_input_container #navbar_search_input" , function(e){
- if (e.keyCode != 13){
+$(document).on("keydown", "#navbar_search_input_container #navbar_search_input", function (e) {
+ if (e.keyCode != 13) {
return;
}
let word = $(this).val();
- if (word == ""){
+ if (word == "") {
$("#navbar_search_input_container").blur();
return;
}
@@ -522,36 +522,36 @@ $(document).on("keydown" , "#navbar_search_input_container #navbar_search_input"
searchPosts(word);
});
/*顶栏搜索 (Mobile)*/
-$(document).on("keydown" , "#navbar_search_input_mobile" , function(e){
- if (e.keyCode != 13){
+$(document).on("keydown", "#navbar_search_input_mobile", function (e) {
+ if (e.keyCode != 13) {
return;
}
let word = $(this).val();
$("#navbar_global .collapse-close button").click();
- if (word == ""){
+ if (word == "") {
return;
}
let scrolltop = $(document).scrollTop();
searchPosts(word);
});
/*侧栏搜索*/
-$(document).on("click" , "#leftbar_search_container" , function(){
+$(document).on("click", "#leftbar_search_container", function () {
$(".leftbar-search-button").addClass("open");
$("#leftbar_search_input").removeAttr("readonly").focus();
$("#leftbar_search_input").focus();
$("#leftbar_search_input").select();
return false;
});
-$(document).on("blur" , "#leftbar_search_container" , function(){
+$(document).on("blur", "#leftbar_search_container", function () {
$(".leftbar-search-button").removeClass("open");
$("#leftbar_search_input").attr("readonly", "readonly");
});
-$(document).on("keydown" , "#leftbar_search_input" , function(e){
- if (e.keyCode != 13){
+$(document).on("keydown", "#leftbar_search_input", function (e) {
+ if (e.keyCode != 13) {
return;
}
let word = $(this).val();
- if (word == ""){
+ if (word == "") {
$("#leftbar_search_container").blur();
return;
}
@@ -559,18 +559,18 @@ $(document).on("keydown" , "#leftbar_search_input" , function(e){
searchPosts(word);
});
/*搜索过滤器*/
-$(document).on("change" , ".search-filter" , function(e){
- if (pjaxLoading){
+$(document).on("change", ".search-filter", function (e) {
+ if (pjaxLoading) {
$(this).prop("checked", !$(this).prop("checked"));
e.preventDefault();
return;
}
pjaxLoading = true;
let postTypes = [];
- $(".search-filter:checked").each(function(){
+ $(".search-filter:checked").each(function () {
postTypes.push($(this).attr("name"));
});
- if (postTypes.length == 0){
+ if (postTypes.length == 0) {
postTypes = ["none"];
}
let url = new URL(document.location.href);
@@ -582,24 +582,24 @@ $(document).on("change" , ".search-filter" , function(e){
});
/*左侧栏随页面滚动浮动*/
-!function(){
- if ($("#leftbar").length == 0){
+!function () {
+ if ($("#leftbar").length == 0) {
let contentOffsetTop = $('#content').offset().top;
- function changeLeftbarStickyStatusWithoutSidebar(){
+ function changeLeftbarStickyStatusWithoutSidebar() {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if( contentOffsetTop - 10 - scrollTop <= 20 ){
+ if (contentOffsetTop - 10 - scrollTop <= 20) {
document.body.classList.add('leftbar-can-headroom');
- }else{
+ } else {
document.body.classList.remove('leftbar-can-headroom');
}
}
changeLeftbarStickyStatusWithoutSidebar();
// 使用节流优化滚动事件性能
- const throttledChangeLeftbarStickyStatusWithoutSidebar = argonEventManager ?
- argonEventManager.throttle(changeLeftbarStickyStatusWithoutSidebar, 16) :
+ const throttledChangeLeftbarStickyStatusWithoutSidebar = argonEventManager ?
+ argonEventManager.throttle(changeLeftbarStickyStatusWithoutSidebar, 16) :
changeLeftbarStickyStatusWithoutSidebar;
- document.addEventListener("scroll", throttledChangeLeftbarStickyStatusWithoutSidebar, {passive: true});
- $(window).resize(function(){
+ document.addEventListener("scroll", throttledChangeLeftbarStickyStatusWithoutSidebar, { passive: true });
+ $(window).resize(function () {
contentOffsetTop = $('#content').offset().top;
changeLeftbarStickyStatusWithoutSidebar();
});
@@ -614,9 +614,9 @@ $(document).on("change" , ".search-filter" , function(e){
let part1OffsetTop = $('#leftbar_part1').offset().top;
let part1OuterHeight = $('#leftbar_part1').outerHeight();
- function changeLeftbarStickyStatus(){
+ function changeLeftbarStickyStatus() {
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
- if( part1OffsetTop + part1OuterHeight + 10 - scrollTop <= (argonConfig.headroom != "absolute" ? 90 : 18) ){
+ if (part1OffsetTop + part1OuterHeight + 10 - scrollTop <= (argonConfig.headroom != "absolute" ? 90 : 18)) {
//滚动条在页面中间浮动状态
leftbarPart2.classList.add('sticky');
if (leftbarPart3) {
@@ -625,16 +625,16 @@ $(document).on("change" , ".search-filter" , function(e){
let viewportHeight = window.innerHeight;
let topOffset = argonConfig.headroom !== 'absolute' ? 90 : 20;
let availableHeight = viewportHeight - topOffset - 20; // 20px 底部边距
-
+
// 获取 part3 的自然高度(不受限制时的高度)
leftbarPart3.style.maxHeight = 'none';
let part3NaturalHeight = leftbarPart3.scrollHeight;
leftbarPart3.style.maxHeight = '';
-
+
// 最小高度限制
let minPart2Height = 150;
let minPart3Height = 100;
-
+
// 计算分配
let part2Height, part3MaxHeight;
if (part3NaturalHeight + minPart2Height <= availableHeight) {
@@ -646,49 +646,59 @@ $(document).on("change" , ".search-filter" , function(e){
part2Height = Math.max(minPart2Height, availableHeight * 0.6);
part3MaxHeight = Math.max(minPart3Height, availableHeight - part2Height - 10);
}
-
+
document.documentElement.style.setProperty('--leftbar-part2-height', leftbarPart2.offsetHeight + 10 + 'px');
document.documentElement.style.setProperty('--leftbar-part3-height', part3MaxHeight + 'px');
document.documentElement.style.setProperty('--leftbar-part3-max-height', part3MaxHeight + 'px');
}
- }else{
+ } else {
//滚动条在顶部 不浮动状态
leftbarPart2.classList.remove('sticky');
if (leftbarPart3) leftbarPart3.classList.remove('sticky');
}
- if( part1OffsetTop + part1OuterHeight + 10 - scrollTop <= 20 ){//侧栏下部分是否可以随 Headroom 一起向上移动
+ if (part1OffsetTop + part1OuterHeight + 10 - scrollTop <= 20) {//侧栏下部分是否可以随 Headroom 一起向上移动
document.body.classList.add('leftbar-can-headroom');
- }else{
+ } else {
document.body.classList.remove('leftbar-can-headroom');
}
}
changeLeftbarStickyStatus();
// 使用节流优化滚动事件性能
- const throttledChangeLeftbarStickyStatus = argonEventManager ?
- argonEventManager.throttle(changeLeftbarStickyStatus, 16) :
+ const throttledChangeLeftbarStickyStatus = argonEventManager ?
+ argonEventManager.throttle(changeLeftbarStickyStatus, 16) :
changeLeftbarStickyStatus;
- document.addEventListener("scroll", throttledChangeLeftbarStickyStatus, {passive: true});
- $(window).resize(function(){
+ document.addEventListener("scroll", throttledChangeLeftbarStickyStatus, { passive: true });
+ $(window).resize(function () {
part1OffsetTop = $leftbarPart1.offset().top;
part1OuterHeight = $leftbarPart1.outerHeight();
changeLeftbarStickyStatus();
});
- new MutationObserver(function(){
+ new MutationObserver(function () {
part1OffsetTop = $leftbarPart1.offset().top;
part1OuterHeight = $leftbarPart1.outerHeight();
changeLeftbarStickyStatus();
- }).observe(leftbarPart1, {attributes: true, childList: true, subtree: true});
+ }).observe(leftbarPart1, { attributes: true, childList: true, subtree: true });
+ // 监听 part2 和 part3 的尺寸变化,确保高度变动时重新计算布局
+ // 注意:这里必须使用 ResizeObserver 而不是 MutationObserver
+ // 因为 changeLeftbarStickyStatus 会修改 DOM 属性(classList, style),使用 MuationObserver 会导致无限循环死机
+ if (typeof ResizeObserver !== 'undefined') {
+ const ro = new ResizeObserver(function () {
+ changeLeftbarStickyStatus();
+ });
+ if (leftbarPart2) ro.observe(leftbarPart2);
+ if (leftbarPart3) ro.observe(leftbarPart3);
+ }
}();
/*Headroom*/
-if (argonConfig.headroom == "true"){
- var headroom = new Headroom(document.querySelector("body"),{
- "tolerance" : {
- up : 0,
- down : 0
+if (argonConfig.headroom == "true") {
+ var headroom = new Headroom(document.querySelector("body"), {
+ "tolerance": {
+ up: 0,
+ down: 0
},
"offset": 0,
- "classes": {
+ "classes": {
"initial": "with-headroom",
"pinned": "headroom---pinned",
"unpinned": "headroom---unpinned",
@@ -706,8 +716,8 @@ function waterflowInit() {
if (argonConfig.waterflow_columns == "1") {
return;
}
- $("#main.article-list img").each(function(index, ele){
- ele.onload = function(){
+ $("#main.article-list img").each(function (index, ele) {
+ ele.onload = function () {
waterflowInit();
}
});
@@ -718,17 +728,17 @@ function waterflowInit() {
} else {
columns = 2;
}
- }else{
+ } else {
columns = parseInt(argonConfig.waterflow_columns);
}
if ($("#main").outerWidth() < 650 && columns == 2) {
columns = 1;
- }else if ($("#main").outerWidth() < 800 && columns == 3) {
+ } else if ($("#main").outerWidth() < 800 && columns == 3) {
columns = 1;
}
let heights = [0, 0, 0];
- function getMinHeightPosition(){
+ function getMinHeightPosition() {
let res = 0, minn = 2147483647;
for (var i = 0; i < columns; i++) {
if (heights[i] < minn) {
@@ -738,7 +748,7 @@ function waterflowInit() {
}
return res;
}
- function getMaxHeight(){
+ function getMaxHeight() {
let res = 0;
for (let i in heights) {
res = Math.max(res, heights[i]);
@@ -748,7 +758,7 @@ function waterflowInit() {
$("#primary").css("transition", "none")
.addClass("waterflow");
let $container = $("#main.article-list");
- if (!$container.length){
+ if (!$container.length) {
return;
}
let $items = $container.find("article.post:not(.no-results), .shuoshuo-preview-container");
@@ -757,9 +767,9 @@ function waterflowInit() {
$container.removeClass("waterflow");
$items.css("transition", "").css("position", "").css("width", "").css("top", "").css("left", "").css("margin", "");
$(".waterflow-placeholder").remove();
- }else{
+ } else {
$container.addClass("waterflow");
- $items.each(function(index, item) {
+ $items.each(function (index, item) {
let $item = $(item);
$item.css("transition", "none")
.css("position", "absolute")
@@ -773,16 +783,16 @@ function waterflowInit() {
}
if ($(".waterflow-placeholder").length) {
$(".waterflow-placeholder").css("height", getMaxHeight() + "px");
- }else{
- $container.prepend("
");
+ } else {
+ $container.prepend("");
}
}
waterflowInit();
if (argonConfig.waterflow_columns != "1") {
- $(window).resize(function(){
+ $(window).resize(function () {
waterflowInit();
});
- new MutationObserver(function(mutations, observer){
+ new MutationObserver(function (mutations, observer) {
waterflowInit();
}).observe(document.querySelector("#primary"), {
'childList': true
@@ -790,10 +800,10 @@ if (argonConfig.waterflow_columns != "1") {
}
/*移动端文章列表布局切换*/
-!function(){
+!function () {
var mobileLayout = argonConfig.article_list_layout_mobile || "1";
var isMobile = window.innerWidth <= 900;
-
+
function applyMobileLayout() {
var nowMobile = window.innerWidth <= 900;
if (nowMobile) {
@@ -802,27 +812,27 @@ if (argonConfig.waterflow_columns != "1") {
$("html").removeClass("mobile-layout-1 mobile-layout-2 mobile-layout-3");
}
}
-
+
applyMobileLayout();
- $(window).resize(function(){
+ $(window).resize(function () {
applyMobileLayout();
});
}();
/*浮动按钮栏相关(回顶部)*/
-!function(){
+!function () {
// 确保 DOM 和 jQuery 已加载
if (typeof jQuery === 'undefined') {
setTimeout(arguments.callee, 50);
return;
}
-
+
let $fabtns = $('#float_action_buttons');
if ($fabtns.length === 0) {
setTimeout(arguments.callee, 50);
return;
}
-
+
let $backToTopBtn = $('#fabtn_back_to_top');
let $toggleSidesBtn = $('#fabtn_toggle_sides');
let $toggleDarkmode = $('#fabtn_toggle_darkmode');
@@ -834,31 +844,31 @@ if (argonConfig.waterflow_columns != "1") {
let $readingProgressBar = $('#fabtn_reading_progress_bar');
let $readingProgressDetails = $('#fabtn_reading_progress_details');
- $backToTopBtn.on("click" , function(){
+ $backToTopBtn.on("click", function () {
$("body,html").stop().animate({
scrollTop: 0
}, 600);
});
- $toggleDarkmode.on("click" , function(){
+ $toggleDarkmode.on("click", function () {
toggleDarkmode();
});
- $toggleAmoledMode.on("click" , function(){
+ $toggleAmoledMode.on("click", function () {
toggleAmoledDarkMode();
})
- if ($("#post_comment").length > 0){
+ if ($("#post_comment").length > 0) {
$("#fabtn_go_to_comment").removeClass("fabtn-hidden");
- }else{
+ } else {
$("#fabtn_go_to_comment").addClass("fabtn-hidden");
}
- $goToComment.on("click" , function(){
+ $goToComment.on("click", function () {
var commentsArea = $("#comments");
var postCommentArea = $("#post_comment");
var wasCollapsed = commentsArea.hasClass("comments-collapsed");
var toggleBtn = $("#comments_toggle");
-
+
if (wasCollapsed && toggleBtn.length > 0) {
// 折叠状态:先滚动到评论切换按钮位置,再展开
$("body,html").stop().animate({
@@ -868,7 +878,7 @@ if (argonConfig.waterflow_columns != "1") {
toggleBtn.find(".btn-inner--text").text("折叠评论");
toggleBtn.addClass("expanded");
commentsArea.removeClass("comments-collapsed");
- setTimeout(function() {
+ setTimeout(function () {
postCommentArea.removeClass("comments-collapsed");
$("#post_comment_content").focus();
}, 150);
@@ -881,60 +891,60 @@ if (argonConfig.waterflow_columns != "1") {
}
});
- if (localStorage['Argon_fabs_Floating_Status'] == "left"){
+ if (localStorage['Argon_fabs_Floating_Status'] == "left") {
$fabtns.addClass("fabtns-float-left");
}
- $toggleSidesBtn.on("click" , function(){
+ $toggleSidesBtn.on("click", function () {
$fabtns.addClass("fabtns-unloaded");
- setTimeout(function(){
+ setTimeout(function () {
$fabtns.toggleClass("fabtns-float-left");
- if ($fabtns.hasClass("fabtns-float-left")){
+ if ($fabtns.hasClass("fabtns-float-left")) {
localStorage['Argon_fabs_Floating_Status'] = "left";
- }else{
+ } else {
localStorage['Argon_fabs_Floating_Status'] = "right";
}
$fabtns.removeClass("fabtns-unloaded");
- } , 300);
+ }, 300);
});
//博客设置
- $toggleBlogSettings.on("click" , function(){
+ $toggleBlogSettings.on("click", function () {
$("#float_action_buttons").toggleClass("blog_settings_opened");
});
- $("#close_blog_settings").on("click" , function(){
+ $("#close_blog_settings").on("click", function () {
$("#float_action_buttons").removeClass("blog_settings_opened");
});
- $("#blog_setting_darkmode_switch .custom-toggle-slider").on("click" , function(){
+ $("#blog_setting_darkmode_switch .custom-toggle-slider").on("click", function () {
toggleDarkmode();
});
//字体
- $("#blog_setting_font_sans_serif").on("click" , function(){
+ $("#blog_setting_font_sans_serif").on("click", function () {
$("html").removeClass("use-serif");
localStorage['Argon_Use_Serif'] = "false";
});
- $("#blog_setting_font_serif").on("click" , function(){
+ $("#blog_setting_font_serif").on("click", function () {
$("html").addClass("use-serif");
localStorage['Argon_Use_Serif'] = "true";
});
// 字体设置已在 header.php 中预加载,此处无需重复应用
-
+
//阴影
- $("#blog_setting_shadow_small").on("click" , function(){
+ $("#blog_setting_shadow_small").on("click", function () {
$("html").removeClass("use-big-shadow");
localStorage['Argon_Use_Big_Shadow'] = "false";
});
- $("#blog_setting_shadow_big").on("click" , function(){
+ $("#blog_setting_shadow_big").on("click", function () {
$("html").addClass("use-big-shadow");
localStorage['Argon_Use_Big_Shadow'] = "true";
});
// 阴影设置已在 header.php 中预加载,此处无需重复应用
//滤镜
- function setBlogFilter(name){
- if (name == undefined || name == ""){
+ function setBlogFilter(name) {
+ if (name == undefined || name == "") {
name = "off";
}
- if (!$("html").hasClass("filter-" + name)){
+ if (!$("html").hasClass("filter-" + name)) {
$("html").removeClass("filter-sunset filter-darkness filter-grayscale");
- if (name != "off"){
+ if (name != "off") {
$("html").addClass("filter-" + name);
}
}
@@ -945,17 +955,17 @@ if (argonConfig.waterflow_columns != "1") {
// 滤镜设置已在 header.php 中预加载,此处只需设置按钮状态
let currentFilter = localStorage['Argon_Filter'] || 'off';
$("#blog_setting_filters .blog-setting-filter-btn[filter-name='" + currentFilter + "']").addClass("active");
- $(".blog-setting-filter-btn").on("click" , function(){
+ $(".blog-setting-filter-btn").on("click", function () {
setBlogFilter(this.getAttribute("filter-name"));
});
//UI 样式切换 (玻璃拟态/新拟态)
- function setUIStyle(style){
- if (style == undefined || style == ""){
+ function setUIStyle(style) {
+ if (style == undefined || style == "") {
style = "default";
}
$("html").removeClass("style-glass style-neumorphism");
- if (style != "default"){
+ if (style != "default") {
$("html").addClass("style-" + style);
}
$(".blog-setting-style-btn").removeClass("active");
@@ -965,60 +975,60 @@ if (argonConfig.waterflow_columns != "1") {
// UI 样式设置已在 header.php 中预加载,此处只需设置按钮状态
let currentUIStyle = localStorage['Argon_UI_Style'] || 'default';
$(".blog-setting-style-btn[style-name='" + currentUIStyle + "']").addClass("active");
- $(".blog-setting-style-btn").on("click" , function(){
+ $(".blog-setting-style-btn").on("click", function () {
setUIStyle(this.getAttribute("style-name"));
});
let $window = $(window);
- function changefabtnDisplayStatus(){
+ function changefabtnDisplayStatus() {
//阅读进度
- function hideReadingProgress(){
+ function hideReadingProgress() {
$readingProgressBtn.addClass("fabtn-hidden");
}
- function setReadingProgress(percent){
+ function setReadingProgress(percent) {
$readingProgressBtn.removeClass("fabtn-hidden");
$readingProgressDetails.html((percent * 100).toFixed(0) + "%");
- $readingProgressBar.css("width" , (percent * 100).toFixed(0) + "%");
+ $readingProgressBar.css("width", (percent * 100).toFixed(0) + "%");
}
- if ($("article.post.post-full").length == 0){
+ if ($("article.post.post-full").length == 0) {
hideReadingProgress();
- }else{
+ } else {
let a = $window.scrollTop() - ($("article.post.post-full").offset().top - 80);
let b = $("article.post.post-full").outerHeight() + 50 - $window.height();
- if (b <= 0){
+ if (b <= 0) {
hideReadingProgress();
- }else{
+ } else {
readingProgress = a / b;
- if (isNaN(readingProgress) || readingProgress < 0 || readingProgress > 1){
+ if (isNaN(readingProgress) || readingProgress < 0 || readingProgress > 1) {
hideReadingProgress();
- }else{
+ } else {
setReadingProgress(readingProgress);
}
}
}
//是否显示回顶
- if ($(window).scrollTop() >= 400){
+ if ($(window).scrollTop() >= 400) {
$backToTopBtn.removeClass("fabtn-hidden");
- }else{
+ } else {
$backToTopBtn.addClass("fabtn-hidden");
}
}
changefabtnDisplayStatus();
- $(window).scroll(function(){
+ $(window).scroll(function () {
changefabtnDisplayStatus();
});
- $(window).resize(function(){
+ $(window).resize(function () {
changefabtnDisplayStatus();
});
$fabtns.removeClass("fabtns-unloaded");
}();
/*卡片圆角大小调整*/
-!function(){
- function setCardRadius(radius, setcookie){
+!function () {
+ function setCardRadius(radius, setcookie) {
document.documentElement.style.setProperty('--card-radius', radius + "px");
- if (setcookie){
+ if (setcookie) {
setCookie("argon_card_radius", radius, 365);
}
}
@@ -1032,15 +1042,15 @@ if (argonConfig.waterflow_columns != "1") {
'max': [30]
}
});
- slider.noUiSlider.on('update', function (values){
+ slider.noUiSlider.on('update', function (values) {
let value = values[0];
setCardRadius(value, false);
});
- slider.noUiSlider.on('set', function (values){
+ slider.noUiSlider.on('set', function (values) {
let value = values[0];
setCardRadius(value, true);
});
- $(document).on("click" , "#blog_setting_card_radius_to_default" , function(){
+ $(document).on("click", "#blog_setting_card_radius_to_default", function () {
slider.noUiSlider.set($("meta[name='theme-card-radius-origin']").attr("content"));
setCardRadius($("meta[name='theme-card-radius-origin']").attr("content"), false);
setCookie("argon_card_radius", $("meta[name='theme-card-radius-origin']").attr("content"), 0);
@@ -1048,15 +1058,15 @@ if (argonConfig.waterflow_columns != "1") {
}();
/*评论区 & 发送评论*/
-!function(){
+!function () {
//回复评论
- let replying = false , replyID = 0;
-
+ let replying = false, replyID = 0;
+
/**
* 显示回复框
* @param {number} commentID - 评论ID
*/
- function reply(commentID){
+ function reply(commentID) {
cancelEdit(false);
replying = true;
replyID = commentID;
@@ -1071,12 +1081,12 @@ if (argonConfig.waterflow_columns != "1") {
preview = sourceEl.textContent;
}
$("#post_comment_reply_preview").text(preview);
- if ($("#comment-" + commentID + " .comment-item-title .badge-private-comment").length > 0){
+ if ($("#comment-" + commentID + " .comment-item-title .badge-private-comment").length > 0) {
$("#post_comment").addClass("post-comment-force-privatemode-on");
- }else{
+ } else {
$("#post_comment").addClass("post-comment-force-privatemode-off");
}
-
+
// 滚动到评论框(使用原生 scrollTo 避免 jQuery easing 依赖问题)
let postComment = $('#post_comment');
if (postComment.length > 0 && postComment.offset()) {
@@ -1086,7 +1096,7 @@ if (argonConfig.waterflow_columns != "1") {
behavior: 'smooth'
});
}
-
+
// 使用 CSS 动画显示回复框
let replyInfo = $('#post_comment_reply_info');
if (replyInfo.length > 0) {
@@ -1095,55 +1105,55 @@ if (argonConfig.waterflow_columns != "1") {
replyInfo[0].offsetHeight;
replyInfo.addClass('reply-entering');
}
-
- setTimeout(function(){
+
+ setTimeout(function () {
$("#post_comment_content").focus();
}, 300);
}
-
+
/**
* 取消回复
*/
- function cancelReply(){
+ function cancelReply() {
replying = false;
replyID = 0;
let replyInfo = $('#post_comment_reply_info');
replyInfo.removeClass('reply-entering').addClass('reply-leaving');
- setTimeout(function(){
+ setTimeout(function () {
replyInfo.css('display', 'none').removeClass('reply-leaving');
}, 200);
$("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off");
}
-
- $(document).on("click" , ".comment-reply" , function(){
+
+ $(document).on("click", ".comment-reply", function () {
reply(this.getAttribute("data-id"));
});
- $(document).on("click pjax:click" , "#post_comment_reply_cancel" , function(){
+ $(document).on("click pjax:click", "#post_comment_reply_cancel", function () {
cancelReply();
});
- $(document).on("pjax:click" , function(){
+ $(document).on("pjax:click", function () {
replying = false;
replyID = 0;
$('#post_comment_reply_info').css("display", "none").removeClass('reply-entering reply-leaving');
$("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off");
});
//编辑评论
- let editing = false , editID = 0;
- function edit(commentID){
+ let editing = false, editID = 0;
+ function edit(commentID) {
cancelReply();
editing = true;
editID = commentID;
$('#post_comment').addClass("editing");
$("#post_comment_content").val($("#comment-" + editID + " .comment-item-source").text());
$("#post_comment_content").trigger("change");
- if ($("#comment-" + editID).data("use-markdown") == true && document.getElementById("comment_post_use_markdown") != null){
+ if ($("#comment-" + editID).data("use-markdown") == true && document.getElementById("comment_post_use_markdown") != null) {
document.getElementById("comment_post_use_markdown").checked = true;
- }else{
+ } else {
document.getElementById("comment_post_use_markdown").checked = false;
}
- if ($("#comment-" + commentID + " .comment-item-title .badge-private-comment").length > 0){
+ if ($("#comment-" + commentID + " .comment-item-title .badge-private-comment").length > 0) {
$("#post_comment").addClass("post-comment-force-privatemode-on");
- }else{
+ } else {
$("#post_comment").addClass("post-comment-force-privatemode-off");
}
// 使用原生 scrollTo 避免 jQuery easing 依赖问题
@@ -1156,7 +1166,7 @@ if (argonConfig.waterflow_columns != "1") {
}
$("#post_comment_content").focus();
}
- function cancelEdit(clear){
+ function cancelEdit(clear) {
editing = false;
editID = 0;
$("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off");
@@ -1164,10 +1174,10 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment_content").trigger("change");
$('#post_comment').removeClass("editing");
}
- $(document).on("click", ".comment-edit", function(){
+ $(document).on("click", ".comment-edit", function () {
edit(this.getAttribute("data-id"));
});
- $(document).on("click", "#post_comment_edit_cancel", function(){
+ $(document).on("click", "#post_comment_edit_cancel", function () {
// 使用原生 scrollTo 避免 jQuery easing 依赖问题
let commentEl = document.getElementById("comment-" + editID);
if (commentEl) {
@@ -1178,46 +1188,46 @@ if (argonConfig.waterflow_columns != "1") {
}
cancelEdit(true);
});
- $(document).on("pjax:click", function(){
+ $(document).on("pjax:click", function () {
cancelEdit(true);
});
- $(document).on("click", ".comment-pin, .comment-unpin", function(){
+ $(document).on("click", ".comment-pin, .comment-unpin", function () {
toogleCommentPin(this.getAttribute("data-id"), !this.classList.contains("comment-pin"));
});
- $(document).on("click", ".comment-delete", function(){
+ $(document).on("click", ".comment-delete", function () {
deleteComment(this.getAttribute("data-id"));
});
- $(document).on("mouseenter", ".comment-parent-info", function(){
+ $(document).on("mouseenter", ".comment-parent-info", function () {
$("#comment-" + this.getAttribute("data-parent-id")).addClass("highlight");
});
- $(document).on("mouseleave", ".comment-parent-info", function(){
+ $(document).on("mouseleave", ".comment-parent-info", function () {
$("#comment-" + this.getAttribute("data-parent-id")).removeClass("highlight");
});
//切换评论置顶状态
- function toogleCommentPin(commentID, pinned){
+ function toogleCommentPin(commentID, pinned) {
$("#comment_pin_comfirm_dialog .modal-title").html(pinned ? __("取消置顶评论") : __("置顶评论"));
$("#comment_pin_comfirm_dialog .modal-body").html(pinned ? __("是否要取消置顶评论 #") + commentID + "?" : __("是否要置顶评论 #") + commentID + "?");
$("#comment_pin_comfirm_dialog .btn-comfirm").html(__("确认")).attr("disabled", false);
$("#comment_pin_comfirm_dialog .btn-dismiss").html(__("取消")).attr("disabled", false);
- $("#comment_pin_comfirm_dialog .btn-comfirm").off("click").on("click", function(){
+ $("#comment_pin_comfirm_dialog .btn-comfirm").off("click").on("click", function () {
$("#comment_pin_comfirm_dialog .btn-dismiss").attr("disabled", true)
$("#comment_pin_comfirm_dialog .btn-comfirm").attr("disabled", true).prepend(__(``));
$.ajax({
type: 'POST',
url: argonConfig.wp_path + "wp-admin/admin-ajax.php",
- dataType : "json",
+ dataType: "json",
data: {
action: "pin_comment",
id: commentID,
pinned: pinned ? "false" : "true"
},
- success: function(result){
+ success: function (result) {
$("#comment_pin_comfirm_dialog").modal('hide');
- if (result.status == "success"){
- if (pinned){
+ if (result.status == "success") {
+ if (pinned) {
$("#comment-" + commentID + " .comment-name .badge-pinned").remove();
$("#comment-" + commentID + " .comment-unpin").removeClass("comment-unpin").addClass("comment-pin").html(__("置顶"));
- }else{
+ } else {
$("#comment-" + commentID + " .comment-name").append(`${__("置顶")}`);
$("#comment-" + commentID + " .comment-pin").removeClass("comment-pin").addClass("comment-unpin").html(__("取消置顶"));
}
@@ -1250,7 +1260,7 @@ if (argonConfig.waterflow_columns != "1") {
});
}
},
- error: function(result){
+ error: function (result) {
$("#comment_pin_comfirm_dialog").modal('hide');
iziToast.show({
title: pinned ? __("取消置顶失败") : __("置顶失败"),
@@ -1270,13 +1280,13 @@ if (argonConfig.waterflow_columns != "1") {
});
$("#comment_pin_comfirm_dialog").modal(null);
}
-
+
//删除评论
function deleteComment(commentID) {
if (!confirm(__('确定要删除评论 #') + commentID + '?')) {
return;
}
-
+
$.ajax({
type: 'POST',
url: argonConfig.wp_path + 'wp-admin/admin-ajax.php',
@@ -1285,14 +1295,14 @@ if (argonConfig.waterflow_columns != "1") {
action: 'frontend_delete_comment',
id: commentID
},
- success: function(result) {
+ success: function (result) {
if (result.status === 'success') {
// 移除评论元素
- $('#comment-' + commentID).fadeOut(300, function() {
+ $('#comment-' + commentID).fadeOut(300, function () {
$(this).next('.comment-divider').remove();
$(this).remove();
});
-
+
iziToast.show({
title: __('删除成功'),
message: result.msg,
@@ -1322,7 +1332,7 @@ if (argonConfig.waterflow_columns != "1") {
});
}
},
- error: function() {
+ error: function () {
iziToast.show({
title: __('删除失败'),
message: __('未知错误'),
@@ -1339,38 +1349,38 @@ if (argonConfig.waterflow_columns != "1") {
}
});
}
-
+
//显示/隐藏额外输入框(评论者网址)
- $(document).on("click" , "#post_comment_toggle_extra_input" , function(){
+ $(document).on("click", "#post_comment_toggle_extra_input", function () {
$("#post_comment").toggleClass("show-extra-input");
- if ($("#post_comment").hasClass("show-extra-input")){
+ if ($("#post_comment").hasClass("show-extra-input")) {
$("#post_comment_extra_input").slideDown(250, 'easeOutCirc');
- }else{
+ } else {
$("#post_comment_extra_input").slideUp(200, 'easeOutCirc');
}
});
//输入框细节
- $(document).on("change input keydown keyup propertychange" , "#post_comment_content" , function(){
+ $(document).on("change input keydown keyup propertychange", "#post_comment_content", function () {
$("#post_comment_content_hidden")[0].innerText = $("#post_comment_content").val() + "\n";
- $("#post_comment_content").css("height" , $("#post_comment_content_hidden").outerHeight());
+ $("#post_comment_content").css("height", $("#post_comment_content_hidden").outerHeight());
});
- $(document).on("focus" , "#post_comment_link" , function(){
+ $(document).on("focus", "#post_comment_link", function () {
$(".post-comment-link-container").addClass("active");
});
- $(document).on("blur" , "#post_comment_link" , function(){
+ $(document).on("blur", "#post_comment_link", function () {
$(".post-comment-link-container").removeClass("active");
});
- $(document).on("focus" , "#post_comment_captcha" , function(){
+ $(document).on("focus", "#post_comment_captcha", function () {
$(".post-comment-captcha-container").addClass("active");
});
- $(document).on("blur" , "#post_comment_captcha" , function(){
+ $(document).on("blur", "#post_comment_captcha", function () {
$(".post-comment-captcha-container").removeClass("active");
});
//发送评论
- window.postComment = function postComment(){
+ window.postComment = function postComment() {
let commentContent = $("#post_comment_content").val();
let commentName = $("#post_comment_name").val();
let commentEmail = $("#post_comment_email").val();
@@ -1379,13 +1389,13 @@ if (argonConfig.waterflow_columns != "1") {
let useMarkdown = false;
let privateMode = false;
let mailNotice = false;
- if ($("#comment_post_use_markdown").length > 0){
+ if ($("#comment_post_use_markdown").length > 0) {
useMarkdown = $("#comment_post_use_markdown")[0].checked;
}
- if ($("#comment_post_privatemode").length > 0){
+ if ($("#comment_post_privatemode").length > 0) {
privateMode = $("#comment_post_privatemode")[0].checked;
}
- if ($("#comment_post_mailnotice").length > 0){
+ if ($("#comment_post_mailnotice").length > 0) {
mailNotice = $("#comment_post_mailnotice")[0].checked;
}
@@ -1396,80 +1406,80 @@ if (argonConfig.waterflow_columns != "1") {
let errorMsg = "";
//检查表单合法性
- if (commentContent.match(/^\s*$/)){
+ if (commentContent.match(/^\s*$/)) {
isError = true;
errorMsg += __("评论内容不能为空") + "";
}
- if (!$("#post_comment").hasClass("no-need-name-email")){
- if (commentName.match(/^\s*$/)){
+ if (!$("#post_comment").hasClass("no-need-name-email")) {
+ if (commentName.match(/^\s*$/)) {
isError = true;
errorMsg += __("昵称不能为空") + "";
}
- if ($("#post_comment").hasClass("enable-qq-avatar")){
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)){
+ if ($("#post_comment").hasClass("enable-qq-avatar")) {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱或QQ 号格式错误") + "";
}
- }else{
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)){
+ } else {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱格式错误") + "";
}
}
- }else{
- if (commentEmail.length || (document.getElementById("comment_post_mailnotice") != null && document.getElementById("comment_post_mailnotice").checked == true)){
- if ($("#post_comment").hasClass("enable-qq-avatar")){
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)){
+ } else {
+ if (commentEmail.length || (document.getElementById("comment_post_mailnotice") != null && document.getElementById("comment_post_mailnotice").checked == true)) {
+ if ($("#post_comment").hasClass("enable-qq-avatar")) {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱或QQ 号格式错误") + "";
}
- }else{
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)){
+ } else {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱格式错误") + "";
}
}
}
}
- if (commentLink != "" && !(/https?:\/\//).test(commentLink)){
+ if (commentLink != "" && !(/https?:\/\//).test(commentLink)) {
isError = true;
errorMsg += __("网站格式错误 (不是 http(s):// 开头)") + "";
}
- if (!$("#post_comment").hasClass("no-need-captcha")){
+ if (!$("#post_comment").hasClass("no-need-captcha")) {
// 检查是否使用Geetest验证码
- if ($("#geetest-captcha").length > 0) {
- // 检查Geetest库是否加载成功
- if (typeof window.geetestLoadFailed !== 'undefined' && window.geetestLoadFailed) {
- isError = true;
- errorMsg += __("验证码服务不可用,请刷新页面重试");
- } else if (typeof window.geetestCaptcha === 'undefined' || !window.geetestCaptcha) {
- isError = true;
- errorMsg += __("验证码未初始化,请稍后重试");;
- } else {
- // Geetest验证码检查
- let lotNumber = $("#geetest_lot_number").val();
- let captchaOutput = $("#geetest_captcha_output").val();
- let passToken = $("#geetest_pass_token").val();
- let genTime = $("#geetest_gen_time").val();
-
- if (!lotNumber || !captchaOutput || !passToken || !genTime) {
+ if ($("#geetest-captcha").length > 0) {
+ // 检查Geetest库是否加载成功
+ if (typeof window.geetestLoadFailed !== 'undefined' && window.geetestLoadFailed) {
isError = true;
- errorMsg += __("请完成验证码验证");
+ errorMsg += __("验证码服务不可用,请刷新页面重试");
+ } else if (typeof window.geetestCaptcha === 'undefined' || !window.geetestCaptcha) {
+ isError = true;
+ errorMsg += __("验证码未初始化,请稍后重试");;
+ } else {
+ // Geetest验证码检查
+ let lotNumber = $("#geetest_lot_number").val();
+ let captchaOutput = $("#geetest_captcha_output").val();
+ let passToken = $("#geetest_pass_token").val();
+ let genTime = $("#geetest_gen_time").val();
+
+ if (!lotNumber || !captchaOutput || !passToken || !genTime) {
+ isError = true;
+ errorMsg += __("请完成验证码验证");
+ }
}
- }
- } else {
+ } else {
// 原有的数学验证码验证
- if (commentCaptcha == ""){
+ if (commentCaptcha == "") {
isError = true;
errorMsg += __("验证码未输入");
}
- if (commentCaptcha != "" && !(/^[0-9]+$/).test(commentCaptcha)){
+ if (commentCaptcha != "" && !(/^[0-9]+$/).test(commentCaptcha)) {
isError = true;
errorMsg += __("验证码格式错误");
}
}
}
- if (isError){
+ if (isError) {
// 确保按钮和表单元素处于可用状态
$("#post_comment_send").removeAttr("disabled");
$("#post_comment_content").removeAttr("disabled");
@@ -1481,7 +1491,7 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment").removeClass("sending");
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送"));
-
+
iziToast.show({
title: __("评论格式错误"),
message: errorMsg,
@@ -1500,13 +1510,13 @@ if (argonConfig.waterflow_columns != "1") {
//增加 disabled 属性和其他的表单提示
$("#post_comment").addClass("sending");
- $("#post_comment_content").attr("disabled","disabled");
- $("#post_comment_name").attr("disabled","disabled");
- $("#post_comment_email").attr("disabled","disabled");
- $("#post_comment_captcha").attr("disabled","disabled");
- $("#post_comment_link").attr("disabled","disabled");
- $("#post_comment_send").attr("disabled","disabled");
- $("#post_comment_reply_cancel").attr("disabled","disabled");
+ $("#post_comment_content").attr("disabled", "disabled");
+ $("#post_comment_name").attr("disabled", "disabled");
+ $("#post_comment_email").attr("disabled", "disabled");
+ $("#post_comment_captcha").attr("disabled", "disabled");
+ $("#post_comment_link").attr("disabled", "disabled");
+ $("#post_comment_send").attr("disabled", "disabled");
+ $("#post_comment_reply_cancel").attr("disabled", "disabled");
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送中"));
@@ -1556,8 +1566,8 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment_reply_cancel").removeAttr("disabled");
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送"));
-
- setTimeout(function() {
+
+ setTimeout(function () {
try {
iziToast.destroy();
iziToast.error({
@@ -1571,13 +1581,13 @@ if (argonConfig.waterflow_columns != "1") {
}, 0);
return false;
}
-
+
// Geetest验证码参数 - 使用后端期望的参数名
ajaxData.lot_number = $("#geetest_lot_number").val();
ajaxData.captcha_output = $("#geetest_captcha_output").val();
ajaxData.pass_token = $("#geetest_pass_token").val();
ajaxData.gen_time = $("#geetest_gen_time").val();
-
+
// 验证Geetest参数是否完整
if (!ajaxData.lot_number || !ajaxData.captcha_output || !ajaxData.pass_token || !ajaxData.gen_time) {
// 重新启用按钮和表单元素
@@ -1591,9 +1601,9 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment_reply_cancel").removeAttr("disabled");
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送"));
-
+
// 使用 setTimeout 确保 iziToast 操作在下一个事件循环中执行
- setTimeout(function() {
+ setTimeout(function () {
try {
iziToast.destroy();
iziToast.error({
@@ -1616,9 +1626,9 @@ if (argonConfig.waterflow_columns != "1") {
$.ajax({
type: 'POST',
url: argonConfig.wp_path + "wp-admin/admin-ajax.php",
- dataType : "json",
+ dataType: "json",
data: ajaxData,
- success: function(result){
+ success: function (result) {
$("#post_comment").removeClass("sending");
$("#post_comment_content").removeAttr("disabled");
$("#post_comment_name").removeAttr("disabled");
@@ -1629,14 +1639,14 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送"));
$("#post_comment").removeClass("show-extra-input post-comment-force-privatemode-on post-comment-force-privatemode-off");
- if (!result.isAdmin){
+ if (!result.isAdmin) {
$("#post_comment_captcha").removeAttr("disabled");
}
//判断是否有错误
- if (result.status == "failed"){
+ if (result.status == "failed") {
// 使用 setTimeout 确保 iziToast 操作在下一个事件循环中执行
- setTimeout(function() {
+ setTimeout(function () {
try {
iziToast.destroy();
iziToast.show({
@@ -1663,12 +1673,12 @@ if (argonConfig.waterflow_columns != "1") {
// 先复位评论表单(确保无论后续操作是否成功都能重置表单)
cancelReply();
$("#post_comment_content").val("");
-
+
// 重置数学验证码
$("#post_comment_captcha_seed").val(result.newCaptchaSeed);
$("#post_comment_captcha + style").html(".post-comment-captcha-container:before{content: '" + result.newCaptcha + "';}");
$("#post_comment_captcha").val("");
-
+
// 清空Geetest验证码隐藏字段并重置验证码实例
if ($("#geetest-captcha").length > 0) {
$("#geetest_lot_number").val("");
@@ -1688,9 +1698,9 @@ if (argonConfig.waterflow_columns != "1") {
}
}
}
-
+
// 显示成功提示
- setTimeout(function() {
+ setTimeout(function () {
try {
iziToast.destroy();
iziToast.show({
@@ -1710,33 +1720,33 @@ if (argonConfig.waterflow_columns != "1") {
ArgonDebug.warn('iziToast error:', e);
}
}, 0);
-
+
// 插入新评论
try {
result.html = result.html.replace(/<(\/).noscript>/g, "");
let parentID = result.parentID;
- if (parentID == "" || parentID == null){
+ if (parentID == "" || parentID == null) {
parentID = 0;
}
parentID = parseInt(parentID);
- if (parentID == 0){
- if ($("#comments > .card-body > ol.comment-list").length == 0){
+ if (parentID == 0) {
+ if ($("#comments > .card-body > ol.comment-list").length == 0) {
$("#comments > .card-body").html("");
}
- if (result.commentOrder == "asc"){
+ if (result.commentOrder == "asc") {
$("#comments > .card-body > ol.comment-list").append(result.html);
- }else{
+ } else {
$("#comments > .card-body > ol.comment-list").prepend(result.html);
}
- }else{
- if ($("#comment-" + parentID + " + .comment-divider + li > ul.children").length > 0){
+ } else {
+ if ($("#comment-" + parentID + " + .comment-divider + li > ul.children").length > 0) {
$("#comment-" + parentID + " + .comment-divider + li > ul.children").append(result.html);
- }else{
+ } else {
$("#comment-" + parentID + " + .comment-divider").after("");
}
}
calcHumanTimesOnPage();
-
+
// 滚动到新评论
$("body,html").animate({
scrollTop: $("#comment-" + result.id).offset().top - 100
@@ -1744,8 +1754,8 @@ if (argonConfig.waterflow_columns != "1") {
} catch (e) {
ArgonDebug.warn('Comment insertion error:', e);
}
- },
- error: function(result){
+ },
+ error: function (result) {
$("#post_comment").removeClass("sending");
$("#post_comment_content").removeAttr("disabled");
$("#post_comment_name").removeAttr("disabled");
@@ -1756,7 +1766,7 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送"));
$("#post_comment").removeClass("show-extra-input post-comment-force-privatemode-on post-comment-force-privatemode-off");
- if (!result.isAdmin){
+ if (!result.isAdmin) {
$("#post_comment_captcha").removeAttr("disabled");
}
@@ -1770,11 +1780,11 @@ if (argonConfig.waterflow_columns != "1") {
$("#geetest_gen_time").val("");
// 重置 Geetest 实例,确保下一次生成新的pass_token
if (window.geetestCaptcha) {
- try { window.geetestCaptcha.reset(); } catch (e) {}
+ try { window.geetestCaptcha.reset(); } catch (e) { }
}
// 安全地处理iziToast 操作,防止time 属性错误
- setTimeout(function() {
+ setTimeout(function () {
try {
iziToast.destroy();
iziToast.show({
@@ -1799,15 +1809,15 @@ if (argonConfig.waterflow_columns != "1") {
});
}
//编辑评论
- function editComment(){
+ function editComment() {
let commentContent = $("#post_comment_content").val();
let isError = false;
let errorMsg = "";
- if (commentContent.match(/^\s*$/)){
+ if (commentContent.match(/^\s*$/)) {
isError = true;
errorMsg += __("评论内容不能为空") + "";
}
- if (isError){
+ if (isError) {
iziToast.show({
title: __("评论格式错误"),
message: errorMsg,
@@ -1825,9 +1835,9 @@ if (argonConfig.waterflow_columns != "1") {
}
//增加 disabled 属性和其他的表单提交
- $("#post_comment_content").attr("disabled","disabled");
- $("#post_comment_send").attr("disabled","disabled");
- $("#post_comment_edit_cancel").attr("disabled","disabled");
+ $("#post_comment_content").attr("disabled", "disabled");
+ $("#post_comment_send").attr("disabled", "disabled");
+ $("#post_comment_edit_cancel").attr("disabled", "disabled");
$("#post_comment_send .btn-inner--icon.hide-on-comment-not-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-not-editing").html(__("编辑中"));
@@ -1849,13 +1859,13 @@ if (argonConfig.waterflow_columns != "1") {
$.ajax({
type: 'POST',
url: argonConfig.wp_path + "wp-admin/admin-ajax.php",
- dataType : "json",
+ dataType: "json",
data: {
action: "user_edit_comment",
comment: commentContent,
id: editID
},
- success: function(result){
+ success: function (result) {
$("#post_comment_content").removeAttr("disabled");
$("#post_comment_send").removeAttr("disabled");
$("#post_comment_edit_cancel").removeAttr("disabled");
@@ -1863,7 +1873,7 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment_send .btn-inner--text.hide-on-comment-not-editing").html(__("编辑"));
//判断是否有错误
- if (result.status == "failed"){
+ if (result.status == "failed") {
iziToast.destroy();
iziToast.show({
title: __("评论编辑失败"),
@@ -1882,13 +1892,13 @@ if (argonConfig.waterflow_columns != "1") {
}
//发送成功,替换原评论
- result.new_comment = result.new_comment.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){
+ if ($("#comment-" + editID + " .comment-info .comment-edited").length == 0) {
$("#comment-" + editID + " .comment-info").prepend("")
}
- if (result.can_visit_edit_history){
+ if (result.can_visit_edit_history) {
$("#comment-" + editID + " .comment-info .comment-edited").addClass("comment-edithistory-accessible");
}
@@ -1915,13 +1925,13 @@ if (argonConfig.waterflow_columns != "1") {
$('#post_comment').removeClass("editing post-comment-force-privatemode-on post-comment-force-privatemode-off");
$("#post_comment_content").trigger("change");
},
- error: function(result){
+ error: function (result) {
$("#post_comment_content").removeAttr("disabled");
$("#post_comment_send").removeAttr("disabled");
$("#post_comment_edit_cancel").removeAttr("disabled");
$("#post_comment_send .btn-inner--icon.hide-on-comment-not-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-not-editing").html(__("编辑"));
- if (result.readyState != 4 || result.status == 0){
+ if (result.readyState != 4 || result.status == 0) {
iziToast.destroy();
iziToast.show({
title: __("评论编辑失败"),
@@ -1941,62 +1951,62 @@ if (argonConfig.waterflow_columns != "1") {
}
});
}
- $(document).on("click" , "#post_comment_send" , function(){
- if ($("#post_comment").hasClass("editing")){
+ $(document).on("click", "#post_comment_send", function () {
+ if ($("#post_comment").hasClass("editing")) {
editComment();
- }else{
+ } else {
// 首先进行基本的表单验证
let commentContent = $("#post_comment_content").val();
let commentName = $("#post_comment_name").val();
let commentEmail = $("#post_comment_email").val();
let commentLink = $("#post_comment_link").val();
-
+
let isError = false;
let errorMsg = "";
// 检查表单合法性
- if (commentContent.match(/^\s*$/)){
+ if (commentContent.match(/^\s*$/)) {
isError = true;
errorMsg += __("评论内容不能为空") + "";
}
- if (!$("#post_comment").hasClass("no-need-name-email")){
- if (commentName.match(/^\s*$/)){
+ if (!$("#post_comment").hasClass("no-need-name-email")) {
+ if (commentName.match(/^\s*$/)) {
isError = true;
errorMsg += __("昵称不能为空") + "";
}
- if ($("#post_comment").hasClass("enable-qq-avatar")){
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)){
+ if ($("#post_comment").hasClass("enable-qq-avatar")) {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱或QQ 号格式错误") + "";
}
- }else{
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)){
+ } else {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱格式错误") + "";
}
}
- }else{
- if (commentEmail.length || (document.getElementById("comment_post_mailnotice") != null && document.getElementById("comment_post_mailnotice").checked == true)){
- if ($("#post_comment").hasClass("enable-qq-avatar")){
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)){
+ } else {
+ if (commentEmail.length || (document.getElementById("comment_post_mailnotice") != null && document.getElementById("comment_post_mailnotice").checked == true)) {
+ if ($("#post_comment").hasClass("enable-qq-avatar")) {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail) && !(/^[1-9][0-9]{4,10}$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱或QQ 号格式错误") + "";
}
- }else{
- if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)){
+ } else {
+ if (!(/^\w+((-\w+)|(\.\w+))*\@[A-Za-z0-9]+((\.|-)[A-Za-z0-9]+)*\.[A-Za-z0-9]+$/).test(commentEmail)) {
isError = true;
errorMsg += __("邮箱格式错误") + "";
}
}
}
}
- if (commentLink != "" && !(/https?:\/\//).test(commentLink)){
+ if (commentLink != "" && !(/https?:\/\//).test(commentLink)) {
isError = true;
errorMsg += __("网站格式错误 (不是 http(s):// 开头") + "";
}
-
+
// 如果基本表单验证失败,显示错误信息并返回
- if (isError){
+ if (isError) {
// 确保按钮和表单元素处于可用状态
$("#post_comment_send").removeAttr("disabled");
$("#post_comment_content").removeAttr("disabled");
@@ -2008,7 +2018,7 @@ if (argonConfig.waterflow_columns != "1") {
$("#post_comment").removeClass("sending");
$("#post_comment_send .btn-inner--icon.hide-on-comment-editing").html("");
$("#post_comment_send .btn-inner--text.hide-on-comment-editing").html(__("发送"));
-
+
iziToast.show({
title: __("评论格式错误"),
message: errorMsg,
@@ -2024,29 +2034,29 @@ if (argonConfig.waterflow_columns != "1") {
});
return;
}
-
+
// 基本验证通过后,检查验证码
if ($("#geetest-captcha").length > 0) {
// 检查Geetest 库是否加载失败
if (window.geetestLoadFailed) {
if (typeof loadGeetestScript === 'function' && typeof initGeetestCaptchaCore === 'function') {
try {
- loadGeetestScript(function(){
+ loadGeetestScript(function () {
initGeetestCaptchaCore();
- setTimeout(function(){
- if (window.geetestCaptcha) { try { window.geetestCaptcha.showBox(); } catch(e){} }
+ setTimeout(function () {
+ if (window.geetestCaptcha) { try { window.geetestCaptcha.showBox(); } catch (e) { } }
}, 0);
});
- } catch(e) {}
+ } catch (e) { }
}
return;
}
-
+
// 如果正在自动提交中,防止重复点击
if (window.geetestAutoSubmitting) {
return;
}
-
+
// 如果使用Geetest,检查验证码是否已完成
if (!window.geetestVerified) {
// 验证码未完成,触发验证码显示
@@ -2058,13 +2068,13 @@ if (argonConfig.waterflow_columns != "1") {
} else {
if (typeof loadGeetestScript === 'function' && typeof initGeetestCaptchaCore === 'function') {
try {
- loadGeetestScript(function(){
+ loadGeetestScript(function () {
initGeetestCaptchaCore();
- setTimeout(function(){
- if (window.geetestCaptcha) { try { window.geetestCaptcha.showBox(); } catch(e){} }
+ setTimeout(function () {
+ if (window.geetestCaptcha) { try { window.geetestCaptcha.showBox(); } catch (e) { } }
}, 0);
});
- } catch(e) {}
+ } catch (e) { }
}
}
return;
@@ -2076,15 +2086,15 @@ if (argonConfig.waterflow_columns != "1") {
});
}();
/*评论点赞*/
-$(document).on('click', '.comment-upvote', function(){
+$(document).on('click', '.comment-upvote', function () {
let $this = $(this);
let ID = $this.attr('data-id');
-
+
// 防止重复点击
if ($this.hasClass('comment-upvoting')) {
return;
}
-
+
$this.addClass('comment-upvoting');
$.ajax({
url: argonConfig.wp_path + 'wp-admin/admin-ajax.php',
@@ -2094,9 +2104,9 @@ $(document).on('click', '.comment-upvote', function(){
action: 'upvote_comment',
comment_id: ID,
},
- success: function(result){
+ success: function (result) {
$this.removeClass('comment-upvoting');
- if (result.status === 'success'){
+ if (result.status === 'success') {
$('.comment-upvote-num', $this).html(result.total_upvote);
if (result.upvoted) {
$this.addClass('upvoted');
@@ -2119,7 +2129,7 @@ $(document).on('click', '.comment-upvote', function(){
});
}
},
- error: function(xhr){
+ error: function (xhr) {
$this.removeClass('comment-upvoting');
iziToast.show({
title: __('点赞失败'),
@@ -2137,30 +2147,30 @@ $(document).on('click', '.comment-upvote', function(){
});
});
/*评论表情面板*/
-function lazyloadStickers(){
+function lazyloadStickers() {
// 原生懒加载无需额外处理
}
-$(document).on("click" , "#comment_emotion_btn" , function(){
+$(document).on("click", "#comment_emotion_btn", function () {
$("#comment_emotion_btn").toggleClass("comment-emotion-keyboard-open");
});
-$(document).on("click" , ".emotion-keyboard .emotion-group-name" , function(){
+$(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");
});
-function inputInsertText(text, input){
+function inputInsertText(text, input) {
$(input).focus();
let isSuccess = document.execCommand("insertText", false, text);
if (!isSuccess) { //FF
- if (typeof input.setRangeText === "function"){
+ if (typeof input.setRangeText === "function") {
const start = input.selectionStart;
input.setRangeText(text);
input.selectionStart = input.selectionEnd = start + input.length;
const e = document.createEvent("UIEvent");
e.initEvent("input", true, false);
input.dispatchEvent(e);
- }else{
+ } else {
let value = $(input).val();
let startPos = input.selectionStart, endPos = input.selectionEnd;
$(input).val(value.substring(0, startPos) + text + value.substring(endPos));
@@ -2170,27 +2180,27 @@ function inputInsertText(text, input){
}
$(input).focus();
}
-$(document).on("click" , ".emotion-keyboard .emotion-item" , function(){
+$(document).on("click", ".emotion-keyboard .emotion-item", function () {
$("#comment_emotion_btn").removeClass("comment-emotion-keyboard-open");
- if ($(this).hasClass("emotion-item-sticker")){
+ if ($(this).hasClass("emotion-item-sticker")) {
inputInsertText(" :" + $(this).attr("code") + ": ", document.getElementById("post_comment_content"));
- }else{
+ } else {
inputInsertText($(this).attr("text"), document.getElementById("post_comment_content"));
}
});
-$(document).on("dragstart" , ".emotion-keyboard .emotion-item > img, .comment-sticker" , function(e){
+$(document).on("dragstart", ".emotion-keyboard .emotion-item > img, .comment-sticker", function (e) {
e.preventDefault();
});
document.addEventListener('click', (e) => {
- if (document.getElementById("comment_emotion_btn") == null){
+ if (document.getElementById("comment_emotion_btn") == null) {
return;
}
- if(e.target.id != "comment_emotion_btn" && e.target.id != "emotion_keyboard" && !document.getElementById("comment_emotion_btn").contains(e.target) && !document.getElementById("emotion_keyboard").contains(e.target)){
+ if (e.target.id != "comment_emotion_btn" && e.target.id != "emotion_keyboard" && !document.getElementById("comment_emotion_btn").contains(e.target) && !document.getElementById("emotion_keyboard").contains(e.target)) {
$("#comment_emotion_btn").removeClass("comment-emotion-keyboard-open");
- }
+ }
})
/*查看评论编辑记录*/
-function showCommentEditHistory(id){
+function showCommentEditHistory(id) {
let requestID = parseInt(new Date().getTime());
$("#comment_edit_history").data("request-id", requestID);
$("#comment_edit_history .modal-title").html(__("评论 #") + id + " " + __("的编辑记录"));
@@ -2199,21 +2209,21 @@ function showCommentEditHistory(id){
$.ajax({
type: 'POST',
url: argonConfig.wp_path + "wp-admin/admin-ajax.php",
- dataType : "json",
+ dataType: "json",
data: {
action: "get_comment_edit_history",
id: id
},
- success: function(result){
- if ($("#comment_edit_history").data("request-id") != requestID){
+ success: function (result) {
+ if ($("#comment_edit_history").data("request-id") != requestID) {
return;
}
$("#comment_edit_history .modal-body").hide();
$("#comment_edit_history .modal-body").html(result.history);
$("#comment_edit_history .modal-body").fadeIn(300);
},
- error: function(result){
- if ($("#comment_edit_history").data("request-id") != requestID){
+ error: function (result) {
+ if ($("#comment_edit_history").data("request-id") != requestID) {
return;
}
$("#comment_edit_history .modal-body").hide();
@@ -2222,75 +2232,75 @@ function showCommentEditHistory(id){
}
});
}
-$(document).on("click" , ".comment-edited.comment-edithistory-accessible" , function(){
+$(document).on("click", ".comment-edited.comment-edithistory-accessible", function () {
showCommentEditHistory($(this).parent().parent().parent().parent().data("id"));
});
/*过长评论折叠*/
-function foldLongComments(){
- if (argonConfig.fold_long_comments == false){
+function foldLongComments() {
+ if (argonConfig.fold_long_comments == false) {
return;
}
- $(".comment-item-inner").each(function(){
- if ($(this).hasClass("comment-unfolded")){
+ $(".comment-item-inner").each(function () {
+ if ($(this).hasClass("comment-unfolded")) {
return;
}
- if (this.clientHeight > 800){
+ if (this.clientHeight > 800) {
$(this).addClass("comment-folded");
$(this).append("");
}
});
}
foldLongComments();
-$(document).on("click" , ".show-full-comment" , function(){
+$(document).on("click", ".show-full-comment", function () {
$(this).parent().removeClass("comment-folded").addClass("comment-unfolded");
});
/*评论文字头像*/
-function generateCommentTextAvatar(img){
+function generateCommentTextAvatar(img) {
let emailHash = '';
- try{
+ try {
emailHash = img.attr("src").match(/([a-f\d]{32}|[A-F\d]{32})/)[0];
- }catch{
+ } catch {
emailHash = img.parent().parent().parent().find(".comment-name").text().trim();
- if (emailHash == '' || emailHash == undefined){
+ if (emailHash == '' || emailHash == undefined) {
emailHash = img.parent().find("*[class*='comment-author']").text().trim();
}
}
let hash = 0;
- for (i in emailHash){
+ for (i in emailHash) {
hash = (hash * 233 + emailHash.charCodeAt(i)) % 16;
}
let colors = ['#e25f50', '#f25e90', '#bc67cb', '#9672cf', '#7984ce', '#5c96fa', '#7bdeeb', '#45d0e2', '#48b7ad', '#52bc89', '#9ace5f', '#d4e34a', '#f9d715', '#fac400', '#ffaa00', '#ff8b61', '#c2c2c2', '#8ea3af', '#a1877d', '#a3a3a3', '#b0b6e3', '#b49cde', '#c2c2c2', '#7bdeeb', '#bcaaa4', '#aed77f'];
let text = $(".comment-name", img.parent().parent().parent()).text().trim()[0];
- if (text == '' || text == undefined){
+ if (text == '' || text == undefined) {
text = img.parent().find("*[class*='comment-author']").text().trim()[0];
}
let classList = img.attr('class') + " text-avatar";
img.prop('outerHTML', '' + text + '
');
}
-document.addEventListener("error", function(e){
+document.addEventListener("error", function (e) {
let img = $(e.target);
- if (!img.hasClass("avatar")){
+ if (!img.hasClass("avatar")) {
return;
}
generateCommentTextAvatar(img);
}, true);
-function refreshCommentTextAvatar(){
- $(".comment-item-avatar > img.avatar").each(function(index, img){
- if (!img.complete){
+function refreshCommentTextAvatar() {
+ $(".comment-item-avatar > img.avatar").each(function (index, img) {
+ if (!img.complete) {
return;
}
- if (img.naturalWidth !== 0){
+ if (img.naturalWidth !== 0) {
return false;
}
generateCommentTextAvatar($(img));
});
}
refreshCommentTextAvatar();
-$(window).on("load", function(){
+$(window).on("load", function () {
refreshCommentTextAvatar();
});
/*需要密码的文章加载*/
-$(document).on("submit" , ".post-password-form" , function(){
+$(document).on("submit", ".post-password-form", function () {
$("input[type='submit']", this).attr("disabled", "disabled");
let url = $(this).attr("action");
$.pjax.form(this, {
@@ -2300,16 +2310,16 @@ $(document).on("submit" , ".post-password-form" , function(){
return false;
});
/*评论分页加载*/
-!function(){
- $(document).on("click" , "#comments_navigation .page-item > div" , function(){
+!function () {
+ $(document).on("click", "#comments_navigation .page-item > div", function () {
$("#comments").addClass("comments-loading");
NProgress.set(0.618);
url = $(this).attr("href");
$.ajax({
type: 'POST',
url: url,
- dataType : "html",
- success : function(result){
+ dataType: "html",
+ success: function (result) {
NProgress.done();
$vdom = $(result);
$("#comments").html($("#comments", $vdom).html());
@@ -2321,12 +2331,12 @@ $(document).on("submit" , ".post-password-form" , function(){
calcHumanTimesOnPage();
panguInit();
},
- error : function(){
+ error: function () {
window.location.href = url;
}
});
});
- $(document).on("click" , "#comments_more" , function(){
+ $(document).on("click", "#comments_more", function () {
$("#comments_more").attr("disabled", "disabled");
NProgress.set(0.618);
url = $(this).attr("href");
@@ -2336,15 +2346,15 @@ $(document).on("submit" , ".post-password-form" , function(){
data: {
no_post_view: 'true'
},
- dataType : "html",
- success : function(result){
+ dataType: "html",
+ success: function (result) {
NProgress.done();
$vdom = $(result);
$("#comments > .card-body > ol.comment-list").append($("#comments > .card-body > ol.comment-list", $vdom).html());
- if ($("#comments_more", $vdom).length == 0){
+ if ($("#comments_more", $vdom).length == 0) {
$("#comments_more").remove();
$(".comments-navigation-more").html("");
- }else{
+ } else {
$("#comments_more").attr("href", $("#comments_more", $vdom).attr("href"));
$("#comments_more").removeAttr("disabled");
}
@@ -2352,7 +2362,7 @@ $(document).on("submit" , ".post-password-form" , function(){
calcHumanTimesOnPage();
panguInit();
},
- error : function(){
+ error: function () {
window.location.href = url;
}
});
@@ -2360,8 +2370,8 @@ $(document).on("submit" , ".post-password-form" , function(){
}();
/*URL 和# 根据 ID 定位*/
-function gotoHash(hash, durtion, easing = 'easeOutExpo'){
- if (!hash || hash === "#"){
+function gotoHash(hash, durtion, easing = 'easeOutExpo') {
+ if (!hash || hash === "#") {
return;
}
var target = null;
@@ -2381,29 +2391,29 @@ function gotoHash(hash, durtion, easing = 'easeOutExpo'){
return;
}
}
- if (!target){
+ if (!target) {
return;
}
- if (durtion == null){
+ if (durtion == null) {
durtion = 200;
}
$("body,html").stop().animate({
scrollTop: $(target).offset().top - 80
}, durtion, easing);
}
-function getHash(url){
+function getHash(url) {
return url.substring(url.indexOf('#'));
}
-!function(){
- $(window).on("hashchange" , function(){
+!function () {
+ $(window).on("hashchange", function () {
gotoHash(window.location.hash);
});
$(window).trigger("hashchange");
}();
/*显示文章过时信息 Toast*/
-function showPostOutdateToast(){
- if ($("#primary #post_outdate_toast").length > 0){
+function showPostOutdateToast() {
+ if ($("#primary #post_outdate_toast").length > 0) {
iziToast.show({
title: '',
message: $("#primary #post_outdate_toast").data("text"),
@@ -2427,24 +2437,24 @@ showPostOutdateToast();
// 全局 Zoomify 实例数组,用于清理
var zoomifyInstances = [];
-function zoomifyInit(){
+function zoomifyInit() {
// 清理旧的 Zoomify 实例
if (zoomifyInstances.length > 0) {
- zoomifyInstances.forEach(function(instance) {
+ zoomifyInstances.forEach(function (instance) {
try {
if (instance && typeof instance.destroy === 'function') {
instance.destroy();
}
- } catch(e) {}
+ } catch (e) { }
});
zoomifyInstances = [];
}
-
- if (argonConfig.zoomify == false){
+
+ if (argonConfig.zoomify == false) {
return;
}
if (typeof $.fn.zoomify === 'function') {
- $("article img:not(.zoomify-initialized)").each(function() {
+ $("article img:not(.zoomify-initialized)").each(function () {
let $img = $(this);
$img.addClass('zoomify-initialized');
try {
@@ -2452,7 +2462,7 @@ function zoomifyInit(){
if (instance) {
zoomifyInstances.push(instance);
}
- } catch(e) {}
+ } catch (e) { }
});
}
}
@@ -2512,12 +2522,12 @@ function lazyloadInit() {
lazyloadObserver.disconnect();
lazyloadObserver = null;
ArgonDebug.log('清理旧的 Lazyload Observer');
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理 Lazyload Observer 失败:', e);
lazyloadObserver = null;
}
}
-
+
// 清理旧的滚动监听器(降级方案)
if (lazyloadScrollHandler) {
try {
@@ -2525,35 +2535,35 @@ function lazyloadInit() {
window.removeEventListener('resize', lazyloadScrollHandler);
lazyloadScrollHandler = null;
ArgonDebug.log('清理旧的滚动监听器');
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理滚动监听器失败:', e);
lazyloadScrollHandler = null;
}
}
-
+
// 检查是否启用懒加载
if (argonConfig.lazyload === false || argonConfig.lazyload === 'false') {
// 未启用懒加载时,直接加载所有图片
loadAllImagesImmediately();
return;
}
-
+
let images = document.querySelectorAll('img.lazyload[data-src]');
if (images.length === 0) {
ArgonDebug.log('没有需要懒加载的图片');
return;
}
-
+
let effect = argonConfig.lazyload_effect || 'fadeIn';
let threshold = parseInt(argonConfig.lazyload_threshold) || 800;
-
+
ArgonDebug.log(`初始化懒加载: ${images.length} 张图片, 效果: ${effect}, 阈值: ${threshold}px`);
-
+
// 使用 IntersectionObserver 实现懒加载
if ('IntersectionObserver' in window) {
try {
- lazyloadObserver = new IntersectionObserver(function(entries) {
- entries.forEach(function(entry) {
+ lazyloadObserver = new IntersectionObserver(function (entries) {
+ entries.forEach(function (entry) {
if (entry.isIntersecting) {
let img = entry.target;
loadImageOptimized(img, effect);
@@ -2563,17 +2573,17 @@ function lazyloadInit() {
}, {
rootMargin: threshold + 'px 0px'
});
-
- images.forEach(function(img) {
+
+ images.forEach(function (img) {
// 重置图片状态
img.style.opacity = '';
img.style.transform = '';
img.style.transition = '';
lazyloadObserver.observe(img);
});
-
+
ArgonDebug.log('使用 IntersectionObserver 实现懒加载');
- } catch(e) {
+ } catch (e) {
ArgonDebug.error('IntersectionObserver 初始化失败,使用降级方案:', e);
lazyloadFallback(images, effect, threshold);
}
@@ -2599,12 +2609,12 @@ function loadImageOptimized(img, effect) {
}
return;
}
-
+
// 预加载图片
let tempImg = new Image();
- tempImg.onload = function() {
+ tempImg.onload = function () {
// 使用 requestAnimationFrame 优化 DOM 操作
- requestAnimationFrame(function() {
+ requestAnimationFrame(function () {
img.src = src;
img.removeAttribute('data-src');
let srcset = img.getAttribute('data-srcset');
@@ -2618,17 +2628,17 @@ function loadImageOptimized(img, effect) {
img.removeAttribute('data-sizes');
}
img.classList.remove('lazyload');
-
+
// 移除所有lazyload-style-* 类
img.className = img.className.replace(/\blazyload-style-\d+\b/g, '').trim();
-
+
// 应用加载效果
applyLoadEffectOptimized(img, effect);
});
};
- tempImg.onerror = function() {
+ tempImg.onerror = function () {
// 加载失败时使用降级方案
- requestAnimationFrame(function() {
+ requestAnimationFrame(function () {
img.src = src;
img.removeAttribute('data-src');
let srcset = img.getAttribute('data-srcset');
@@ -2643,7 +2653,7 @@ function loadImageOptimized(img, effect) {
}
img.classList.remove('lazyload');
img.className = img.className.replace(/\blazyload-style-\d+\b/g, '').trim();
-
+
// 取消 Observer 监听
if (lazyloadObserver) {
lazyloadObserver.unobserve(img);
@@ -2662,8 +2672,8 @@ function applyLoadEffectOptimized(img, effect) {
if (effect === 'fadeIn') {
img.style.opacity = '0';
img.style.transition = 'opacity 0.3s ease';
- requestAnimationFrame(function() {
- requestAnimationFrame(function() {
+ requestAnimationFrame(function () {
+ requestAnimationFrame(function () {
img.style.opacity = '1';
});
});
@@ -2671,13 +2681,13 @@ function applyLoadEffectOptimized(img, effect) {
img.addEventListener('transitionend', function cleanup() {
img.style.transition = '';
img.removeEventListener('transitionend', cleanup);
- }, {once: true});
+ }, { once: true });
} else if (effect === 'slideDown') {
img.style.opacity = '0';
img.style.transform = 'translateY(-20px)';
img.style.transition = 'opacity 0.3s ease, transform 0.3s ease';
- requestAnimationFrame(function() {
- requestAnimationFrame(function() {
+ requestAnimationFrame(function () {
+ requestAnimationFrame(function () {
img.style.opacity = '1';
img.style.transform = 'translateY(0)';
});
@@ -2687,7 +2697,7 @@ function applyLoadEffectOptimized(img, effect) {
img.style.transition = '';
img.style.transform = '';
img.removeEventListener('transitionend', cleanup);
- }, {once: true});
+ }, { once: true });
}
}
@@ -2700,21 +2710,21 @@ function applyLoadEffectOptimized(img, effect) {
*/
function lazyloadFallback(images, effect, threshold) {
let loadedImages = new Set();
-
+
function checkImagesInView() {
let viewportHeight = window.innerHeight;
let scrollTop = document.documentElement.scrollTop || document.body.scrollTop;
-
- images.forEach(function(img) {
+
+ images.forEach(function (img) {
if (loadedImages.has(img)) return;
-
+
let rect = img.getBoundingClientRect();
if (rect.top < viewportHeight + threshold && rect.bottom > -threshold) {
loadImageOptimized(img, effect);
loadedImages.add(img);
}
});
-
+
// 如果所有图片都已加载,清理监听器
if (loadedImages.size === images.length) {
if (lazyloadScrollHandler) {
@@ -2725,16 +2735,16 @@ function lazyloadFallback(images, effect, threshold) {
}
}
}
-
+
// 使用 eventManager 的节流函数优化性能
- lazyloadScrollHandler = argonEventManager ?
- argonEventManager.throttle(checkImagesInView, 100) :
+ lazyloadScrollHandler = argonEventManager ?
+ argonEventManager.throttle(checkImagesInView, 100) :
checkImagesInView;
-
+
// 绑定事件监听器
- window.addEventListener('scroll', lazyloadScrollHandler, {passive: true});
- window.addEventListener('resize', lazyloadScrollHandler, {passive: true});
-
+ window.addEventListener('scroll', lazyloadScrollHandler, { passive: true });
+ window.addEventListener('resize', lazyloadScrollHandler, { passive: true });
+
// 立即检查一次
checkImagesInView();
}
@@ -2745,7 +2755,7 @@ function lazyloadFallback(images, effect, threshold) {
*/
function loadAllImagesImmediately() {
let images = document.querySelectorAll('img.lazyload[data-src]');
- images.forEach(function(img) {
+ images.forEach(function (img) {
let src = img.getAttribute('data-src');
if (src) {
img.src = src;
@@ -2775,34 +2785,34 @@ if (document.readyState === 'loading') {
}
/*Pangu.js*/
-function panguInit(){
- if (argonConfig.pangu.indexOf("article") >= 0){
+function panguInit() {
+ if (argonConfig.pangu.indexOf("article") >= 0) {
pangu.spacingElementByClassName('post-content');
}
- if (argonConfig.pangu.indexOf("comment") >= 0){
+ if (argonConfig.pangu.indexOf("comment") >= 0) {
pangu.spacingElementById('comments');
}
- if (argonConfig.pangu.indexOf("shuoshuo") >= 0){
+ if (argonConfig.pangu.indexOf("shuoshuo") >= 0) {
pangu.spacingElementByClassName('shuoshuo-content');
}
}
panguInit();
/*Clamp.js*/
-function clampInit(){
- $(".clamp").each(function(index, dom) {
- $clamp(dom, {clamp: dom.getAttribute("clamp-line")});
+function clampInit() {
+ $(".clamp").each(function (index, dom) {
+ $clamp(dom, { clamp: dom.getAttribute("clamp-line") });
});
}
clampInit();
/*Tippy.js*/
-function tippyInit(){
+function tippyInit() {
//Reference Popover
tippy('sup.reference[data-content]:not(.tippy-initialized)', {
content: (reference) => reference.getAttribute('data-content'),
allowHTML: true,
- interactive: true,theme: 'light scroll-y',
+ interactive: true, theme: 'light scroll-y',
delay: [100, 250],
animation: 'fade'
});
@@ -2811,50 +2821,50 @@ function tippyInit(){
tippyInit();
/*Banner 全屏封面相关*/
-if ($("html").hasClass("banner-as-cover")){
- function classInit(){
- if ($("#main").hasClass("article-list-home")){
- if (!$("html").hasClass("is-home")){
+if ($("html").hasClass("banner-as-cover")) {
+ function classInit() {
+ if ($("#main").hasClass("article-list-home")) {
+ if (!$("html").hasClass("is-home")) {
$("html").addClass("is-home");
$("html").trigger("resize");
}
- }else{
- if ($("html").hasClass("is-home")){
+ } else {
+ if ($("html").hasClass("is-home")) {
$("html").removeClass("is-home");
$("html").trigger("resize");
}
}
}
classInit();
- new MutationObserver(function(mutations, observer){
+ new MutationObserver(function (mutations, observer) {
classInit();
}).observe(document.querySelector("#primary"), {
'childList': true
});
- $(".cover-scroll-down").on("click" , function(){
+ $(".cover-scroll-down").on("click", function () {
gotoHash("#content", 600, 'easeOutCirc');
$("#content").focus();
});
$fabs = $("#float_action_buttons");
$coverScrollDownBtn = $(".cover-scroll-down");
- function changeWidgetsDisplayStatus(){
+ function changeWidgetsDisplayStatus() {
let scrollTop = $(window).scrollTop();
- if (scrollTop >= window.outerHeight * 0.2){
+ if (scrollTop >= window.outerHeight * 0.2) {
$fabs.removeClass("hidden");
- }else{
+ } else {
$fabs.addClass("hidden");
}
- if (scrollTop >= window.outerHeight * 0.6){
+ if (scrollTop >= window.outerHeight * 0.6) {
$coverScrollDownBtn.addClass("hidden");
- }else{
+ } else {
$coverScrollDownBtn.removeClass("hidden");
}
}
changeWidgetsDisplayStatus();
- $(window).scroll(function(){
+ $(window).scroll(function () {
changeWidgetsDisplayStatus();
});
- $(window).resize(function(){
+ $(window).resize(function () {
changeWidgetsDisplayStatus();
});
}
@@ -2880,12 +2890,12 @@ function cleanupLazyloadObserver() {
lazyloadObserver.disconnect();
lazyloadObserver = null;
ArgonDebug.log('Lazyload Observer 已清理');
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理 Lazyload Observer 失败:', e);
lazyloadObserver = null;
}
}
-
+
// 清理滚动监听器(降级方案)
if (lazyloadScrollHandler) {
try {
@@ -2893,7 +2903,7 @@ function cleanupLazyloadObserver() {
window.removeEventListener('resize', lazyloadScrollHandler);
lazyloadScrollHandler = null;
ArgonDebug.log('Lazyload 滚动监听器已清理');
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理 Lazyload 滚动监听器失败:', e);
lazyloadScrollHandler = null;
}
@@ -2907,13 +2917,13 @@ function cleanupLazyloadObserver() {
function cleanupZoomifyInstances() {
if (zoomifyInstances && zoomifyInstances.length > 0) {
let cleanedCount = 0;
- zoomifyInstances.forEach(function(instance) {
+ zoomifyInstances.forEach(function (instance) {
try {
if (instance && typeof instance.destroy === 'function') {
instance.destroy();
cleanedCount++;
}
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('销毁 Zoomify 实例失败:', e);
}
});
@@ -2931,13 +2941,13 @@ function cleanupZoomifyInstances() {
function cleanupTippyInstances() {
if (typeof tippy !== 'undefined') {
let cleanedCount = 0;
- document.querySelectorAll('[data-tippy-root]').forEach(function(el) {
+ document.querySelectorAll('[data-tippy-root]').forEach(function (el) {
try {
if (el._tippy && typeof el._tippy.destroy === 'function') {
el._tippy.destroy();
cleanedCount++;
}
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('销毁 Tippy 实例失败:', e);
}
});
@@ -2958,12 +2968,12 @@ function cleanupDynamicStyles() {
// 只清理标记为动态的样式
const dynamicStyles = document.querySelectorAll('style[data-dynamic="true"]');
if (dynamicStyles.length > 0) {
- dynamicStyles.forEach(function(style) {
+ dynamicStyles.forEach(function (style) {
style.remove();
});
ArgonDebug.log(`已清理 ${dynamicStyles.length} 个动态样式`);
}
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理动态样式失败:', e);
}
}
@@ -2977,12 +2987,12 @@ function cleanupDynamicScripts() {
// 只清理标记为动态的脚本
const dynamicScripts = document.querySelectorAll('script[data-dynamic="true"]');
if (dynamicScripts.length > 0) {
- dynamicScripts.forEach(function(script) {
+ dynamicScripts.forEach(function (script) {
script.remove();
});
ArgonDebug.log(`已清理 ${dynamicScripts.length} 个动态脚本`);
}
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理动态脚本失败:', e);
}
}
@@ -2995,11 +3005,11 @@ function cleanupEventListeners() {
try {
// 注意:大部分事件使用事件委托,不需要手动清理
// 这里只清理特定的非委托事件
-
+
// Lazyload 滚动监听器已在 cleanupLazyloadObserver() 中清理
-
+
ArgonDebug.log('事件监听器已清理');
- } catch(e) {
+ } catch (e) {
ArgonDebug.warn('清理事件监听器失败:', e);
}
}
@@ -3020,14 +3030,14 @@ function cleanupEventListeners() {
*/
function cleanupPjaxResources() {
ArgonDebug.log('开始清理 PJAX 资源...');
-
+
// 按顺序清理各类资源
cleanupLazyloadObserver();
cleanupZoomifyInstances();
- cleanupTippyInstances(); cleanupDynamicStyles();
+ cleanupTippyInstances(); cleanupDynamicStyles();
cleanupDynamicScripts();
cleanupEventListeners();
-
+
ArgonDebug.log('PJAX 资源清理完成');
}
@@ -3042,21 +3052,21 @@ function resetGT4Captcha() {
// 重置前端状态,避免重复提交阻塞
window.geetestVerified = false;
window.geetestAutoSubmitting = false;
-
+
// 清空隐藏字段,防止残留导致pass_token 复用
$('#geetest_lot_number').val('');
$('#geetest_captcha_output').val('');
$('#geetest_pass_token').val('');
$('#geetest_gen_time').val('');
-
+
// 清空容器,防止重复appendTo 导致多个实例
$('#geetest-captcha').empty();
-
+
// 若页面脚本已提供初始化方法,则调用以加载验证码
if (typeof initGeetestCaptcha === 'function') {
initGeetestCaptcha();
} else if (typeof loadGeetestScript === 'function' && typeof initGeetestCaptchaCore === 'function') {
- loadGeetestScript(function() {
+ loadGeetestScript(function () {
initGeetestCaptchaCore();
});
}
@@ -3098,24 +3108,24 @@ function executeScript(oldScript) {
try {
// 创建新的 script 元素
const newScript = document.createElement('script');
-
+
// 复制脚本内容
if (oldScript.textContent) {
newScript.textContent = oldScript.textContent;
}
-
+
// 复制所有属性(包括 type, async, defer 等)
// 需求 4.5: 尊重 async 和 defer 属性的执行时机
Array.from(oldScript.attributes).forEach(attr => {
newScript.setAttribute(attr.name, attr.value);
});
-
+
// 将脚本添加到 head 并立即执行
document.head.appendChild(newScript);
-
+
// 执行后立即移除,避免污染 DOM
document.head.removeChild(newScript);
-
+
ArgonDebug.log('Script executed successfully:', oldScript.textContent.substring(0, 50) + '...');
return true;
} catch (error) {
@@ -3141,20 +3151,20 @@ function executeInlineScripts(container) {
if (!container) {
container = document;
}
-
+
// 需求 4.1: 提取所有 script 标签
const scripts = container.querySelectorAll('script');
-
+
if (scripts.length === 0) {
ArgonDebug.log('No scripts found in new page');
- return {total: 0, success: 0, failed: 0};
+ return { total: 0, success: 0, failed: 0 };
}
-
+
let successCount = 0;
let failedCount = 0;
-
+
ArgonDebug.log(`Found ${scripts.length} script tags in new page`);
-
+
// 需求 4.3: 按照脚本在 DOM 中的顺序执行
scripts.forEach((script, index) => {
if (script.getAttribute('data-pjax-executed') === 'true') {
@@ -3167,9 +3177,9 @@ function executeInlineScripts(container) {
ArgonDebug.log(`Script ${index + 1}: Empty, skipped`);
return;
}
-
+
ArgonDebug.log(`Executing inline script ${index + 1}/${scripts.length}`);
-
+
// 需求 4.4: 错误隔离 - 单个脚本失败不影响其他脚本
const success = executeScript(script);
if (success) {
@@ -3183,19 +3193,19 @@ function executeInlineScripts(container) {
ArgonDebug.log(`Script ${index + 1}: External (${script.src}), skipped`);
}
});
-
+
const result = {
total: scripts.length,
success: successCount,
failed: failedCount
};
-
+
ArgonDebug.log('Script execution completed:', result);
return result;
}
var pjaxContainerSelectors = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#rightbar', '#wpadminbar'];
-var pjaxContainers = pjaxContainerSelectors.filter(function(selector) {
+var pjaxContainers = pjaxContainerSelectors.filter(function (selector) {
return document.querySelector(selector);
});
@@ -3206,7 +3216,7 @@ var pjaxContainers = pjaxContainerSelectors.filter(function(selector) {
/**
* 页面加载管理器 - 提供智能加载动画和进度追踪
*/
-const PageLoader = (function() {
+const PageLoader = (function () {
// 配置常量
const CONFIG = {
OVERLAY_ID: 'page-loader',
@@ -3216,7 +3226,7 @@ const PageLoader = (function() {
PROGRESS_INTERVAL: 200, // 进度更新间隔
SKELETON_DELAY: 150 // 骨架屏延迟显示
};
-
+
// 状态管理
let state = {
element: null,
@@ -3227,7 +3237,7 @@ const PageLoader = (function() {
hideTimer: null,
skeletonTimer: null
};
-
+
/**
* 创建加载动画 HTML
*/
@@ -3268,7 +3278,7 @@ const PageLoader = (function() {
`;
}
-
+
/**
* 创建加载器元素
*/
@@ -3279,7 +3289,7 @@ const PageLoader = (function() {
el.innerHTML = createHTML();
return el;
}
-
+
/**
* 获取或创建元素
*/
@@ -3293,34 +3303,34 @@ const PageLoader = (function() {
}
return state.element;
}
-
+
/**
* 更新进度环
*/
function updateProgress(progress) {
const el = state.element;
if (!el) return;
-
+
const circle = el.querySelector('.loader-ring-progress');
if (circle) {
const circumference = 2 * Math.PI * 45;
const offset = circumference - (progress / 100) * circumference;
circle.style.strokeDashoffset = offset;
}
-
+
state.progress = progress;
}
-
+
/**
* 自动递增进度
*/
function startProgressAnimation() {
stopProgressAnimation();
-
+
state.progress = 0;
updateProgress(0);
-
- state.progressTimer = setInterval(function() {
+
+ state.progressTimer = setInterval(function () {
if (state.progress < 90) {
// 使用缓动函数,越接近 90% 越慢
const increment = CONFIG.PROGRESS_STEP * (1 - state.progress / 100);
@@ -3329,7 +3339,7 @@ const PageLoader = (function() {
}
}, CONFIG.PROGRESS_INTERVAL);
}
-
+
/**
* 停止进度动画
*/
@@ -3339,7 +3349,7 @@ const PageLoader = (function() {
state.progressTimer = null;
}
}
-
+
/**
* 完成进度到 100%
*/
@@ -3347,7 +3357,7 @@ const PageLoader = (function() {
stopProgressAnimation();
updateProgress(100);
}
-
+
/**
* 显示加载器
*/
@@ -3361,57 +3371,57 @@ const PageLoader = (function() {
clearTimeout(state.skeletonTimer);
state.skeletonTimer = null;
}
-
+
const el = getElement();
state.startTime = Date.now();
state.isVisible = true;
-
+
// 移除隐藏类,添加显示类
el.classList.remove('is-hiding');
void el.offsetWidth; // 强制重排
el.classList.add('is-visible');
-
+
// 启动进度动画
startProgressAnimation();
-
+
// 延迟显示骨架屏(避免快速加载时闪烁)
- state.skeletonTimer = setTimeout(function() {
+ state.skeletonTimer = setTimeout(function () {
if (state.isVisible && el) {
el.classList.add('show-skeleton');
}
}, CONFIG.SKELETON_DELAY);
}
-
+
/**
* 隐藏加载器
*/
function hide() {
if (!state.isVisible) return;
-
+
const el = state.element;
if (!el) return;
-
+
// 完成进度
completeProgress();
-
+
// 计算已显示时间
const elapsedTime = Date.now() - state.startTime;
const remainingTime = Math.max(0, CONFIG.MIN_DISPLAY_TIME - elapsedTime);
-
+
// 确保最小显示时间后再隐藏
- state.hideTimer = setTimeout(function() {
+ state.hideTimer = setTimeout(function () {
el.classList.add('is-hiding');
el.classList.remove('show-skeleton');
-
+
// 动画结束后清理
- setTimeout(function() {
+ setTimeout(function () {
el.classList.remove('is-visible', 'is-hiding');
state.isVisible = false;
stopProgressAnimation();
}, CONFIG.FADE_DURATION);
}, remainingTime);
}
-
+
/**
* 设置进度(手动控制)
*/
@@ -3420,13 +3430,13 @@ const PageLoader = (function() {
stopProgressAnimation();
updateProgress(progress);
}
-
+
/**
* 销毁加载器
*/
function destroy() {
stopProgressAnimation();
-
+
if (state.hideTimer) {
clearTimeout(state.hideTimer);
state.hideTimer = null;
@@ -3435,15 +3445,15 @@ const PageLoader = (function() {
clearTimeout(state.skeletonTimer);
state.skeletonTimer = null;
}
-
+
if (state.element && state.element.parentNode) {
state.element.parentNode.removeChild(state.element);
}
-
+
state.element = null;
state.isVisible = false;
}
-
+
// 公开 API
return {
show: show,
@@ -3465,20 +3475,20 @@ function hideLoadingOverlay() {
}
function startPageTransition() {
document.documentElement.classList.add('page-transition-enter');
- pjaxContainers.forEach(function(selector) {
+ pjaxContainers.forEach(function (selector) {
var c = document.querySelector(selector);
if (c) c.classList.add('page-transition-content');
});
}
function activatePageTransition() {
- requestAnimationFrame(function() {
+ requestAnimationFrame(function () {
document.documentElement.classList.add('page-transition-active');
});
}
function endPageTransition() {
document.documentElement.classList.remove('page-transition-active');
document.documentElement.classList.remove('page-transition-enter');
- pjaxContainers.forEach(function(selector) {
+ pjaxContainers.forEach(function (selector) {
var c = document.querySelector(selector);
if (c) c.classList.remove('page-transition-content');
});
@@ -3501,151 +3511,151 @@ $.pjax.defaults.fragment = pjaxContainers;
* - pjax:end: 需求 1.7 (特定任务处理)
*/
if (argonConfig.disable_pjax != true && argonConfig.disable_pjax != 'true') {
-$(document).pjax(
- "a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):not([download]):not(.reference-link):not(.reference-list-backlink):not([href^='#'])",
- pjaxContainers.length ? pjaxContainers[0] : '#primary',
- { fragment: (pjaxContainers.length ? pjaxContainers : ['#primary']), timeout: $.pjax.defaults.timeout }
-)
-.on('pjax:click', function(e, f, g){
- NProgress.remove();
- NProgress.start();
- pjaxLoading = true;
- showLoadingOverlay();
-}).on('pjax:afterGetContainers', function(e, f, g) {
- pjaxScrollTop = 0;
- if ($("html").hasClass("banner-as-cover")){
- if (g.is(".page-link")){
- pjaxScrollTop = $("#content").offset().top - 80;
- }
- }
-}).on('pjax:send', function() {
- NProgress.set(0.618);
- startPageTransition();
-}).on('pjax:beforeReplace', function(e, dom) {
- // ========== 需求 1.1-1.4: 清理旧页面的所有资源 ==========
- // 调用统一的资源清理管理器
- // 清理内容:Lazyload Observer、Zoomify、Tippy 实例、动态标签
- cleanupPjaxResources();
-
- // 更新 UI 状态
- if ($("#post_comment", dom[0]).length > 0){
- $("#fabtn_go_to_comment").removeClass("d-none");
- }else{
- $("#fabtn_go_to_comment").addClass("d-none");
- }
-
- // 处理滚动位置
- if ($("html").hasClass("banner-as-cover")){
- if (!$("#main").hasClass("article-list-home")){
+ $(document).pjax(
+ "a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):not([download]):not(.reference-link):not(.reference-list-backlink):not([href^='#'])",
+ pjaxContainers.length ? pjaxContainers[0] : '#primary',
+ { fragment: (pjaxContainers.length ? pjaxContainers : ['#primary']), timeout: $.pjax.defaults.timeout }
+ )
+ .on('pjax:click', function (e, f, g) {
+ NProgress.remove();
+ NProgress.start();
+ pjaxLoading = true;
+ showLoadingOverlay();
+ }).on('pjax:afterGetContainers', function (e, f, g) {
pjaxScrollTop = 0;
- }
- }
-}).on('pjax:complete', function() {
- // ========== 需求 1.5, 1.6: 重新初始化所有功能模块 ==========
- pjaxLoading = false;
- NProgress.inc();
- startPageTransition();
- activatePageTransition();
- setTimeout(function() {
- hideLoadingOverlay();
- endPageTransition();
- }, 320);
-
- // ========== 需求 4.1-4.5: 执行新页面中的内联脚本 ==========
- try {
- pjaxContainers.forEach(function(selector) {
- var container = document.querySelector(selector);
- if (container) {
- executeInlineScripts(container);
+ if ($("html").hasClass("banner-as-cover")) {
+ if (g.is(".page-link")) {
+ pjaxScrollTop = $("#content").offset().top - 80;
+ }
}
+ }).on('pjax:send', function () {
+ NProgress.set(0.618);
+ startPageTransition();
+ }).on('pjax:beforeReplace', function (e, dom) {
+ // ========== 需求 1.1-1.4: 清理旧页面的所有资源 ==========
+ // 调用统一的资源清理管理器
+ // 清理内容:Lazyload Observer、Zoomify、Tippy 实例、动态标签
+ cleanupPjaxResources();
+
+ // 更新 UI 状态
+ if ($("#post_comment", dom[0]).length > 0) {
+ $("#fabtn_go_to_comment").removeClass("d-none");
+ } else {
+ $("#fabtn_go_to_comment").addClass("d-none");
+ }
+
+ // 处理滚动位置
+ if ($("html").hasClass("banner-as-cover")) {
+ if (!$("#main").hasClass("article-list-home")) {
+ pjaxScrollTop = 0;
+ }
+ }
+ }).on('pjax:complete', function () {
+ // ========== 需求 1.5, 1.6: 重新初始化所有功能模块 ==========
+ pjaxLoading = false;
+ NProgress.inc();
+ startPageTransition();
+ activatePageTransition();
+ setTimeout(function () {
+ hideLoadingOverlay();
+ endPageTransition();
+ }, 320);
+
+ // ========== 需求 4.1-4.5: 执行新页面中的内联脚本 ==========
+ try {
+ pjaxContainers.forEach(function (selector) {
+ var container = document.querySelector(selector);
+ if (container) {
+ executeInlineScripts(container);
+ }
+ });
+ } catch (err) {
+ ArgonDebug.error('executeInlineScripts failed:', err);
+ }
+
+ // MathJax 数学公式渲染
+ try {
+ if (MathJax != undefined) {
+ if (MathJax.Hub != undefined) {
+ MathJax.Hub.Typeset();
+ } else {
+ MathJax.typeset();
+ }
+ }
+ } catch (err) { }
+
+ // KaTeX 数学公式渲染
+ try {
+ if (renderMathInElement != undefined) {
+ renderMathInElement(document.body, {
+ delimiters: [
+ { left: "$$", right: "$$", display: true },
+ { left: "$", right: "$", display: false },
+ { left: "\\(", right: "\\)", display: false }
+ ]
+ });
+ }
+ } catch (err) { }
+
+ // 初始化各个功能模块(添加错误处理确保单个模块失败不影响其他模块)
+ try { waterflowInit(); } catch (err) { ArgonDebug.error('waterflowInit failed:', err); }
+ try { lazyloadInit(); } catch (err) { ArgonDebug.error('lazyloadInit failed:', err); }
+ try { zoomifyInit(); } catch (err) { ArgonDebug.error('zoomifyInit failed:', err); }
+ try { highlightJsRender(); } catch (err) { ArgonDebug.error('highlightJsRender failed:', err); }
+ try { panguInit(); } catch (err) { ArgonDebug.error('panguInit failed:', err); }
+ try { clampInit(); } catch (err) { ArgonDebug.error('clampInit failed:', err); }
+ try { tippyInit(); } catch (err) { ArgonDebug.error('tippyInit failed:', err); }
+ try { getGithubInfoCardContent(); } catch (err) { ArgonDebug.error('getGithubInfoCardContent failed:', err); }
+ try { showPostOutdateToast(); } catch (err) { ArgonDebug.error('showPostOutdateToast failed:', err); }
+ try { calcHumanTimesOnPage(); } catch (err) { ArgonDebug.error('calcHumanTimesOnPage failed:', err); }
+ try { foldLongComments(); } catch (err) { ArgonDebug.error('foldLongComments failed:', err); }
+ try { foldLongShuoshuo(); } catch (err) { ArgonDebug.error('foldLongShuoshuo failed:', err); }
+ try { handleHashNavigation(); } catch (err) { ArgonDebug.error('handleHashNavigation failed:', err); }
+
+ $("html").trigger("resize");
+
+ // 恢复滚动位置
+ if (pjaxScrollTop > 0) {
+ $("body,html").scrollTop(pjaxScrollTop);
+ pjaxScrollTop = 0;
+ }
+
+ // 调用用户自定义的 PJAX 加载完成回调
+ if (typeof (window.pjaxLoaded) == "function") {
+ try {
+ window.pjaxLoaded();
+ } catch (err) {
+ ArgonDebug.error(err);
+ }
+ }
+
+ NProgress.done();
+ }).on('pjax:error', function () {
+ hideLoadingOverlay();
+ endPageTransition();
+ pjaxLoading = false;
+ }).on('pjax:end', function () {
+ // ========== 需求 1.7: 执行特定任务 ==========
+
+ // 重置移动端目录状态
+ if (typeof window.resetMobileCatalog === 'function') {
+ try {
+ window.resetMobileCatalog();
+ } catch (err) {
+ ArgonDebug.warn('resetMobileCatalog failed:', err);
+ }
+ }
+
+ // GT4: PJAX 后确保评论页验证码已初始化
+ resetGT4Captcha();
});
- } catch (err) {
- ArgonDebug.error('executeInlineScripts failed:', err);
- }
-
- // MathJax 数学公式渲染
- try{
- if (MathJax != undefined){
- if (MathJax.Hub != undefined){
- MathJax.Hub.Typeset();
- }else{
- MathJax.typeset();
- }
- }
- }catch (err){}
-
- // KaTeX 数学公式渲染
- try{
- if (renderMathInElement != undefined){
- renderMathInElement(document.body,{
- delimiters: [
- {left: "$$", right: "$$", display: true},
- {left: "$", right: "$", display: false},
- {left: "\\(", right: "\\)", display: false}
- ]
- });
- }
- }catch (err){}
-
- // 初始化各个功能模块(添加错误处理确保单个模块失败不影响其他模块)
- try { waterflowInit(); } catch (err) { ArgonDebug.error('waterflowInit failed:', err); }
- try { lazyloadInit(); } catch (err) { ArgonDebug.error('lazyloadInit failed:', err); }
- try { zoomifyInit(); } catch (err) { ArgonDebug.error('zoomifyInit failed:', err); }
- try { highlightJsRender(); } catch (err) { ArgonDebug.error('highlightJsRender failed:', err); }
- try { panguInit(); } catch (err) { ArgonDebug.error('panguInit failed:', err); }
- try { clampInit(); } catch (err) { ArgonDebug.error('clampInit failed:', err); }
- try { tippyInit(); } catch (err) { ArgonDebug.error('tippyInit failed:', err); }
- try { getGithubInfoCardContent(); } catch (err) { ArgonDebug.error('getGithubInfoCardContent failed:', err); }
- try { showPostOutdateToast(); } catch (err) { ArgonDebug.error('showPostOutdateToast failed:', err); }
- try { calcHumanTimesOnPage(); } catch (err) { ArgonDebug.error('calcHumanTimesOnPage failed:', err); }
- try { foldLongComments(); } catch (err) { ArgonDebug.error('foldLongComments failed:', err); }
- try { foldLongShuoshuo(); } catch (err) { ArgonDebug.error('foldLongShuoshuo failed:', err); }
- try { handleHashNavigation(); } catch (err) { ArgonDebug.error('handleHashNavigation failed:', err); }
-
- $("html").trigger("resize");
-
- // 恢复滚动位置
- if (pjaxScrollTop > 0) {
- $("body,html").scrollTop(pjaxScrollTop);
- pjaxScrollTop = 0;
- }
-
- // 调用用户自定义的 PJAX 加载完成回调
- if (typeof(window.pjaxLoaded) == "function"){
- try{
- window.pjaxLoaded();
- }catch (err){
- ArgonDebug.error(err);
- }
- }
-
- NProgress.done();
-}).on('pjax:error', function() {
- hideLoadingOverlay();
- endPageTransition();
- pjaxLoading = false;
-}).on('pjax:end', function() {
- // ========== 需求 1.7: 执行特定任务 ==========
-
- // 重置移动端目录状态
- if (typeof window.resetMobileCatalog === 'function') {
- try {
- window.resetMobileCatalog();
- } catch (err) {
- ArgonDebug.warn('resetMobileCatalog failed:', err);
- }
- }
-
- // GT4: PJAX 后确保评论页验证码已初始化
- resetGT4Captcha();
-});
}
-window.addEventListener('hashchange', function() {
+window.addEventListener('hashchange', function () {
handleHashNavigation();
});
if (document.readyState === 'loading') {
- document.addEventListener('DOMContentLoaded', function() {
+ document.addEventListener('DOMContentLoaded', function () {
handleHashNavigation();
});
} else {
@@ -3653,10 +3663,10 @@ if (document.readyState === 'loading') {
}
/*Reference 跳转*/
-$(document).on("click", ".reference-link , .reference-list-backlink" , function(e){
+$(document).on("click", ".reference-link , .reference-list-backlink", function (e) {
e.preventDefault();
var href = $(this).attr("href");
- if (!href || href === "#" ) { return; }
+ if (!href || href === "#") { return; }
var $target;
try {
$target = $(href);
@@ -3666,31 +3676,31 @@ $(document).on("click", ".reference-link , .reference-list-backlink" , function(
$("body,html").animate({
scrollTop: $target.offset().top - document.body.clientHeight / 2 - 75
}, 500, 'easeOutExpo')
- setTimeout(function(){
- if ($target.is("li")){
+ setTimeout(function () {
+ if ($target.is("li")) {
$(".space", $target).focus();
- }else{
+ } else {
$target.focus();
}
}, 1);
});
/*Tags Dialog pjax 加载后自动关闭 */
-$(document).on("click" , "#blog_tags .tag" , function(){
+$(document).on("click", "#blog_tags .tag", function () {
$("#blog_tags button.close").trigger("click");
});
-$(document).on("click" , "#blog_categories .tag" , function(){
+$(document).on("click", "#blog_categories .tag", function () {
$("#blog_categories button.close").trigger("click");
});
/*侧栏 & 顶栏菜单手机适配*/
-!function(){
- $(document).on("click" , "#fabtn_open_sidebar, #open_sidebar" , function(){
+!function () {
+ $(document).on("click", "#fabtn_open_sidebar, #open_sidebar", function () {
$("html").addClass("leftbar-opened");
// 侧边栏打开时初始化移动端文章目录
initMobileCatalog();
// 如果有文章目录,默认展开
- setTimeout(function() {
+ setTimeout(function () {
var catalogSection = $("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section");
if (catalogSection.length > 0 && !catalogSection.hasClass("expanded")) {
catalogSection.addClass("expanded");
@@ -3699,28 +3709,28 @@ $(document).on("click" , "#blog_categories .tag" , function(){
}
}, 100);
});
- $(document).on("click" , "#sidebar_mask, #leftbar_close_btn" , function(){
+ $(document).on("click", "#sidebar_mask, #leftbar_close_btn", function () {
$("html").removeClass("leftbar-opened");
// 关闭侧边栏时折叠所有面板
$(".leftbar-mobile-collapse-section.expanded").removeClass("expanded");
});
- $(document).on("click" , "#leftbar a[href]:not([no-pjax]):not([href^='#']):not(.has-submenu)" , function(){
+ $(document).on("click", "#leftbar a[href]:not([no-pjax]):not([href^='#']):not(.has-submenu)", function () {
$("html").removeClass("leftbar-opened");
// 关闭侧边栏时折叠所有面板
$(".leftbar-mobile-collapse-section.expanded").removeClass("expanded");
});
// 移动端子菜单展开/收起
- $(document).on("click" , ".leftbar-mobile-menu-item.has-children > a.has-submenu" , function(e){
+ $(document).on("click", ".leftbar-mobile-menu-item.has-children > a.has-submenu", function (e) {
e.preventDefault();
$(this).parent().toggleClass("expanded");
});
// 移动端侧边栏搜索
- $(document).on("keydown" , "#leftbar_mobile_search_input" , function(e){
- if (e.keyCode != 13){
+ $(document).on("keydown", "#leftbar_mobile_search_input", function (e) {
+ if (e.keyCode != 13) {
return;
}
let word = $(this).val();
- if (word == ""){
+ if (word == "") {
return;
}
$("html").removeClass("leftbar-opened");
@@ -3728,64 +3738,64 @@ $(document).on("click" , "#blog_categories .tag" , function(){
$(".leftbar-mobile-collapse-section.expanded").removeClass("expanded");
searchPosts(word);
});
- $(document).on("click" , "#navbar_global.show .navbar-nav a[href]:not([no-pjax]):not([href^='#'])" , function(){
+ $(document).on("click", "#navbar_global.show .navbar-nav a[href]:not([no-pjax]):not([href^='#'])", function () {
$("#navbar_global .navbar-toggler").click();
});
- $(document).on("click" , "#navbar_global.show #navbar_search_btn_mobile" , function(){
+ $(document).on("click", "#navbar_global.show #navbar_search_btn_mobile", function () {
$("#navbar_global .navbar-toggler").click();
});
-
+
// ========== 移动端折叠面板交互==========
- $(document).on("click", ".leftbar-mobile-collapse-header", function(e) {
+ $(document).on("click", ".leftbar-mobile-collapse-header", function (e) {
var section = $(this).closest(".leftbar-mobile-collapse-section");
var header = $(this);
var isExpanded = section.hasClass("expanded");
-
+
// 切换展开状态
section.toggleClass("expanded");
-
+
// 如果是文章目录面板展开,初始化目录并滚动到当前位置
if (!isExpanded && header.attr("id") === "mobile_catalog_toggle") {
initMobileCatalog();
setTimeout(scrollMobileCatalogToActive, 100);
}
});
-
+
// ========== 移动端文章目录初始化 ==========
window.mobileCatalogInitialized = false;
-
+
function initMobileCatalog() {
if (window.mobileCatalogInitialized) return;
var $mobileContainer = $("#leftbar_mobile_catalog");
var $postContent = $("#post_content");
if ($mobileContainer.length === 0) return;
if ($postContent.length === 0) return;
-
+
// 直接生成目录,不依赖 headIndex 插件
var $headers = $postContent.find('h1, h2, h3, h4, h5, h6');
if ($headers.length === 0) {
$mobileContainer.html('暂无目录
');
return;
}
-
+
// 构建目录树
var toc = [];
var stack = [{ level: 0, children: toc }];
-
- $headers.each(function(index) {
+
+ $headers.each(function (index) {
var $h = $(this);
var level = parseInt(this.tagName.charAt(1));
var text = $h.text().trim();
var id = $h.attr('id');
-
+
// 确保标题有ID
if (!id) {
id = 'mobile-heading-' + index;
$h.attr('id', id);
}
-
+
var item = { id: id, text: text, level: level, children: [] };
-
+
// 找到合适的父级
while (stack.length > 1 && stack[stack.length - 1].level >= level) {
stack.pop();
@@ -3793,7 +3803,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
stack[stack.length - 1].children.push(item);
stack.push({ level: level, children: item.children });
});
-
+
// 递归生成 HTML
function buildHtml(items, isRoot) {
if (!items || items.length === 0) return '';
@@ -3810,12 +3820,12 @@ $(document).on("click" , "#blog_categories .tag" , function(){
html += '';
return html;
}
-
+
$mobileContainer.html(buildHtml(toc, true));
window.mobileCatalogInitialized = true;
-
+
// 绑定点击事件
- $mobileContainer.off('click.mobileCatalog').on('click.mobileCatalog', '.index-link', function(e) {
+ $mobileContainer.off('click.mobileCatalog').on('click.mobileCatalog', '.index-link', function (e) {
e.preventDefault();
var targetId = $(this).attr('href');
if (targetId) {
@@ -3827,7 +3837,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
scrollTop: $target.offset().top - 80
}, 500, 'easeOutExpo');
// 点击后关闭侧边栏
- setTimeout(function() {
+ setTimeout(function () {
$("html").removeClass("leftbar-opened");
// 关闭侧边栏时折叠所有面板
$(".leftbar-mobile-collapse-section.expanded").removeClass("expanded");
@@ -3835,42 +3845,42 @@ $(document).on("click" , "#blog_categories .tag" , function(){
}
}
});
-
+
// 初始化高亮并启动滚动监听
updateMobileCatalogHighlight();
setTimeout(scrollMobileCatalogToActive, 150);
}
-
+
// 更新移动端目录高亮
function updateMobileCatalogHighlight() {
var $mobileContainer = $("#leftbar_mobile_catalog");
var $postContent = $("#post_content");
if ($mobileContainer.length === 0 || $postContent.length === 0) return;
-
+
var scrollTop = $(window).scrollTop();
var $headers = $postContent.find('h1, h2, h3, h4, h5, h6');
var currentId = null;
-
- $headers.each(function() {
+
+ $headers.each(function () {
var $h = $(this);
var top = $h.offset().top - 100;
if (scrollTop >= top) {
currentId = $h.attr('id');
}
});
-
+
if (currentId) {
$mobileContainer.find('.index-item').removeClass('current');
$mobileContainer.find('.index-link[href="#' + currentId + '"]').closest('.index-item').addClass('current');
}
}
-
+
// 重置移动端目录状态(由PJAX 调用)
- window.resetMobileCatalog = function() {
+ window.resetMobileCatalog = function () {
window.mobileCatalogInitialized = false;
$("#leftbar_mobile_catalog").empty();
};
-
+
// 滚动目录到当前激活项
function scrollMobileCatalogToActive() {
var container = $("#leftbar_mobile_catalog");
@@ -3886,27 +3896,28 @@ $(document).on("click" , "#blog_categories .tag" , function(){
}, 300, 'easeOutCubic');
}
}
-
+
// 监听页面滚动,实时更新移动端目录高亮并自动滚动
- var mobileCatalogScrollTimer = null;
- $(window).on("scroll.mobileCatalog", function() {
+ var mobileCatalogScrollTicking = false;
+ $(window).on("scroll.mobileCatalog", function () {
if (!window.mobileCatalogInitialized) return;
- // 节流处理
- if (mobileCatalogScrollTimer) return;
- mobileCatalogScrollTimer = setTimeout(function() {
- mobileCatalogScrollTimer = null;
+ // 使用 rAF 实现实时更新,无延迟
+ if (mobileCatalogScrollTicking) return;
+ mobileCatalogScrollTicking = true;
+ requestAnimationFrame(function () {
+ mobileCatalogScrollTicking = false;
// 更新高亮状态
updateMobileCatalogHighlight();
// 只在侧边栏打开且目录展开时滚动
- if ($("html").hasClass("leftbar-opened") &&
+ if ($("html").hasClass("leftbar-opened") &&
$("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section").hasClass("expanded")) {
scrollMobileCatalogToActive();
}
- }, 150);
+ });
});
-
+
// 点击目录项后关闭侧边栏(已在 initMobileCatalog 中处理)
-
+
// ========== 移动端TODO交互 ==========
function updateMobileTodoCount() {
var count = $("#mobile-todo-list .mobile-todo-item:not(.todo-completed)").length;
@@ -3914,7 +3925,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
$("#mobile_todo_count").text(count);
// 同步更新桌面端计数
$(".todo-count").text(count);
-
+
// 更新分隔栏的已完成数量
var divider = $("#mobile-todo-collapse-btn");
if (divider.length) {
@@ -3926,14 +3937,14 @@ $(document).on("click" , "#blog_categories .tag" , function(){
}
}
}
-
+
// 移动端折叠/展开已完成任务
- $(document).on("click", "#mobile-todo-collapse-btn", function(e) {
+ $(document).on("click", "#mobile-todo-collapse-btn", function (e) {
e.stopPropagation();
var btn = $(this);
var completedItems = $("#mobile-todo-list .mobile-todo-item.todo-completed");
var isCollapsed = btn.hasClass("collapsed");
-
+
if (isCollapsed) {
// 展开
btn.removeClass("collapsed");
@@ -3944,28 +3955,28 @@ $(document).on("click" , "#blog_categories .tag" , function(){
completedItems.addClass("collapsed");
}
});
-
+
// 添加TODO
- $(document).on("click", "#mobile-todo-add-btn", function() {
+ $(document).on("click", "#mobile-todo-add-btn", function () {
addMobileTodo();
});
-
- $(document).on("keypress", "#mobile-todo-input", function(e) {
+
+ $(document).on("keypress", "#mobile-todo-input", function (e) {
if (e.key === "Enter") {
addMobileTodo();
}
});
-
+
function addMobileTodo() {
if (!window.mobileTodoConfig) return;
-
+
var input = $("#mobile-todo-input");
var content = input.val().trim();
if (!content) return;
-
+
var btn = $("#mobile-todo-add-btn");
btn.prop("disabled", true);
-
+
$.ajax({
url: window.mobileTodoConfig.ajaxUrl,
type: "POST",
@@ -3974,43 +3985,43 @@ $(document).on("click" , "#blog_categories .tag" , function(){
nonce: window.mobileTodoConfig.nonce,
content: content
},
- success: function(res) {
+ success: function (res) {
if (res.success) {
var list = $("#mobile-todo-list");
list.find(".mobile-todo-empty").remove();
-
+
var newItem = $('' +
'' + $("").text(content).html() + '' +
'
' +
'');
list.prepend(newItem);
-
+
input.val("");
updateMobileTodoCount();
-
+
// 同步到桌面端
syncTodoToDesktop(res.data.id, content, "add");
}
btn.prop("disabled", false);
},
- error: function() {
+ error: function () {
btn.prop("disabled", false);
}
});
}
-
+
// 移动端TODO 验证码相关变量
var mobilePendingUrgeBtn = null;
var mobileGeetestCaptchaObj = null;
-
+
// 完成/删除/催促TODO
- $(document).on("click", "#mobile-todo-list .mobile-todo-complete-btn, #mobile-todo-list .mobile-todo-delete-btn, #mobile-todo-list .mobile-todo-urge-btn", function() {
+ $(document).on("click", "#mobile-todo-list .mobile-todo-complete-btn, #mobile-todo-list .mobile-todo-delete-btn, #mobile-todo-list .mobile-todo-urge-btn", function () {
if (!window.mobileTodoConfig) return;
-
+
var btn = $(this);
var item = btn.closest(".mobile-todo-item");
var id = item.data("id");
-
+
if (btn.hasClass("mobile-todo-complete-btn")) {
btn.prop("disabled", true);
$.ajax({
@@ -4021,7 +4032,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
nonce: window.mobileTodoConfig.nonce,
id: id
},
- success: function(res) {
+ success: function (res) {
if (res.success) {
item.addClass("todo-completed");
btn.replaceWith('
');
@@ -4042,10 +4053,10 @@ $(document).on("click" , "#blog_categories .tag" , function(){
nonce: window.mobileTodoConfig.nonce,
id: id
},
- success: function(res) {
+ success: function (res) {
if (res.success) {
item.addClass("todo-completing");
- setTimeout(function() {
+ setTimeout(function () {
item.remove();
updateMobileTodoCount();
if ($("#mobile-todo-list .mobile-todo-item").length === 0) {
@@ -4063,24 +4074,24 @@ $(document).on("click" , "#blog_categories .tag" , function(){
if (captchaContainer.length > 0) {
captchaContainer.slideDown(200);
mobilePendingUrgeBtn = btn;
-
+
if (window.mobileTodoConfig.captchaType === 'geetest') {
// 极验验证码
if (!mobileGeetestCaptchaObj && typeof initGeetest4 === 'function') {
initGeetest4({
captchaId: window.mobileTodoConfig.geetestId,
product: 'bind'
- }, function(captcha) {
+ }, function (captcha) {
mobileGeetestCaptchaObj = captcha;
- captcha.onReady(function() {
+ captcha.onReady(function () {
captcha.showCaptcha();
- }).onSuccess(function() {
+ }).onSuccess(function () {
var result = captcha.getValidate();
if (result && mobilePendingUrgeBtn) {
var urgeId = mobilePendingUrgeBtn.closest(".mobile-todo-item").data("id");
doMobileUrgeGeetest(mobilePendingUrgeBtn, urgeId, result);
}
- }).onError(function() {
+ }).onError(function () {
captchaContainer.slideUp(200);
mobilePendingUrgeBtn = null;
});
@@ -4095,39 +4106,39 @@ $(document).on("click" , "#blog_categories .tag" , function(){
return;
}
}
-
+
// 不需要验证码,直接催促
doMobileUrge(btn, id, "");
}
});
-
+
// 移动端数学验证码提交
- $(document).on("click", "#mobile-todo-captcha-submit", function() {
+ $(document).on("click", "#mobile-todo-captcha-submit", function () {
if (!mobilePendingUrgeBtn) return;
-
+
var captchaInput = $("#mobile-todo-captcha-input");
var captchaValue = captchaInput.val().trim();
-
+
if (!captchaValue) {
captchaInput.focus();
return;
}
-
+
var id = mobilePendingUrgeBtn.closest(".mobile-todo-item").data("id");
doMobileUrge(mobilePendingUrgeBtn, id, captchaValue);
});
-
+
// 移动端验证码回车提交
- $(document).on("keypress", "#mobile-todo-captcha-input", function(e) {
+ $(document).on("keypress", "#mobile-todo-captcha-input", function (e) {
if (e.key === "Enter") {
$("#mobile-todo-captcha-submit").click();
}
});
-
+
// 执行移动端催促
function doMobileUrge(btn, id, captcha) {
btn.prop("disabled", true).html('
');
-
+
$.ajax({
url: window.mobileTodoConfig.ajaxUrl,
type: "POST",
@@ -4137,19 +4148,19 @@ $(document).on("click" , "#blog_categories .tag" , function(){
id: id,
comment_captcha: captcha
},
- success: function(res) {
+ success: function (res) {
handleMobileUrgeResponse(btn, res);
},
- error: function() {
+ error: function () {
btn.prop("disabled", false).html('
');
}
});
}
-
+
// 极验验证码催促
function doMobileUrgeGeetest(btn, id, geetestResult) {
btn.prop("disabled", true).html('
');
-
+
$.ajax({
url: window.mobileTodoConfig.ajaxUrl,
type: "POST",
@@ -4162,34 +4173,34 @@ $(document).on("click" , "#blog_categories .tag" , function(){
pass_token: geetestResult.pass_token,
gen_time: geetestResult.gen_time
},
- success: function(res) {
+ success: function (res) {
handleMobileUrgeResponse(btn, res);
if (mobileGeetestCaptchaObj) mobileGeetestCaptchaObj.reset();
},
- error: function() {
+ error: function () {
btn.prop("disabled", false).html('
');
}
});
}
-
+
// 处理移动端催促响应
function handleMobileUrgeResponse(btn, res) {
var captchaContainer = $(".mobile-todo-captcha-container");
-
+
if (res.success) {
btn.addClass("urged").html('
');
captchaContainer.slideUp(200);
mobilePendingUrgeBtn = null;
-
+
// 更新验证码文本
if (res.data && res.data.captcha) {
$(".mobile-todo-captcha-text").text(res.data.captcha);
}
-
+
// 同步到桌面端
var id = btn.closest(".mobile-todo-item").data("id");
syncTodoToDesktop(id, "", "urge");
-
+
// 显示成功提示
if (typeof iziToast !== 'undefined') {
iziToast.success({
@@ -4201,7 +4212,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
}
} else {
btn.prop("disabled", false).html('
');
-
+
// 显示错误提示
if (typeof iziToast !== 'undefined') {
iziToast.error({
@@ -4211,7 +4222,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){
timeout: 3000
});
}
-
+
// 刷新验证码
if (res.data && res.data.captcha) {
$(".mobile-todo-captcha-text").text(res.data.captcha);
@@ -4219,12 +4230,12 @@ $(document).on("click" , "#blog_categories .tag" , function(){
$("#mobile-todo-captcha-input").val("").focus();
}
}
-
+
// 同步TODO操作到桌面端
function syncTodoToDesktop(id, content, action) {
var desktopList = $("#todo-list");
if (desktopList.length === 0) return;
-
+
if (action === "add") {
desktopList.find(".todo-empty").remove();
var newItem = $('
' +
@@ -4246,51 +4257,51 @@ $(document).on("click" , "#blog_categories .tag" , function(){
}();
/*折叠区块小工具*/
-$(document).on("click" , ".collapse-block .collapse-block-title" , function(){
+$(document).on("click", ".collapse-block .collapse-block-title", function () {
let block = $(this).parent();
$(block).toggleClass("collapsed");
let inner = $(".collapse-block-body", block);
- if (block.hasClass("collapsed")){
+ if (block.hasClass("collapsed")) {
inner.stop(true, false).slideUp(250, 'easeOutCirc');
- }else{
+ } else {
inner.stop(true, false).slideDown(300, 'easeOutCirc');
}
$("html").trigger("scroll");
});
/*获得 Github Repo Shortcode 信息卡内容*/
-function getGithubInfoCardContent(){
- $(".github-info-card").each(function(){
- (function($this){
- if ($this.attr("data-getdata") == "backend"){
- $(".github-info-card-description" , $this).html($this.attr("data-description"));
- $(".github-info-card-stars" , $this).html($this.attr("data-stars"));
- $(".github-info-card-forks" , $this).html($this.attr("data-forks"));
+function getGithubInfoCardContent() {
+ $(".github-info-card").each(function () {
+ (function ($this) {
+ if ($this.attr("data-getdata") == "backend") {
+ $(".github-info-card-description", $this).html($this.attr("data-description"));
+ $(".github-info-card-stars", $this).html($this.attr("data-stars"));
+ $(".github-info-card-forks", $this).html($this.attr("data-forks"));
return;
}
- $(".github-info-card-description" , $this).html("Loading...");
- $(".github-info-card-stars" , $this).html("-");
- $(".github-info-card-forks" , $this).html("-");
+ $(".github-info-card-description", $this).html("Loading...");
+ $(".github-info-card-stars", $this).html("-");
+ $(".github-info-card-forks", $this).html("-");
author = $this.attr("data-author");
project = $this.attr("data-project");
$.ajax({
- url : "https://api.github.com/repos/" + author + "/" + project,
- type : "GET",
- dataType : "json",
- success : function(result){
+ url: "https://api.github.com/repos/" + author + "/" + project,
+ type: "GET",
+ dataType: "json",
+ success: function (result) {
description = result.description;
- if (result.homepage != "" && result.homepage != null){
+ if (result.homepage != "" && result.homepage != null) {
description += " " + result.homepage + ""
}
- $(".github-info-card-description" , $this).html(description);
- $(".github-info-card-stars" , $this).html(result.stargazers_count);
- $(".github-info-card-forks" , $this).html(result.forks_count);
+ $(".github-info-card-description", $this).html(description);
+ $(".github-info-card-stars", $this).html(result.stargazers_count);
+ $(".github-info-card-forks", $this).html(result.forks_count);
},
- error : function(xhr){
- if (xhr.status == 404){
- $(".github-info-card-description" , $this).html(__("找不到该 Repo"));
- }else{
- $(".github-info-card-description" , $this).html(__("获取 Repo 信息失败"));
+ error: function (xhr) {
+ if (xhr.status == 404) {
+ $(".github-info-card-description", $this).html(__("找不到该 Repo"));
+ } else {
+ $(".github-info-card-description", $this).html(__("获取 Repo 信息失败"));
}
}
});
@@ -4300,23 +4311,23 @@ function getGithubInfoCardContent(){
getGithubInfoCardContent();
/*说说点赞*/
-$(document).on("click" , ".shuoshuo-upvote" , function(){
+$(document).on("click", ".shuoshuo-upvote", function () {
$this = $(this);
ID = $this.attr("data-id");
$this.addClass("shuoshuo-upvoting");
$.ajax({
- url : argonConfig.wp_path + "wp-admin/admin-ajax.php",
- type : "POST",
- dataType : "json",
- data : {
+ url: argonConfig.wp_path + "wp-admin/admin-ajax.php",
+ type: "POST",
+ dataType: "json",
+ data: {
action: "upvote_shuoshuo",
- shuoshuo_id : ID,
+ shuoshuo_id: ID,
},
- success : function(result){
+ success: function (result) {
$this.removeClass("shuoshuo-upvoting");
- if (result.status == "success"){
- $(".shuoshuo-upvote-num" , $this).html(result.total_upvote);
- $("i.fa-thumbs-o-up" , $this).addClass("fa-thumbs-up").removeClass("fa-thumbs-o-up");
+ if (result.status == "success") {
+ $(".shuoshuo-upvote-num", $this).html(result.total_upvote);
+ $("i.fa-thumbs-o-up", $this).addClass("fa-thumbs-up").removeClass("fa-thumbs-o-up");
$this.addClass("upvoted");
$this.addClass("shuoshuo-upvoted-animation");
iziToast.show({
@@ -4331,8 +4342,8 @@ $(document).on("click" , ".shuoshuo-upvote" , function(){
icon: 'fa fa-check',
timeout: 5000
});
- }else{
- $(".shuoshuo-upvote-num" , $this).html(result.total_upvote);
+ } else {
+ $(".shuoshuo-upvote-num", $this).html(result.total_upvote);
iziToast.show({
title: result.msg,
class: 'shadow-sm',
@@ -4347,7 +4358,7 @@ $(document).on("click" , ".shuoshuo-upvote" , function(){
});
}
},
- error : function(xhr){
+ error: function (xhr) {
$this.removeClass("shuoshuo-upvoting");
iziToast.show({
title: __("点赞失败"),
@@ -4365,27 +4376,27 @@ $(document).on("click" , ".shuoshuo-upvote" , function(){
});
});
//折叠长说说
-function foldLongShuoshuo(){
- if (argonConfig.fold_long_shuoshuo == false){
+function foldLongShuoshuo() {
+ if (argonConfig.fold_long_shuoshuo == false) {
return;
}
- $("#main .shuoshuo-foldable > .shuoshuo-content").each(function(){
- if ($(this).hasClass("shuoshuo-unfolded")){
+ $("#main .shuoshuo-foldable > .shuoshuo-content").each(function () {
+ if ($(this).hasClass("shuoshuo-unfolded")) {
return;
}
- if (this.clientHeight > 400){
+ if (this.clientHeight > 400) {
$(this).addClass("shuoshuo-folded");
$(this).append("");
}
});
}
foldLongShuoshuo();
-$(document).on("click" , ".show-full-shuoshuo" , function(){
+$(document).on("click", ".show-full-shuoshuo", function () {
$(this).parent().removeClass("shuoshuo-folded").addClass("shuoshuo-unfolded");
});
//颜色计算
-function rgb2hsl(R,G,B){
+function rgb2hsl(R, G, B) {
let r = R / 255;
let g = G / 255;
let b = B / 255;
@@ -4396,13 +4407,13 @@ function rgb2hsl(R,G,B){
let H, S, L = (var_Max + var_Min) / 2;
- if (del_Max == 0){
+ if (del_Max == 0) {
H = 0;
S = 0;
- }else{
- if (L < 0.5){
+ } else {
+ if (L < 0.5) {
S = del_Max / (var_Max + var_Min);
- }else{
+ } else {
S = del_Max / (2 - var_Max - var_Min);
}
@@ -4410,13 +4421,13 @@ function rgb2hsl(R,G,B){
del_G = (((var_Max - g) / 6) + (del_Max / 2)) / del_Max;
del_B = (((var_Max - b) / 6) + (del_Max / 2)) / del_Max;
- if (r == var_Max){
+ if (r == var_Max) {
H = del_B - del_G;
}
- else if (g == var_Max){
+ else if (g == var_Max) {
H = (1 / 3) + del_R - del_B;
}
- else if (b == var_Max){
+ else if (b == var_Max) {
H = (2 / 3) + del_G - del_R;
}
if (H < 0) H += 1;
@@ -4431,7 +4442,7 @@ function rgb2hsl(R,G,B){
'L': Math.round(L * 100),//0~100
};
}
-function Hue_2_RGB(v1,v2,vH){
+function Hue_2_RGB(v1, v2, vH) {
if (vH < 0) vH += 1;
if (vH > 1) vH -= 1;
if ((6 * vH) < 1) return (v1 + (v2 - v1) * 6 * vH);
@@ -4439,18 +4450,18 @@ function Hue_2_RGB(v1,v2,vH){
if ((3 * vH) < 2) return (v1 + (v2 - v1) * ((2 / 3) - vH) * 6);
return v1;
}
-function hsl2rgb(h,s,l){
+function hsl2rgb(h, s, l) {
let r, g, b, var_1, var_2;
- if (s == 0){
+ if (s == 0) {
r = l;
g = l;
b = l;
}
- else{
- if (l < 0.5){
+ else {
+ if (l < 0.5) {
var_2 = l * (1 + s);
}
- else{
+ else {
var_2 = (l + s) - (s * l);
}
var_1 = 2 * l - var_2;
@@ -4467,53 +4478,53 @@ function hsl2rgb(h,s,l){
'b': b
};
}
-function rgb2hex(r,g,b){
+function rgb2hex(r, g, b) {
let hex = new Array('0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F');
let rh, gh, bh;
- rh = "", gh ="", bh="";
- while (rh.length < 2){
- rh = hex[r%16] + rh;
+ rh = "", gh = "", bh = "";
+ while (rh.length < 2) {
+ rh = hex[r % 16] + rh;
r = Math.floor(r / 16);
}
- while (gh.length < 2){
- gh = hex[g%16] + gh;
+ while (gh.length < 2) {
+ gh = hex[g % 16] + gh;
g = Math.floor(g / 16);
}
- while (bh.length < 2){
- bh = hex[b%16] + bh;
+ while (bh.length < 2) {
+ bh = hex[b % 16] + bh;
b = Math.floor(b / 16);
}
return "#" + rh + gh + bh;
}
-function hex2rgb(hex){
+function hex2rgb(hex) {
//hex: #XXXXXX
let dec = {
'0': 0, '1': 1, '2': 2, '3': 3, '4': 4, '5': 5, '6': 6, '7': 7, '8': 8, '9': 9, 'A': 10, 'B': 11, 'C': 12, 'D': 13, 'E': 14, 'F': 15
};
return {
- 'R': (dec[hex.substr(1,1)] * 16 + dec[hex.substr(2,1)]),//0~255
- 'G': (dec[hex.substr(3,1)] * 16 + dec[hex.substr(4,1)]),
- 'B': (dec[hex.substr(5,1)] * 16 + dec[hex.substr(6,1)]),
- 'r': (dec[hex.substr(1,1)] * 16 + dec[hex.substr(2,1)]) / 255,//0~1
- 'g': (dec[hex.substr(3,1)] * 16 + dec[hex.substr(4,1)]) / 255,
- 'b': (dec[hex.substr(5,1)] * 16 + dec[hex.substr(6,1)]) / 255
+ 'R': (dec[hex.substr(1, 1)] * 16 + dec[hex.substr(2, 1)]),//0~255
+ 'G': (dec[hex.substr(3, 1)] * 16 + dec[hex.substr(4, 1)]),
+ 'B': (dec[hex.substr(5, 1)] * 16 + dec[hex.substr(6, 1)]),
+ 'r': (dec[hex.substr(1, 1)] * 16 + dec[hex.substr(2, 1)]) / 255,//0~1
+ 'g': (dec[hex.substr(3, 1)] * 16 + dec[hex.substr(4, 1)]) / 255,
+ 'b': (dec[hex.substr(5, 1)] * 16 + dec[hex.substr(6, 1)]) / 255
};
}
-function rgb2gray(R,G,B){
+function rgb2gray(R, G, B) {
return Math.round(R * 0.299 + G * 0.587 + B * 0.114);
}
-function hex2gray(hex){
+function hex2gray(hex) {
let rgb_array = hex2rgb(hex);
return hex2gray(rgb_array['R'], rgb_array['G'], rgb_array['B']);
}
-function rgb2str(rgb){
+function rgb2str(rgb) {
return rgb['R'] + "," + rgb['G'] + "," + rgb['B'];
}
-function hex2str(hex){
+function hex2str(hex) {
return rgb2str(hex2rgb(hex));
}
//颜色选择器& 切换主题色
-if ($("meta[name='argon-enable-custom-theme-color']").attr("content") == 'true'){
+if ($("meta[name='argon-enable-custom-theme-color']").attr("content") == 'true') {
let themeColorPicker = new Pickr({
el: '#theme-color-picker',
container: 'body',
@@ -4573,11 +4584,11 @@ if ($("meta[name='argon-enable-custom-theme-color']").attr("content") == 'true')
setCookie("argon_custom_theme_color", "", 0);
});
}
-function pickrObjectToHEX(color){
+function pickrObjectToHEX(color) {
let HEXA = color.toHEXA();
return ("#" + HEXA[0] + HEXA[1] + HEXA[2]).toUpperCase();
}
-function updateThemeColor(color, setcookie){
+function updateThemeColor(color, setcookie) {
let themecolor = color;
let themecolor_rgbstr = hex2str(themecolor);
let RGB = hex2rgb(themecolor);
@@ -4592,58 +4603,58 @@ function updateThemeColor(color, setcookie){
document.documentElement.style.setProperty('--themecolor-L', HSL['L']);
- if (rgb2gray(RGB['R'], RGB['G'], RGB['B']) < 50){
+ if (rgb2gray(RGB['R'], RGB['G'], RGB['B']) < 50) {
$("html").addClass("themecolor-toodark");
- }else{
+ } else {
$("html").removeClass("themecolor-toodark");
}
$("meta[name='theme-color']").attr("content", themecolor);
$("meta[name='theme-color-rgb']").attr("content", themecolor_rgbstr);
- if (setcookie){
+ if (setcookie) {
setCookie("argon_custom_theme_color", themecolor, 365);
}
}
/*打字效果*/
-function typeEffect($element, text, now, interval){
- if (now > text.length){
- setTimeout(function(){
+function typeEffect($element, text, now, interval) {
+ if (now > text.length) {
+ setTimeout(function () {
$element.removeClass("typing-effect");
}, 1000);
return;
}
$element[0].innerText = text.substring(0, now);
- setTimeout(function(){typeEffect($element, text, now + 1, interval)}, interval);
+ setTimeout(function () { typeEffect($element, text, now + 1, interval) }, interval);
}
-function startTypeEffect($element, text, interval){
+function startTypeEffect($element, text, interval) {
$element.addClass("typing-effect");
$element.attr("style", "--animation-cnt: " + Math.ceil(text.length * interval / 1000));
typeEffect($element, text, 1, interval);
}
-!function(){
- if ($(".banner-title").data("interval") != undefined){
+!function () {
+ if ($(".banner-title").data("interval") != undefined) {
let interval = $(".banner-title").data("interval");
let $title = $(".banner-title-inner");
let $subTitle = $(".banner-subtitle");
startTypeEffect($title, $title.data("text"), interval);
- if (!$subTitle.length){
+ if (!$subTitle.length) {
return;
}
- setTimeout(function(){startTypeEffect($subTitle, $subTitle.data("text"), interval);}, Math.ceil($title.data("text").length * interval / 1000) * 1000);
+ setTimeout(function () { startTypeEffect($subTitle, $subTitle.data("text"), interval); }, Math.ceil($title.data("text").length * interval / 1000) * 1000);
}
}();
/*一言*/
-if ($(".hitokoto").length > 0){
+if ($(".hitokoto").length > 0) {
$.ajax({
type: 'GET',
url: "https://v1.hitokoto.cn",
- success: function(result){
+ success: function (result) {
$(".hitokoto").text(result.hitokoto);
},
- error: function(result){
+ error: function (result) {
$(".hitokoto").text(__("Hitokoto 获取失败"));
}
});
@@ -4661,13 +4672,13 @@ function randomString(len) {
return res;
}
var codeOfBlocks = {};
-function getCodeFromBlock(block){
- if (codeOfBlocks[block.id] != undefined){
+function getCodeFromBlock(block) {
+ if (codeOfBlocks[block.id] != undefined) {
return codeOfBlocks[block.id];
}
let lines = $(".hljs-ln-code", block);
let res = "";
- for (let i = 0; i < lines.length - 1; i++){
+ for (let i = 0; i < lines.length - 1; i++) {
res += lines[i].innerText;
res += "\n";
}
@@ -4677,37 +4688,37 @@ function getCodeFromBlock(block){
}
-function highlightJsRender(){
- if (typeof(hljs) == "undefined"){
+function highlightJsRender() {
+ if (typeof (hljs) == "undefined") {
return;
}
- if (typeof(argonConfig.code_highlight.enable) == "undefined"){
+ if (typeof (argonConfig.code_highlight.enable) == "undefined") {
return;
}
- if (!argonConfig.code_highlight.enable){
+ if (!argonConfig.code_highlight.enable) {
return;
}
- $("article pre.code").each(function(index, block) {
- if ($(block).hasClass("no-hljs")){
+ $("article pre.code").each(function (index, block) {
+ if ($(block).hasClass("no-hljs")) {
return;
}
$(block).html("" + $(block).html() + "");
});
- $("article pre > code").each(function(index, block) {
- if ($(block).hasClass("no-hljs")){
+ $("article pre > code").each(function (index, block) {
+ if ($(block).hasClass("no-hljs")) {
return;
}
$(block).parent().attr("id", randomString());
hljs.highlightBlock(block);
- hljs.lineNumbersBlock(block, {singleLine: true});
+ hljs.lineNumbersBlock(block, { singleLine: true });
$(block).parent().addClass("hljs-codeblock");
- if (argonConfig.code_highlight.hide_linenumber){
+ if (argonConfig.code_highlight.hide_linenumber) {
$(block).parent().addClass("hljs-hide-linenumber");
}
- if (argonConfig.code_highlight.break_line){
+ if (argonConfig.code_highlight.break_line) {
$(block).parent().addClass("hljs-break-line");
}
- if (argonConfig.code_highlight.transparent_linenumber){
+ if (argonConfig.code_highlight.transparent_linenumber) {
$(block).parent().addClass("hljs-transparent-linenumber");
}
$(block).attr("hljs-codeblock-inner", "");
@@ -4727,11 +4738,11 @@ function highlightJsRender(){
`);
let clipboard = new ClipboardJS("#" + copyBtnID, {
- text: function(trigger) {
+ text: function (trigger) {
return getCodeFromBlock($(block).parent()[0]);
}
});
- clipboard.on('success', function(e) {
+ clipboard.on('success', function (e) {
iziToast.show({
title: __("复制成功"),
message: __("代码已复制到剪贴板"),
@@ -4746,7 +4757,7 @@ function highlightJsRender(){
timeout: 5000
});
});
- clipboard.on('error', function(e) {
+ clipboard.on('error', function (e) {
iziToast.show({
title: __("复制失败"),
message: __("请手动复制代码"),
@@ -4763,14 +4774,14 @@ function highlightJsRender(){
});
});
}
-$(document).ready(function(){
+$(document).ready(function () {
// ==========================================================================
// 初始化性能优化模块
// ==========================================================================
if (typeof initArgonPerformance === 'function') {
// 调用性能优化模块的初始化函数
initArgonPerformance();
-
+
// 创建各个优化模块的实例
try {
// 1. 性能监控模块(最先初始化,用于监控其他模块)
@@ -4778,7 +4789,7 @@ $(document).ready(function(){
argonPerformanceMonitor = new ArgonPerformanceMonitor();
ArgonDebug.info('✓ 性能监控模块已初始化');
}
-
+
// 2. DOM 缓存模块
if (typeof ArgonDOMCache !== 'undefined') {
argonDOMCache = new ArgonDOMCache();
@@ -4790,31 +4801,31 @@ $(document).ready(function(){
argonDOMCache.init();
ArgonDebug.info('✓ DOM 缓存模块已初始化');
}
-
+
// 3. 事件管理模块
if (typeof ArgonEventManager !== 'undefined') {
argonEventManager = new ArgonEventManager();
ArgonDebug.info('✓ 事件管理模块已初始化');
}
-
+
// 4. 资源加载模块
if (typeof ArgonResourceLoader !== 'undefined') {
argonResourceLoader = new ArgonResourceLoader();
ArgonDebug.info('✓ 资源加载模块已初始化');
}
-
+
// 5. 渲染优化模块
if (typeof ArgonRenderOptimizer !== 'undefined') {
argonRenderOptimizer = new ArgonRenderOptimizer();
ArgonDebug.info('✓ 渲染优化模块已初始化');
}
-
+
// 6. 内存管理模块
if (typeof ArgonMemoryManager !== 'undefined') {
argonMemoryManager = new ArgonMemoryManager();
ArgonDebug.info('✓ 内存管理模块已初始化');
}
-
+
ArgonDebug.info('🚀 Argon 性能优化模块全部初始化完成');
} catch (error) {
ArgonDebug.error('性能优化模块初始化失败:', error);
@@ -4822,27 +4833,27 @@ $(document).ready(function(){
} else {
ArgonDebug.warn('性能优化模块未加载,请确保 argon-performance.js 已正确引入');
}
-
+
// ==========================================================================
// 原有初始化代码
// ==========================================================================
highlightJsRender();
waterflowInit();
});
-$(document).on("click" , ".hljs-control-fullscreen" , function(){
+$(document).on("click", ".hljs-control-fullscreen", function () {
let block = $(this).parent().parent();
block.toggleClass("hljs-codeblock-fullscreen");
- if (block.hasClass("hljs-codeblock-fullscreen")){
+ if (block.hasClass("hljs-codeblock-fullscreen")) {
$("html").addClass("noscroll codeblock-fullscreen");
- }else{
+ } else {
$("html").removeClass("noscroll codeblock-fullscreen");
}
});
-$(document).on("click" , ".hljs-control-toggle-break-line" , function(){
+$(document).on("click", ".hljs-control-toggle-break-line", function () {
let block = $(this).parent().parent();
block.toggleClass("hljs-break-line");
});
-$(document).on("click" , ".hljs-control-toggle-linenumber" , function(){
+$(document).on("click", ".hljs-control-toggle-linenumber", function () {
let block = $(this).parent().parent();
block.toggleClass("hljs-hide-linenumber");
});
@@ -4925,171 +4936,204 @@ setInterval(function(){
/*Console*/
-!function(){
-void 0;
+!function () {
+ void 0;
}();
/* ========== Modern UI Enhancements - 现代化交互动画增强========== */
-(function() {
- 'use strict';
+(function () {
+ 'use strict';
- // 1. 图片加载动画
- function initImageLoadAnimation() {
- var images = document.querySelectorAll('article img[loading="lazy"], .post-thumbnail img');
- images.forEach(function(img) {
- if (img.dataset.loadAnimInit) return;
- img.dataset.loadAnimInit = 'true';
- if (img.complete) { img.classList.add('loaded'); }
- else { img.addEventListener('load', function() { this.classList.add('loaded'); }); }
- });
- }
+ // 1. 图片加载动画
+ function initImageLoadAnimation() {
+ var images = document.querySelectorAll('article img[loading="lazy"], .post-thumbnail img');
+ images.forEach(function (img) {
+ if (img.dataset.loadAnimInit) return;
+ img.dataset.loadAnimInit = 'true';
+ if (img.complete) { img.classList.add('loaded'); }
+ else { img.addEventListener('load', function () { this.classList.add('loaded'); }); }
+ });
+ }
- // 3. 滚动入场动画
- function initScrollAnimations() {
- if (!('IntersectionObserver' in window)) return;
- var animatedElements = document.querySelectorAll('.article-list article.post, .comment-item, .timeline-item, .friend-link-item, #leftbar .card, #rightbar .card');
- var observer = new IntersectionObserver(function(entries) {
- entries.forEach(function(entry) {
- if (entry.isIntersecting) { entry.target.classList.add('animate-in'); observer.unobserve(entry.target); }
- });
- }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' });
- animatedElements.forEach(function(el) { if (!el.classList.contains('animate-in')) observer.observe(el); });
- }
+ // 3. 滚动入场动画
+ function initScrollAnimations() {
+ if (!('IntersectionObserver' in window)) return;
+ var animatedElements = document.querySelectorAll('.article-list article.post, .comment-item, .timeline-item, .friend-link-item, #leftbar .card, #rightbar .card');
+ var observer = new IntersectionObserver(function (entries) {
+ entries.forEach(function (entry) {
+ if (entry.isIntersecting) { entry.target.classList.add('animate-in'); observer.unobserve(entry.target); }
+ });
+ }, { threshold: 0.1, rootMargin: '0px 0px -50px 0px' });
+ animatedElements.forEach(function (el) { if (!el.classList.contains('animate-in')) observer.observe(el); });
+ }
- // 4. 平滑滚动
- function initSmoothScroll() {
- document.querySelectorAll('a[href^="#"]').forEach(function(anchor) {
- if (anchor.dataset.smoothScrollInit) return;
- anchor.dataset.smoothScrollInit = 'true';
- anchor.addEventListener('click', function(e) {
- var targetId = this.getAttribute('href');
- if (targetId === '#') return;
- var target = document.querySelector(targetId);
- if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth', block: 'start' }); }
- });
- });
- }
+ // 4. 平滑滚动
+ function initSmoothScroll() {
+ document.querySelectorAll('a[href^="#"]').forEach(function (anchor) {
+ if (anchor.dataset.smoothScrollInit) return;
+ anchor.dataset.smoothScrollInit = 'true';
+ anchor.addEventListener('click', function (e) {
+ var targetId = this.getAttribute('href');
+ if (targetId === '#') return;
+ var target = document.querySelector(targetId);
+ if (target) { e.preventDefault(); target.scrollIntoView({ behavior: 'smooth', block: 'start' }); }
+ });
+ });
+ }
- // 5. 页面加载进度条
- function initLoadingBar() {
- if (document.getElementById('page-loading-bar')) return;
- var bar = document.createElement('div');
- bar.id = 'page-loading-bar';
- bar.style.width = '0%';
- document.body.appendChild(bar);
- var progress = 0;
- var interval = setInterval(function() {
- progress += Math.random() * 10;
- if (progress >= 90) { clearInterval(interval); progress = 90; }
- bar.style.width = progress + '%';
- }, 100);
- var overlay = document.getElementById('article-loading-overlay');
- if (!overlay) {
- overlay = document.createElement('div');
- overlay.id = 'article-loading-overlay';
- var inner = document.createElement('div');
- inner.className = 'overlay-content';
- inner.innerHTML = '';
- overlay.appendChild(inner);
- document.body.appendChild(overlay);
- }
- overlay.classList.remove('is-hiding');
- requestAnimationFrame(function() {
- overlay.classList.add('is-visible');
- });
- window.addEventListener('load', function() {
- clearInterval(interval);
- bar.style.width = '100%';
- setTimeout(function() { bar.style.opacity = '0'; setTimeout(function() { bar.remove(); }, 300); }, 200);
- if (overlay) {
- overlay.classList.remove('is-visible');
- overlay.classList.add('is-hiding');
- setTimeout(function() { if (overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); }, 360);
- }
- });
- }
+ // 5. 页面加载进度条
+ function initLoadingBar() {
+ if (document.getElementById('page-loading-bar')) return;
+ var bar = document.createElement('div');
+ bar.id = 'page-loading-bar';
+ bar.style.width = '0%';
+ document.body.appendChild(bar);
+ var progress = 0;
+ var interval = setInterval(function () {
+ progress += Math.random() * 10;
+ if (progress >= 90) { clearInterval(interval); progress = 90; }
+ bar.style.width = progress + '%';
+ }, 100);
+ var overlay = document.getElementById('article-loading-overlay');
+ if (!overlay) {
+ overlay = document.createElement('div');
+ overlay.id = 'article-loading-overlay';
+ var inner = document.createElement('div');
+ inner.className = 'overlay-content';
+ inner.innerHTML = '';
+ overlay.appendChild(inner);
+ document.body.appendChild(overlay);
+ }
+ overlay.classList.remove('is-hiding');
+ requestAnimationFrame(function () {
+ overlay.classList.add('is-visible');
+ });
+ window.addEventListener('load', function () {
+ clearInterval(interval);
+ bar.style.width = '100%';
+ setTimeout(function () { bar.style.opacity = '0'; setTimeout(function () { bar.remove(); }, 300); }, 200);
+ if (overlay) {
+ overlay.classList.remove('is-visible');
+ overlay.classList.add('is-hiding');
+ setTimeout(function () { if (overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); }, 360);
+ }
+ });
+ }
- // 6. PJAX 加载动画
- function initPjaxAnimations() {
- if (typeof jQuery === 'undefined') return;
- jQuery(document).on('pjax:start', function() {
- jQuery('#primary').addClass('pjax-loading');
- var bar = document.getElementById('page-loading-bar');
- if (!bar) { bar = document.createElement('div'); bar.id = 'page-loading-bar'; document.body.appendChild(bar); }
- bar.style.opacity = '1'; bar.style.width = '30%';
- setTimeout(function() { bar.style.width = '60%'; }, 200);
- var overlay = document.getElementById('article-loading-overlay');
- if (!overlay) {
- overlay = document.createElement('div');
- overlay.id = 'article-loading-overlay';
- var inner = document.createElement('div');
- inner.className = 'overlay-content';
- inner.innerHTML = '';
- overlay.appendChild(inner);
- document.body.appendChild(overlay);
- }
- overlay.classList.remove('is-hiding');
- requestAnimationFrame(function() {
- overlay.classList.add('is-visible');
- });
- });
- jQuery(document).on('pjax:end', function() {
- jQuery('#primary').removeClass('pjax-loading');
- var bar = document.getElementById('page-loading-bar');
- if (bar) { bar.style.width = '100%'; setTimeout(function() { bar.style.opacity = '0'; setTimeout(function() { bar.remove(); }, 300); }, 200); }
- setTimeout(function() { initImageLoadAnimation(); initScrollAnimations(); initSmoothScroll(); }, 100);
- var overlay = document.getElementById('article-loading-overlay');
- if (overlay) {
- overlay.classList.remove('is-visible');
- overlay.classList.add('is-hiding');
- setTimeout(function() { if (overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); }, 360);
- }
- });
- }
+ // 6. PJAX 加载动画
+ function initPjaxAnimations() {
+ if (typeof jQuery === 'undefined') return;
+ jQuery(document).on('pjax:start', function () {
+ jQuery('#primary').addClass('pjax-loading');
+ var bar = document.getElementById('page-loading-bar');
+ if (!bar) { bar = document.createElement('div'); bar.id = 'page-loading-bar'; document.body.appendChild(bar); }
+ bar.style.opacity = '1'; bar.style.width = '30%';
+ setTimeout(function () { bar.style.width = '60%'; }, 200);
+ var overlay = document.getElementById('article-loading-overlay');
+ if (!overlay) {
+ overlay = document.createElement('div');
+ overlay.id = 'article-loading-overlay';
+ var inner = document.createElement('div');
+ inner.className = 'overlay-content';
+ inner.innerHTML = '';
+ overlay.appendChild(inner);
+ document.body.appendChild(overlay);
+ }
+ overlay.classList.remove('is-hiding');
+ requestAnimationFrame(function () {
+ overlay.classList.add('is-visible');
+ });
+ });
+ jQuery(document).on('pjax:end', function () {
+ jQuery('#primary').removeClass('pjax-loading');
+ var bar = document.getElementById('page-loading-bar');
+ if (bar) { bar.style.width = '100%'; setTimeout(function () { bar.style.opacity = '0'; setTimeout(function () { bar.remove(); }, 300); }, 200); }
+ setTimeout(function () { initArticleSkeletons(); initImageLoadAnimation(); initScrollAnimations(); initSmoothScroll(); }, 100);
+ var overlay = document.getElementById('article-loading-overlay');
+ if (overlay) {
+ overlay.classList.remove('is-visible');
+ overlay.classList.add('is-hiding');
+ setTimeout(function () { if (overlay && overlay.parentNode) overlay.parentNode.removeChild(overlay); }, 360);
+ }
+ });
+ }
- // 7. 主题切换动画 - 已在 header.php 中通过 setDarkmode 函数处理,此处不再重复
- function initThemeTransition() {
- // 移除 MutationObserver 避免无限循环导致内存泄漏
- // 主题切换过渡效果已在 setDarkmode() 函数中实现
- }
+ // 7. 主题切换动画 - 已在 header.php 中通过 setDarkmode 函数处理,此处不再重复
+ function initThemeTransition() {
+ // 移除 MutationObserver 避免无限循环导致内存泄漏
+ // 主题切换过渡效果已在 setDarkmode() 函数中实现
+ }
- // 8. 减少动画偏好检查
- function checkReducedMotion() {
- if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
- document.documentElement.classList.add('reduced-motion');
- }
- }
+ // 7.1 骨架屏加载动画 (Skeleton Screen)
+ function initArticleSkeletons() {
+ if (typeof jQuery === 'undefined') return;
+ var $articles = jQuery('.article-list article.post:not(.skeleton-processed)');
+ if ($articles.length === 0) return;
- // 初始化
- function init() {
- checkReducedMotion();
- initImageLoadAnimation();
- initScrollAnimations();
- initSmoothScroll();
- initPjaxAnimations();
- initThemeTransition();
- }
+ $articles.each(function () {
+ var $this = jQuery(this);
+ $this.addClass('skeleton-processed skeleton-loading');
- if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); }
- else { init(); }
- if (document.readyState !== 'complete') { initLoadingBar(); }
+ // 构造骨架屏 DOM
+ var skeletonHtml =
+ '' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
' +
+ '
';
+
+ var $skeleton = jQuery(skeletonHtml);
+ $this.prepend($skeleton);
+
+ setTimeout(function () {
+ $this.removeClass('skeleton-loading');
+ setTimeout(function () {
+ $skeleton.remove();
+ }, 400); // 配合 CSS 的 0.4s transition
+ }, 800); // 骨架屏显示 800ms
+ });
+ }
+
+ // 8. 减少动画偏好检查
+ function checkReducedMotion() {
+ if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
+ document.documentElement.classList.add('reduced-motion');
+ }
+ }
+
+ // 初始化
+ function init() {
+ initArticleSkeletons();
+ checkReducedMotion();
+ initImageLoadAnimation();
+ initScrollAnimations();
+ initSmoothScroll();
+ initPjaxAnimations();
+ initThemeTransition();
+ }
+
+ if (document.readyState === 'loading') { document.addEventListener('DOMContentLoaded', init); }
+ else { init(); }
+ if (document.readyState !== 'complete') { initLoadingBar(); }
})();
/* ========== End of Modern UI Enhancements ========== */
// ========== jQuery Easing 备用(确保在所有脚本加载后仍可用)==========
-(function() {
- if (typeof jQuery === 'undefined') return;
- var $ = jQuery;
- if (!$.easing) $.easing = {};
- if (!$.easing.easeOutCirc) {
- $.easing.easeOutCirc = function(x) {
- return Math.sqrt(1 - Math.pow(x - 1, 2));
- };
- }
- if (!$.easing.easeOutExpo) {
- $.easing.easeOutExpo = function(x) {
- return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
- };
- }
+(function () {
+ if (typeof jQuery === 'undefined') return;
+ var $ = jQuery;
+ if (!$.easing) $.easing = {};
+ if (!$.easing.easeOutCirc) {
+ $.easing.easeOutCirc = function (x) {
+ return Math.sqrt(1 - Math.pow(x - 1, 2));
+ };
+ }
+ if (!$.easing.easeOutExpo) {
+ $.easing.easeOutExpo = function (x) {
+ return x === 1 ? 1 : 1 - Math.pow(2, -10 * x);
+ };
+ }
})();
diff --git a/footer.php b/footer.php
index 2c36eeb..dd81527 100644
--- a/footer.php
+++ b/footer.php
@@ -161,6 +161,55 @@
+
+
+