2023-03-21 10:49:35 +08:00

1 line
4.0 KiB
JavaScript

(()=>{const r=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},o=$(".actions>.bullet-screen"),i=()=>{0===$("halo-comment[bullet-screen]").length?o.addClass("is-hidden-all"):o.removeClass("is-hidden-all")},m=(e,n,t)=>{if(n>=e.length)t&&t();else{let o=$(e[n]).attr("src");c.has(o)?m(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(),m(e,n+1,t)}).fail(function(){console.log((t?"同步":"异步")+"顺序加载js失败 "+o),m(e,n+1,t)}))}};$(document).on("click","a[target!=_blank][href]:not(data-not-pjax)",o=>{$.pjax.click(o,".column-main",{scrollTo:"/"!==o.currentTarget.pathname&&0!==$(".banner").length?window.innerHeight/4:0,fragment:".column-main",serialNumber:e(),timeout:8e3})}),$(document).on("submit","form[data-pjax]",function(o){$.pjax.submit(o,".column-main",{scrollTo:0,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(),i(),$("html").removeClass("pjax-loading");const s=$($.parseHTML(e,document,!0)),l=$("head");l.find("meta").remove(),l.append(s.filter("meta")),s.filter("link[data-pjax]").each(function(){let o=$(this).attr("href");r.has(o)||(l.append($(this)),console.log("加载css "+$(this).attr("href")),this.onload=function(){r.add(o),window.DProgress&&DProgress.inc(),console.log("加载css完成 "+$(this).attr("href"))})});let o=s.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(()=>{m(o.filter("[defer]"),0)});let e=o.filter(":not([async]):not([defer])");0<e.length&&await new Promise(o=>{m(e,0,o)})}console.log("全部处理完成"),window.pjaxSerialNumber===a&&(window.journalPjax&&window.journalPjax(a),window.postPjax&&window.postPjax(a),window.photoPjax&&window.photoPjax(a),commonContext.initCarousel(),commonContext.loadMaintain(),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)}),$(document).on("pjax:end",function(o,e,n){console.log("pjax:end sn = "+n.serialNumber),null==e&&(commonContext.initTocAndNotice(),i(),commonContext.initCarousel(),window.DProgress&&DProgress.done(),$("html").removeClass("pjax-loading"))}),$(document).on("pjax:popstate",function(){console.log("pjax:popstate")})})();