diff --git a/argontheme.js b/argontheme.js index c196211..b1956d0 100644 --- a/argontheme.js +++ b/argontheme.js @@ -1,24 +1,9 @@ /*! * Argon 主题核心 JavaScript - * - * 目录: - * 1. 兼容性修复 - 第三方库 polyfill - * 2. 全局配置 - argonConfig 初始化 - * 3. 工具函数 - Cookie、翻译等 - * 4. 顶栏功能 - 透明度、搜索 - * 5. 侧边栏 - 浮动、滚动 - * 6. 文章列表 - 瀑布流布局 - * 7. 浮动按钮 - 回顶、设置 - * 8. 评论系统 - 发送、回复、编辑 - * 9. 代码高亮 - Prism 增强 - * 10. PJAX - 页面无刷新加载 */ -// ========================================================================== -// 1. 兼容性修复 - 确保第三方库存在 -// ========================================================================== - -// Prism 代码高亮 +// ========== 兼容性修复 ========== +// 确保 Prism 和 autoloader 存在 if (typeof window.Prism === 'undefined') { window.Prism = { highlightAll: function() {}, @@ -36,19 +21,21 @@ if (typeof window.Prism.plugins.autoloader === 'undefined') { }; } -// Zoomify 图片缩放 +// 确保 Zoomify 存在 if (typeof window.Zoomify === 'undefined') { window.Zoomify = function() {}; window.Zoomify.DEFAULTS = {}; } -// jQuery 插件 +// 确保 jQuery 插件存在 if (typeof jQuery !== 'undefined') { (function($) { + // 确保 zoomify 插件存在 if (typeof $.fn.zoomify === 'undefined') { $.fn.zoomify = function() { return this; }; } + // 确保 fancybox 存在 if (typeof $.fancybox === 'undefined') { $.fancybox = { defaults: { @@ -70,6 +57,7 @@ if (typeof jQuery !== 'undefined') { }; } + // 确保 pjax 存在 if (typeof $.pjax === 'undefined') { $.pjax = function() {}; $.pjax.defaults = { @@ -88,56 +76,37 @@ if (typeof jQuery !== 'undefined') { })(jQuery); } -// ========================================================================== -// 2. 全局配置 -// ========================================================================== - -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 = "/"; } - -// ========================================================================== -// 3. 工具函数 -// ========================================================================== - -/** - * 设置 Cookie - * @param {string} cname - Cookie 名称 - * @param {string} cvalue - Cookie 值 - * @param {number} exdays - 过期天数 - */ +/*Cookies 操作*/ function setCookie(cname, cvalue, exdays) { let d = new Date(); d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000)); let expires = "expires=" + d.toUTCString(); document.cookie = cname + "=" + cvalue + ";" + expires + ";path=/"; } - -/** - * 获取 Cookie - * @param {string} cname - Cookie 名称 - * @returns {string} Cookie 值 - */ function getCookie(cname) { let name = cname + "="; let decodedCookie = decodeURIComponent(document.cookie); let ca = decodedCookie.split(';'); for (let i = 0; i < ca.length; i++) { let c = ca[i]; - while (c.charAt(0) === ' ') { + while (c.charAt(0) == ' ') { c = c.substring(1); } - if (c.indexOf(name) === 0) { + if (c.indexOf(name) == 0) { return c.substring(name.length, c.length); } } return ""; } -// ---------- 多语言翻译系统 ---------- +/*多语言支持*/ var translation = {}; translation['en_US'] = { "确定": "OK", @@ -324,20 +293,16 @@ translation['zh_TW'] = { }; 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]; } -// ========================================================================== -// 4. 顶栏功能 -// ========================================================================== - -// ---------- 顶栏透明度随滚动变化 ---------- +/*根据滚动高度改变顶栏透明度*/ !function(){ let toolbar = document.getElementById("navbar-main"); let $bannerContainer = $("#banner_container"); @@ -400,7 +365,7 @@ function __(text){ document.addEventListener("scroll", changeToolbarOnTopClass, {passive: true}); return; } - if (argonConfig.headroom === "absolute") { + if (argonConfig.headroom == "absolute") { toolbar.classList.add("navbar-ontop"); return; } @@ -414,7 +379,7 @@ function __(text){ document.addEventListener("scroll", changeToolbarTransparency, {passive: true}); }(); -// ---------- 搜索功能 ---------- +/*搜索*/ function searchPosts(word){ if ($(".search-result").length > 0){ let url = new URL(window.location.href); @@ -444,7 +409,7 @@ $(document).on("blur" , "#navbar_search_input_container" , function(){ }); // 监听输入变化来切换has-text类 $(document).on("input" , "#navbar_search_input" , function(){ - let container = $("#navbar_search_input_container"); + var container = $("#navbar_search_input_container"); if ($(this).val().trim() !== "") { container.addClass("has-text"); } else { @@ -452,11 +417,11 @@ $(document).on("input" , "#navbar_search_input" , function(){ } }); $(document).on("keydown" , "#navbar_search_input_container #navbar_search_input" , function(e){ - if (e.keyCode !== 13){ + if (e.keyCode != 13){ return; } let word = $(this).val(); - if (word === ""){ + if (word == ""){ $("#navbar_search_input_container").blur(); return; } @@ -465,12 +430,12 @@ $(document).on("keydown" , "#navbar_search_input_container #navbar_search_input" }); /*顶栏搜索 (Mobile)*/ $(document).on("keydown" , "#navbar_search_input_mobile" , function(e){ - if (e.keyCode !== 13){ + if (e.keyCode != 13){ return; } let word = $(this).val(); $("#navbar_global .collapse-close button").click(); - if (word === ""){ + if (word == ""){ return; } let scrolltop = $(document).scrollTop(); @@ -489,11 +454,11 @@ $(document).on("blur" , "#leftbar_search_container" , function(){ $("#leftbar_search_input").attr("readonly", "readonly"); }); $(document).on("keydown" , "#leftbar_search_input" , function(e){ - if (e.keyCode !== 13){ + if (e.keyCode != 13){ return; } let word = $(this).val(); - if (word === ""){ + if (word == ""){ $("#leftbar_search_container").blur(); return; } @@ -512,7 +477,7 @@ $(document).on("change" , ".search-filter" , function(e){ $(".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); @@ -523,13 +488,9 @@ $(document).on("change" , ".search-filter" , function(e){ }); }); -// ========================================================================== -// 5. 侧边栏 -// ========================================================================== - -// ---------- 侧栏随滚动浮动 ---------- +/*左侧栏随页面滚动浮动*/ !function(){ - if ($("#leftbar").length === 0){ + if ($("#leftbar").length == 0){ let contentOffsetTop = $('#content').offset().top; function changeLeftbarStickyStatusWithoutSidebar(){ let scrollTop = document.documentElement.scrollTop || document.body.scrollTop; @@ -558,7 +519,7 @@ $(document).on("change" , ".search-filter" , function(e){ 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) { @@ -592,7 +553,7 @@ $(document).on("change" , ".search-filter" , function(e){ }(); /*Headroom*/ -if (argonConfig.headroom === "true"){ +if (argonConfig.headroom == "true"){ var headroom = new Headroom(document.querySelector("body"),{ "tolerance" : { up : 0, @@ -612,13 +573,9 @@ if (argonConfig.headroom === "true"){ }).init(); } -// ========================================================================== -// 6. 文章列表布局 -// ========================================================================== - -// ---------- 瀑布流布局 ---------- +/*瀑布流布局*/ function waterflowInit() { - if (argonConfig.waterflow_columns === "1") { + if (argonConfig.waterflow_columns == "1") { return; } $("#main.article-list img").each(function(index, ele){ @@ -627,7 +584,7 @@ function waterflowInit() { } }); let columns; - if (argonConfig.waterflow_columns === "2and3") { + if (argonConfig.waterflow_columns == "2and3") { if ($("#main").outerWidth() > 1000) { columns = 3; } else { @@ -636,16 +593,16 @@ function waterflowInit() { }else{ columns = parseInt(argonConfig.waterflow_columns); } - if ($("#main").outerWidth() < 650 && columns === 2) { + 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(){ let res = 0, minn = 2147483647; - for (let i = 0; i < columns; i++) { + for (var i = 0; i < columns; i++) { if (heights[i] < minn) { minn = heights[i]; res = i; @@ -668,7 +625,7 @@ function waterflowInit() { } let $items = $container.find("article.post:not(.no-results), .shuoshuo-preview-container"); columns = Math.max(Math.min(columns, $items.length), 1); - if (columns === 1) { + if (columns == 1) { $container.removeClass("waterflow"); $items.css("transition", "").css("position", "").css("width", "").css("top", "").css("left", "").css("margin", ""); $(".waterflow-placeholder").remove(); @@ -693,7 +650,7 @@ function waterflowInit() { } } waterflowInit(); -if (argonConfig.waterflow_columns !== "1") { +if (argonConfig.waterflow_columns != "1") { $(window).resize(function(){ waterflowInit(); }); @@ -706,11 +663,11 @@ if (argonConfig.waterflow_columns !== "1") { /*移动端文章列表布局切换*/ !function(){ - let mobileLayout = argonConfig.article_list_layout_mobile || "1"; - let isMobile = window.innerWidth <= 900; + var mobileLayout = argonConfig.article_list_layout_mobile || "1"; + var isMobile = window.innerWidth <= 900; function applyMobileLayout() { - let nowMobile = window.innerWidth <= 900; + var nowMobile = window.innerWidth <= 900; if (nowMobile) { $("html").addClass("mobile-layout-" + mobileLayout); } else { @@ -724,10 +681,7 @@ if (argonConfig.waterflow_columns !== "1") { }); }(); -// ========================================================================== -// 7. 浮动操作按钮 -// ========================================================================== - +/*浮动按钮栏相关 (回顶等)*/ !function(){ // 确保 DOM 和 jQuery 已加载 if (typeof jQuery === 'undefined') { @@ -774,10 +728,10 @@ if (argonConfig.waterflow_columns !== "1") { $("#fabtn_go_to_comment").addClass("fabtn-hidden"); } $goToComment.on("click" , function(){ - let commentsArea = $("#comments"); - let postCommentArea = $("#post_comment"); - let wasCollapsed = commentsArea.hasClass("comments-collapsed"); - let toggleBtn = $("#comments_toggle"); + var commentsArea = $("#comments"); + var postCommentArea = $("#post_comment"); + var wasCollapsed = commentsArea.hasClass("comments-collapsed"); + var toggleBtn = $("#comments_toggle"); if (wasCollapsed && toggleBtn.length > 0) { // 折叠状态:先滚动到评论切换按钮位置,再展开 @@ -801,7 +755,7 @@ 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(){ @@ -835,9 +789,9 @@ if (argonConfig.waterflow_columns !== "1") { $("html").addClass("use-serif"); localStorage['Argon_Use_Serif'] = "true"; }); - if (localStorage['Argon_Use_Serif'] === "true"){ + if (localStorage['Argon_Use_Serif'] == "true"){ $("html").addClass("use-serif"); - }else if (localStorage['Argon_Use_Serif'] === "false"){ + }else if (localStorage['Argon_Use_Serif'] == "false"){ $("html").removeClass("use-serif"); } //阴影 @@ -849,19 +803,19 @@ if (argonConfig.waterflow_columns !== "1") { $("html").addClass("use-big-shadow"); localStorage['Argon_Use_Big_Shadow'] = "true"; }); - if (localStorage['Argon_Use_Big_Shadow'] === "true"){ + if (localStorage['Argon_Use_Big_Shadow'] == "true"){ $("html").addClass("use-big-shadow"); - }else if (localStorage['Argon_Use_Big_Shadow'] === "false"){ + }else if (localStorage['Argon_Use_Big_Shadow'] == "false"){ $("html").removeClass("use-big-shadow"); } //滤镜 function setBlogFilter(name){ - if (name === undefined || name === ""){ + if (name == undefined || name == ""){ name = "off"; } if (!$("html").hasClass("filter-" + name)){ $("html").removeClass("filter-sunset filter-darkness filter-grayscale"); - if (name !== "off"){ + if (name != "off"){ $("html").addClass("filter-" + name); } } @@ -876,11 +830,11 @@ if (argonConfig.waterflow_columns !== "1") { //UI 样式切换 (玻璃拟态/新拟态) function setUIStyle(style){ - if (style === undefined || 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"); @@ -904,7 +858,7 @@ if (argonConfig.waterflow_columns !== "1") { $readingProgressDetails.html((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{ let a = $window.scrollTop() - ($("article.post.post-full").offset().top - 80); @@ -970,12 +924,9 @@ if (argonConfig.waterflow_columns !== "1") { }); }(); -// ========================================================================== -// 8. 评论系统 -// ========================================================================== - +/*评论区 & 发送评论*/ !function(){ - // ---------- 回复评论 ---------- + //回复评论 let replying = false , replyID = 0; function reply(commentID){ cancelEdit(false); @@ -1032,7 +983,7 @@ if (argonConfig.waterflow_columns !== "1") { $('#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{ document.getElementById("comment_post_use_markdown").checked = false; @@ -1051,7 +1002,7 @@ if (argonConfig.waterflow_columns !== "1") { editing = false; editID = 0; $("#post_comment").removeClass("post-comment-force-privatemode-on post-comment-force-privatemode-off"); - if (clear === true) $("#post_comment_content").val(""); + if (clear == true) $("#post_comment_content").val(""); $("#post_comment_content").trigger("change"); $('#post_comment').removeClass("editing"); } @@ -1096,7 +1047,7 @@ if (argonConfig.waterflow_columns !== "1") { }, success: function(result){ $("#comment_pin_comfirm_dialog").modal('hide'); - if (result.status === "success"){ + if (result.status == "success"){ if (pinned){ $("#comment-" + commentID + " .comment-name .badge-pinned").remove(); $("#comment-" + commentID + " .comment-unpin").removeClass("comment-unpin").addClass("comment-pin").html(__("置顶")); @@ -1153,8 +1104,9 @@ if (argonConfig.waterflow_columns !== "1") { }); $("#comment_pin_comfirm_dialog").modal(null); } + -//显示/隐藏额外输入框 (评论者网站) + //显示/隐藏额外输入框 (评论者网站) $(document).on("click" , "#post_comment_toggle_extra_input" , function(){ $("#post_comment").toggleClass("show-extra-input"); if ($("#post_comment").hasClass("show-extra-input")){ @@ -1230,7 +1182,7 @@ if (argonConfig.waterflow_columns !== "1") { } } }else{ - if (commentEmail.length || (document.getElementById("comment_post_mailnotice") !== null && document.getElementById("comment_post_mailnotice").checked === true)){ + 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; @@ -1244,7 +1196,7 @@ if (argonConfig.waterflow_columns !== "1") { } } } - if (commentLink !== "" && !(/https?:\/\//).test(commentLink)){ + if (commentLink != "" && !(/https?:\/\//).test(commentLink)){ isError = true; errorMsg += __("网站格式错误 (不是 http(s):// 开头)") + "
"; } @@ -1272,11 +1224,11 @@ if (argonConfig.waterflow_columns !== "1") { } } else { // 原有的数学验证码检查 - if (commentCaptcha === ""){ + if (commentCaptcha == ""){ isError = true; errorMsg += __("验证码未输入"); } - if (commentCaptcha !== "" && !(/^[0-9]+$/).test(commentCaptcha)){ + if (commentCaptcha != "" && !(/^[0-9]+$/).test(commentCaptcha)){ isError = true; errorMsg += __("验证码格式错误"); } @@ -1339,7 +1291,7 @@ if (argonConfig.waterflow_columns !== "1") { }); // 准备数据 - let ajaxData = { + var ajaxData = { action: "ajax_post_comment", comment: commentContent, author: commentName, @@ -1447,7 +1399,7 @@ if (argonConfig.waterflow_columns !== "1") { } //判断是否有错误 - if (result.status === "failed"){ + if (result.status == "failed"){ // 使用 setTimeout 确保 iziToast 操作在下一个事件循环中执行 setTimeout(function() { try { @@ -1493,15 +1445,15 @@ if (argonConfig.waterflow_columns !== "1") { //插入新评论 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{ $("#comments > .card-body > ol.comment-list").prepend(result.html); @@ -1658,7 +1610,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: __("评论编辑失败"), @@ -1680,7 +1632,7 @@ if (argonConfig.waterflow_columns !== "1") { 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){ @@ -1716,7 +1668,7 @@ if (argonConfig.waterflow_columns !== "1") { $("#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: __("评论编辑失败"), @@ -1771,7 +1723,7 @@ if (argonConfig.waterflow_columns !== "1") { } } }else{ - if (commentEmail.length || (document.getElementById("comment_post_mailnotice") !== null && document.getElementById("comment_post_mailnotice").checked === true)){ + 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; @@ -1785,7 +1737,7 @@ if (argonConfig.waterflow_columns !== "1") { } } } - if (commentLink !== "" && !(/https?:\/\//).test(commentLink)){ + if (commentLink != "" && !(/https?:\/\//).test(commentLink)){ isError = true; errorMsg += __("网站格式错误 (不是 http(s):// 开头)") + "
    "; } @@ -1885,7 +1837,7 @@ $(document).on("click" , ".comment-upvote" , function(){ }, success : function(result){ $this.removeClass("comment-upvoting"); - if (result.status === "success"){ + if (result.status == "success"){ $(".comment-upvote-num" , $this).html(result.total_upvote); $this.addClass("upvoted"); }else{ @@ -1967,10 +1919,10 @@ $(document).on("dragstart" , ".emotion-keyboard .emotion-item > img, .comment-st 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");   } }) @@ -1990,7 +1942,7 @@ function showCommentEditHistory(id){ id: id }, success: function(result){ - if ($("#comment_edit_history").data("request-id") !== requestID){ + if ($("#comment_edit_history").data("request-id") != requestID){ return; } $("#comment_edit_history .modal-body").hide(); @@ -1998,7 +1950,7 @@ function showCommentEditHistory(id){ $("#comment_edit_history .modal-body").fadeIn(300); }, error: function(result){ - if ($("#comment_edit_history").data("request-id") !== requestID){ + if ($("#comment_edit_history").data("request-id") != requestID){ return; } $("#comment_edit_history .modal-body").hide(); @@ -2012,7 +1964,7 @@ $(document).on("click" , ".comment-edited.comment-edithistory-accessible" , func }); /*过长评论折叠*/ function foldLongComments(){ - if (argonConfig.fold_long_comments === false){ + if (argonConfig.fold_long_comments == false){ return; } $(".comment-item-inner").each(function(){ @@ -2036,7 +1988,7 @@ function generateCommentTextAvatar(img){ emailHash = img.attr("src").match(/([a-f\d]{32}|[A-F\d]{32})/)[0]; }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(); } } @@ -2046,7 +1998,7 @@ function generateCommentTextAvatar(img){ } 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"; @@ -2126,7 +2078,7 @@ $(document).on("submit" , ".post-password-form" , function(){ 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{ @@ -2146,13 +2098,13 @@ $(document).on("submit" , ".post-password-form" , function(){ /*URL 中 # 根据 ID 定位*/ function gotoHash(hash, durtion, easing = 'easeOutExpo'){ - if (hash.length === 0){ + if (hash.length == 0){ return; } - if ($(hash).length === 0){ + if ($(hash).length == 0){ return; } - if (durtion === null){ + if (durtion == null){ durtion = 200; } $("body,html").stop().animate({ @@ -2193,7 +2145,7 @@ showPostOutdateToast(); /*Zoomify*/ function zoomifyInit(){ - if (argonConfig.zoomify === false){ + if (argonConfig.zoomify == false){ return; } if (typeof $.fn.zoomify === 'function') { @@ -2327,18 +2279,14 @@ if ($("html").hasClass("banner-as-cover")){ }); } -// ========================================================================== -// 10. PJAX 无刷新加载 -// ========================================================================== - -let pjaxScrollTop = 0; -var pjaxLoading = false; +/*Pjax*/ +var pjaxScrollTop = 0, pjaxLoading = false; $.pjax.defaults.timeout = 10000; $.pjax.defaults.container = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#rightbar', '#wpadminbar']; $.pjax.defaults.fragment = ['#primary', '#leftbar_part1_menu', '#leftbar_part2_inner', '.page-information-card-container', '#rightbar', '#wpadminbar']; $(document).pjax("a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):not([download]):not(.reference-link):not(.reference-list-backlink)") .on('pjax:click', function(e, f, g){ - if (argonConfig.disable_pjax === true){ + if (argonConfig.disable_pjax == true){ e.preventDefault(); return; } @@ -2392,8 +2340,8 @@ $(document).pjax("a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):no pjaxLoading = false; NProgress.inc(); try{ - if (MathJax !== undefined){ - if (MathJax.Hub !== undefined){ + if (MathJax != undefined){ + if (MathJax.Hub != undefined){ MathJax.Hub.Typeset(); }else{ MathJax.typeset(); @@ -2401,7 +2349,7 @@ $(document).pjax("a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):no } }catch (err){} try{ - if (renderMathInElement !== undefined){ + if (renderMathInElement != undefined){ renderMathInElement(document.body,{ delimiters: [ {left: "$$", right: "$$", display: true}, @@ -2426,7 +2374,7 @@ $(document).pjax("a[href]:not([no-pjax]):not(.no-pjax):not([target='_blank']):no foldLongShuoshuo(); $("html").trigger("resize"); - if (typeof(window.pjaxLoaded) === "function"){ + if (typeof(window.pjaxLoaded) == "function"){ try{ window.pjaxLoaded(); }catch (err){ @@ -2501,7 +2449,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){ initMobileCatalog(); // 如果有文章目录,默认展开 setTimeout(function() { - let catalogSection = $("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section"); + var catalogSection = $("#mobile_catalog_toggle").closest(".leftbar-mobile-collapse-section"); console.log('[Mobile Sidebar] Catalog section found:', catalogSection.length); if (catalogSection.length > 0 && !catalogSection.hasClass("expanded")) { catalogSection.addClass("expanded"); @@ -2523,11 +2471,11 @@ $(document).on("click" , "#blog_categories .tag" , function(){ }); // 移动端侧边栏搜索 $(document).on("keydown" , "#leftbar_mobile_search_input" , function(e){ - if (e.keyCode !== 13){ + if (e.keyCode != 13){ return; } let word = $(this).val(); - if (word === ""){ + if (word == ""){ return; } $("html").removeClass("leftbar-opened"); @@ -2542,15 +2490,15 @@ $(document).on("click" , "#blog_categories .tag" , function(){ // ========== 移动端折叠面板交互 ========== $(document).on("click", ".leftbar-mobile-collapse-header", function(e) { - let section = $(this).closest(".leftbar-mobile-collapse-section"); - let header = $(this); - let isExpanded = section.hasClass("expanded"); + var section = $(this).closest(".leftbar-mobile-collapse-section"); + var header = $(this); + var isExpanded = section.hasClass("expanded"); // 添加点击波纹效果 - let ripple = $(''); - let rect = this.getBoundingClientRect(); - let x = e.clientX - rect.left; - let y = e.clientY - rect.top; + var ripple = $(''); + var rect = this.getBoundingClientRect(); + var x = e.clientX - rect.left; + var y = e.clientY - rect.top; ripple.css({ left: x + 'px', top: y + 'px' @@ -2576,14 +2524,14 @@ $(document).on("click" , "#blog_categories .tag" , function(){ function initMobileCatalog() { console.log('[Mobile Catalog] initMobileCatalog called, initialized:', window.mobileCatalogInitialized); if (window.mobileCatalogInitialized) return; - let $mobileContainer = $("#leftbar_mobile_catalog"); - let $postContent = $("#post_content"); + var $mobileContainer = $("#leftbar_mobile_catalog"); + var $postContent = $("#post_content"); console.log('[Mobile Catalog] Container found:', $mobileContainer.length, 'PostContent found:', $postContent.length); if ($mobileContainer.length === 0) return; if ($postContent.length === 0) return; // 直接生成目录,不依赖 headIndex 插件 - let $headers = $postContent.find('h1, h2, h3, h4, h5, h6'); + var $headers = $postContent.find('h1, h2, h3, h4, h5, h6'); console.log('[Mobile Catalog] Headers found:', $headers.length); if ($headers.length === 0) { $mobileContainer.html('
    暂无目录
    '); @@ -2591,14 +2539,14 @@ $(document).on("click" , "#blog_categories .tag" , function(){ } // 构建目录树 - let toc = []; - let stack = [{ level: 0, children: toc }]; + var toc = []; + var stack = [{ level: 0, children: toc }]; $headers.each(function(index) { - let $h = $(this); - let level = parseInt(this.tagName.charAt(1)); - let text = $h.text().trim(); - let id = $h.attr('id'); + var $h = $(this); + var level = parseInt(this.tagName.charAt(1)); + var text = $h.text().trim(); + var id = $h.attr('id'); // 确保标题有 ID if (!id) { @@ -2606,7 +2554,7 @@ $(document).on("click" , "#blog_categories .tag" , function(){ $h.attr('id', id); } - let item = { id: id, text: text, level: level, children: [] }; + var item = { id: id, text: text, level: level, children: [] }; // 找到合适的父级 while (stack.length > 1 && stack[stack.length - 1].level >= level) { @@ -2619,9 +2567,9 @@ $(document).on("click" , "#blog_categories .tag" , function(){ // 递归生成 HTML function buildHtml(items, isRoot) { if (!items || items.length === 0) return ''; - let html = isRoot ? '