diff --git a/src/js/pjax.js b/src/js/pjax.js index b924e3b..0fed7cb 100644 --- a/src/js/pjax.js +++ b/src/js/pjax.js @@ -196,18 +196,21 @@ $(document).on('pjax:error', function (event, xhr, textStatus, error, options) { $(document).on('pjax:complete', function (event, xhr, textStatus, options) { console.log(`pjax:complete sn = ${options.serialNumber}`) - // 获取当前页面的标题、路径和 URL - const currentTitle = document.title - const currentPath = window.location.pathname - const currentUrl = window.location.href + //启用全局评论 + if (DreamConfig.site_comment) { + // 获取当前页面的标题、路径和 URL + const currentTitle = document.title + const currentPath = window.location.pathname + const currentUrl = window.location.href - if (window.history && window.history.replaceState) { - // 更新历史记录状态 - window.history.replaceState( - { url: currentUrl, title: currentTitle, path: currentPath }, - currentTitle, - currentUrl - ) + if (window.history && window.history.replaceState) { + // 更新历史记录状态 + window.history.replaceState( + {url: currentUrl, title: currentTitle, path: currentPath}, + currentTitle, + currentUrl + ) + } } }) @@ -244,7 +247,8 @@ $(document).on('pjax:popstate', function (event) { // 监听 popstate 事件 window.addEventListener('popstate', function (event) { console.log('popstate event triggered') - if (event.state) { + //启用全局评论时 + if (DreamConfig.site_comment && event.state) { // console.log('State:', event.state) const currentUrl = window.location.href diff --git a/templates/assets/js/pjax.min.js b/templates/assets/js/pjax.min.js index ec1e316..46a0dca 100644 --- a/templates/assets/js/pjax.min.js +++ b/templates/assets/js/pjax.min.js @@ -1 +1 @@ -(()=>{const s=new Set($('link[href*=".css"]').map((o,e)=>$(e).attr("href")).get()),l=new Set($('script[src*=".js"]').map((o,e)=>$(e).attr("src")).get()),e=()=>{var o=(new Date).getTime();return window.pjaxSerialNumber=o,console.log("sn = "+o),o},n=o=>"/"!==o.pathname&&0!==$(".banner").length?(window.initTop=99999999,window.innerHeight/4):0,c=(e,n,t)=>{if(n>=e.length)t&&t();else{let o=$(e[n]).attr("src");l.has(o)?c(e,n+1,t):(console.log((t?"同步":"异步")+"顺序加载js "+o),Utils.cachedScript(o).done(function(){console.log((t?"同步":"异步")+"顺序加载js完成 "+o),l.add(o),window.DProgress&&DProgress.inc(),c(e,n+1,t)}).fail(function(){console.log((t?"同步":"异步")+"顺序加载js失败 "+o),c(e,n+1,t)}))}};$(document).on("click","a[target!=_blank][href]:not([data-not-pjax])",o=>{$.pjax.click(o,".column-main",{scrollTo:n(o.currentTarget),fragment:".column-main",serialNumber:e(),timeout:8e3})}),$(document).on("submit","form[data-pjax]",function(o){$.pjax.submit(o,".column-main",{scrollTo:n(o.currentTarget),fragment:".column-main",serialNumber:e(),timeout:8e3})}),$(document).on("pjax:click",function(o,e){console.log("------------------------"),console.log("pjax:click sn = "+e.serialNumber)}),$(document).on("pjax:beforeSend",function(o,e,n){console.log("pjax:beforeSend sn = "+n.serialNumber),$("html").addClass("pjax-loading")}),$(document).on("pjax:start",function(o,e,n){console.log("pjax:start sn = "+n.serialNumber),window.DProgress&&DProgress.start(),$(".pjax-close").remove()}),$(document).on("pjax:send",function(o,e,n){console.log("pjax:send sn = "+n.serialNumber)}),$(document).on("pjax:clicked",function(o,e){console.log("pjax:clicked sn = "+e.serialNumber)}),$(document).on("pjax:beforeReplace",function(o,e,n){console.log("pjax:beforeReplace sn = "+n.serialNumber),$(".navbar-nav .current,.panel-side-menu .current").removeClass("current"),commonContext.initNavbar(),0<$("html.disable-scroll").length&&$(".navbar-mask").trigger("click")}),$(document).on("pjax:success",async function(o,e,n,t,a){a=a.serialNumber;if(console.log("pjax:success sn = "+a),window.pjaxSerialNumber===a){commonContext.initGallery(),commonContext.initTocAndNotice(),$("html").removeClass("pjax-loading");const i=$($.parseHTML(e,document,!0)),r=$("head");r.find("meta").remove(),r.find('link[rel="canonical"]').remove(),r.append(i.filter("meta")),r.append(i.filter('link[rel="canonical"]')),i.filter("link[data-pjax]").each(function(){let o=$(this).attr("href");s.has(o)||(r.append($(this)),console.log("加载css "+$(this).attr("href")),this.onload=function(){s.add(o),window.DProgress&&DProgress.inc(),console.log("加载css完成 "+$(this).attr("href"))})});let o=i.filter("script[data-pjax]");if(0{c(o.filter("[defer]"),0)});let e=o.filter(":not([async]):not([defer])");0{c(e,0,o)})}console.log("全部处理完成"),window.pjaxSerialNumber===a&&(window.journalPjax&&window.journalPjax(a),window.postPjax&&window.postPjax(a),commonContext.initTimeCount(),commonContext.iniTaskItemDisabled(),commonContext.initCarousel(),commonContext.closeFancybox(),window.DProgress)&&DProgress.done()}}),$(document).on("pjax:timeout",function(o,e,n){console.log("pjax:timeout sn = "+n.serialNumber)}),$(document).on("pjax:error",function(o,e,n,t,a){console.log(`pjax:error sn = ${a.serialNumber} error `+t)}),$(document).on("pjax:complete",function(o,e,n,t){console.log("pjax:complete sn = "+t.serialNumber);var t=document.title,a=window.location.pathname,i=window.location.href;window.history&&window.history.replaceState&&window.history.replaceState({url:i,title:t,path:a},t,i)}),$(document).on("pjax:end",function(o,e,n){console.log("pjax:end sn = "+n.serialNumber),null==e&&(commonContext.initTocAndNotice(),commonContext.initCarousel(),commonContext.initTimeCount(),commonContext.iniTaskItemDisabled(),commonContext.closeFancybox(),window.DProgress&&DProgress.done(),$("html").removeClass("pjax-loading"))}),$(document).on("pjax:popstate",function(o){console.log("pjax:popstate")}),window.addEventListener("popstate",function(o){if(console.log("popstate event triggered"),o.state){const o=window.location.href;$.pjax.reload(".column-main",{container:".column-main",push:!1,url:o,fragment:".column-main",serialNumber:e(),timeout:8e3})}})})(); \ No newline at end of file +(()=>{const s=new Set($('link[href*=".css"]').map((o,e)=>$(e).attr("href")).get()),c=new Set($('script[src*=".js"]').map((o,e)=>$(e).attr("src")).get()),e=()=>{var o=(new Date).getTime();return window.pjaxSerialNumber=o,console.log("sn = "+o),o},n=o=>"/"!==o.pathname&&0!==$(".banner").length?(window.initTop=99999999,window.innerHeight/4):0,l=(e,n,t)=>{if(n>=e.length)t&&t();else{let o=$(e[n]).attr("src");c.has(o)?l(e,n+1,t):(console.log((t?"同步":"异步")+"顺序加载js "+o),Utils.cachedScript(o).done(function(){console.log((t?"同步":"异步")+"顺序加载js完成 "+o),c.add(o),window.DProgress&&DProgress.inc(),l(e,n+1,t)}).fail(function(){console.log((t?"同步":"异步")+"顺序加载js失败 "+o),l(e,n+1,t)}))}};$(document).on("click","a[target!=_blank][href]:not([data-not-pjax])",o=>{$.pjax.click(o,".column-main",{scrollTo:n(o.currentTarget),fragment:".column-main",serialNumber:e(),timeout:8e3})}),$(document).on("submit","form[data-pjax]",function(o){$.pjax.submit(o,".column-main",{scrollTo:n(o.currentTarget),fragment:".column-main",serialNumber:e(),timeout:8e3})}),$(document).on("pjax:click",function(o,e){console.log("------------------------"),console.log("pjax:click sn = "+e.serialNumber)}),$(document).on("pjax:beforeSend",function(o,e,n){console.log("pjax:beforeSend sn = "+n.serialNumber),$("html").addClass("pjax-loading")}),$(document).on("pjax:start",function(o,e,n){console.log("pjax:start sn = "+n.serialNumber),window.DProgress&&DProgress.start(),$(".pjax-close").remove()}),$(document).on("pjax:send",function(o,e,n){console.log("pjax:send sn = "+n.serialNumber)}),$(document).on("pjax:clicked",function(o,e){console.log("pjax:clicked sn = "+e.serialNumber)}),$(document).on("pjax:beforeReplace",function(o,e,n){console.log("pjax:beforeReplace sn = "+n.serialNumber),$(".navbar-nav .current,.panel-side-menu .current").removeClass("current"),commonContext.initNavbar(),0<$("html.disable-scroll").length&&$(".navbar-mask").trigger("click")}),$(document).on("pjax:success",async function(o,e,n,t,a){a=a.serialNumber;if(console.log("pjax:success sn = "+a),window.pjaxSerialNumber===a){commonContext.initGallery(),commonContext.initTocAndNotice(),$("html").removeClass("pjax-loading");const i=$($.parseHTML(e,document,!0)),r=$("head");r.find("meta").remove(),r.find('link[rel="canonical"]').remove(),r.append(i.filter("meta")),r.append(i.filter('link[rel="canonical"]')),i.filter("link[data-pjax]").each(function(){let o=$(this).attr("href");s.has(o)||(r.append($(this)),console.log("加载css "+$(this).attr("href")),this.onload=function(){s.add(o),window.DProgress&&DProgress.inc(),console.log("加载css完成 "+$(this).attr("href"))})});let o=i.filter("script[data-pjax]");if(0{l(o.filter("[defer]"),0)});let e=o.filter(":not([async]):not([defer])");0{l(e,0,o)})}console.log("全部处理完成"),window.pjaxSerialNumber===a&&(window.journalPjax&&window.journalPjax(a),window.postPjax&&window.postPjax(a),commonContext.initTimeCount(),commonContext.iniTaskItemDisabled(),commonContext.initCarousel(),commonContext.closeFancybox(),window.DProgress)&&DProgress.done()}}),$(document).on("pjax:timeout",function(o,e,n){console.log("pjax:timeout sn = "+n.serialNumber)}),$(document).on("pjax:error",function(o,e,n,t,a){console.log(`pjax:error sn = ${a.serialNumber} error `+t)}),$(document).on("pjax:complete",function(o,e,n,t){if(console.log("pjax:complete sn = "+t.serialNumber),DreamConfig.site_comment){const o=document.title,e=window.location.pathname,n=window.location.href;window.history&&window.history.replaceState&&window.history.replaceState({url:n,title:o,path:e},o,n)}}),$(document).on("pjax:end",function(o,e,n){console.log("pjax:end sn = "+n.serialNumber),null==e&&(commonContext.initTocAndNotice(),commonContext.initCarousel(),commonContext.initTimeCount(),commonContext.iniTaskItemDisabled(),commonContext.closeFancybox(),window.DProgress&&DProgress.done(),$("html").removeClass("pjax-loading"))}),$(document).on("pjax:popstate",function(o){console.log("pjax:popstate")}),window.addEventListener("popstate",function(o){if(console.log("popstate event triggered"),DreamConfig.site_comment&&o.state){const o=window.location.href;$.pjax.reload(".column-main",{container:".column-main",push:!1,url:o,fragment:".column-main",serialNumber:e(),timeout:8e3})}})})(); \ No newline at end of file diff --git a/templates/common/config.html b/templates/common/config.html index 194fc39..1eda46b 100644 --- a/templates/common/config.html +++ b/templates/common/config.html @@ -114,6 +114,7 @@ DreamConfig["security_link_url"] = [[${theme.config.security_link_config.security_link_url}]]; DreamConfig["theme_version"] = [[${theme.spec.version}]]; + DreamConfig["site_comment"] = [[${site.comment.enable}]]; DreamConfig["theme_base"] = "[(${#theme.assets('/')})]"; [(${!#strings.isEmpty(theme.config.post.code_fold_line)?'DreamConfig["code_fold_line"] = "' + theme.config.post.code_fold_line + '";': ''})] [(${!#strings.isEmpty(theme.config.basic_info.document_hidden_title)?'DreamConfig["document_hidden_title"] = "' + #strings.escapeJavaScript(theme.config.basic_info.document_hidden_title) + '";': ''})]