mirror of
https://ghfast.top/https://github.com/zsjy/halo-theme-dream2.0-plus.git
synced 2025-03-15 20:09:41 +08:00
优化站点设置关闭评论并且启用pjax时,浏览器前进后退不执行pjax重载
This commit is contained in:
parent
3ebac82706
commit
74664a5e4b
@ -196,18 +196,21 @@ $(document).on('pjax:error', function (event, xhr, textStatus, error, options) {
|
|||||||
$(document).on('pjax:complete', function (event, xhr, textStatus, options) {
|
$(document).on('pjax:complete', function (event, xhr, textStatus, options) {
|
||||||
console.log(`pjax:complete sn = ${options.serialNumber}`)
|
console.log(`pjax:complete sn = ${options.serialNumber}`)
|
||||||
|
|
||||||
// 获取当前页面的标题、路径和 URL
|
//启用全局评论
|
||||||
const currentTitle = document.title
|
if (DreamConfig.site_comment) {
|
||||||
const currentPath = window.location.pathname
|
// 获取当前页面的标题、路径和 URL
|
||||||
const currentUrl = window.location.href
|
const currentTitle = document.title
|
||||||
|
const currentPath = window.location.pathname
|
||||||
|
const currentUrl = window.location.href
|
||||||
|
|
||||||
if (window.history && window.history.replaceState) {
|
if (window.history && window.history.replaceState) {
|
||||||
// 更新历史记录状态
|
// 更新历史记录状态
|
||||||
window.history.replaceState(
|
window.history.replaceState(
|
||||||
{ url: currentUrl, title: currentTitle, path: currentPath },
|
{url: currentUrl, title: currentTitle, path: currentPath},
|
||||||
currentTitle,
|
currentTitle,
|
||||||
currentUrl
|
currentUrl
|
||||||
)
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
@ -244,7 +247,8 @@ $(document).on('pjax:popstate', function (event) {
|
|||||||
// 监听 popstate 事件
|
// 监听 popstate 事件
|
||||||
window.addEventListener('popstate', function (event) {
|
window.addEventListener('popstate', function (event) {
|
||||||
console.log('popstate event triggered')
|
console.log('popstate event triggered')
|
||||||
if (event.state) {
|
//启用全局评论时
|
||||||
|
if (DreamConfig.site_comment && event.state) {
|
||||||
// console.log('State:', event.state)
|
// console.log('State:', event.state)
|
||||||
|
|
||||||
const currentUrl = window.location.href
|
const currentUrl = window.location.href
|
||||||
|
2
templates/assets/js/pjax.min.js
vendored
2
templates/assets/js/pjax.min.js
vendored
@ -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<o.length){o.filter("[async]").each(function(){let o=$(this).attr("src");l.has(o)||(console.log("异步无序加载js "+o),Utils.cachedScript(o).done(function(){console.log("异步无序js完成 "+o),window.DProgress&&DProgress.inc(),l.add(o)}).fail(function(){console.log("异步无序js失败 "+o)}))}),new Promise(()=>{c(o.filter("[defer]"),0)});let e=o.filter(":not([async]):not([defer])");0<e.length&&await new Promise(o=>{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})}})})();
|
(()=>{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<o.length){o.filter("[async]").each(function(){let o=$(this).attr("src");c.has(o)||(console.log("异步无序加载js "+o),Utils.cachedScript(o).done(function(){console.log("异步无序js完成 "+o),window.DProgress&&DProgress.inc(),c.add(o)}).fail(function(){console.log("异步无序js失败 "+o)}))}),new Promise(()=>{l(o.filter("[defer]"),0)});let e=o.filter(":not([async]):not([defer])");0<e.length&&await new Promise(o=>{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})}})})();
|
@ -114,6 +114,7 @@
|
|||||||
DreamConfig["security_link_url"] = [[${theme.config.security_link_config.security_link_url}]];
|
DreamConfig["security_link_url"] = [[${theme.config.security_link_config.security_link_url}]];
|
||||||
|
|
||||||
DreamConfig["theme_version"] = [[${theme.spec.version}]];
|
DreamConfig["theme_version"] = [[${theme.spec.version}]];
|
||||||
|
DreamConfig["site_comment"] = [[${site.comment.enable}]];
|
||||||
DreamConfig["theme_base"] = "[(${#theme.assets('/')})]";
|
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.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) + '";': ''})]
|
[(${!#strings.isEmpty(theme.config.basic_info.document_hidden_title)?'DreamConfig["document_hidden_title"] = "' + #strings.escapeJavaScript(theme.config.basic_info.document_hidden_title) + '";': ''})]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user