File size: 14,269 Bytes
779c5fe |
1 2 3 4 5 6 7 8 |
document.addEventListener("DOMContentLoaded",function(){let O,S,A,T,C=!1;const B=e=>{if(e){O=document.getElementById("site-name").offsetWidth;const n=document.querySelectorAll("#menus .menus_item");S=0,n.length&&n.forEach(i=>{S+=i.offsetWidth});const o=document.querySelector("#search-button");A=o?o.offsetWidth:0,T=document.getElementById("nav")}let t="";window.innerWidth<768?t=!0:t=O+S+A>T.offsetWidth-120,t?T.classList.add("hide-menu"):T.classList.remove("hide-menu")},F=()=>{B(!0),T.classList.add("show")},I={open:()=>{btf.sidebarPaddingR(),document.body.style.overflow="hidden",btf.animateIn(document.getElementById("menu-mask"),"to_show 0.5s"),document.getElementById("sidebar-menus").classList.add("open"),C=!0},close:()=>{const e=document.body;e.style.overflow="",e.style.paddingRight="",btf.animateOut(document.getElementById("menu-mask"),"to_hide 0.5s"),document.getElementById("sidebar-menus").classList.remove("open"),C=!1}},N=()=>{const e=document.getElementById("scroll-down");e&&e.addEventListener("click",function(){btf.scrollToDest(document.getElementById("content-inner").offsetTop,300)})},x=function(){const e=GLOBAL_CONFIG.highlight;if(!e)return;const t=e.highlightCopy,n=e.highlightLang,o=GLOBAL_CONFIG_SITE.isHighlightShrink,i=e.highlightHeightLimit,l=t||n||o!==void 0,f=e.plugin==="highlighjs"?document.querySelectorAll("figure.highlight"):document.querySelectorAll('pre[class*="language-"]');if(!((l||i)&&f.length))return;const L=e.plugin==="prismjs";let m="",u="";const v=o===!0?"closed":"";o!==void 0&&(m=`<i class="fas fa-angle-down expand ${v}"></i>`),t&&(u='<div class="copy-notice"></div><i class="fas fa-paste copy-button"></i>');const g=(c,s)=>{if(document.queryCommandSupported&&document.queryCommandSupported("copy"))if(document.execCommand("copy"),GLOBAL_CONFIG.Snackbar!==void 0)btf.snackbarShow(GLOBAL_CONFIG.copy.success);else{const a=s.previousElementSibling;a.innerText=GLOBAL_CONFIG.copy.success,a.style.opacity=1,setTimeout(()=>{a.style.opacity=0},700)}else GLOBAL_CONFIG.Snackbar!==void 0?btf.snackbarShow(GLOBAL_CONFIG.copy.noSupport):s.previousElementSibling.innerText=GLOBAL_CONFIG.copy.noSupport},E=c=>{const s=c.parentNode;s.classList.add("copy-true");const a=window.getSelection(),b=document.createRange();L?b.selectNodeContents(s.querySelectorAll("pre code")[0]):b.selectNodeContents(s.querySelectorAll("table .code pre")[0]),a.removeAllRanges(),a.addRange(b);const y=a.toString();g(y,c.lastChild),a.removeAllRanges(),s.classList.remove("copy-true")},h=c=>{const s=[...c.parentNode.children].slice(1);c.firstChild.classList.toggle("closed"),btf.isHidden(s[s.length-1])?s.forEach(a=>{a.style.display="block"}):s.forEach(a=>{a.style.display="none"})},r=function(c){const s=c.target.classList;s.contains("expand")?h(this):s.contains("copy-button")&&E(this)},d=function(){this.classList.toggle("expand-done")};function p(c,s,a){const b=document.createDocumentFragment();if(l){const y=document.createElement("div");y.className=`highlight-tools ${v}`,y.innerHTML=m+c+u,y.addEventListener("click",r),b.appendChild(y)}if(i&&s.offsetHeight>i+30){const y=document.createElement("div");y.className="code-expand-btn",y.innerHTML='<i class="fas fa-angle-double-down"></i>',y.addEventListener("click",d),b.appendChild(y)}a==="hl"?s.insertBefore(b,s.firstChild):s.parentNode.insertBefore(b,s)}n?L?f.forEach(function(c){const a=`<div class="code-lang">${c.getAttribute("data-language")?c.getAttribute("data-language"):"Code"}</div>`;btf.wrap(c,"figure",{class:"highlight"}),p(a,c)}):f.forEach(function(c){let s=c.getAttribute("class").split(" ")[1];(s==="plain"||s===void 0)&&(s="Code");const a=`<div class="code-lang">${s}</div>`;p(a,c,"hl")}):L?f.forEach(function(c){btf.wrap(c,"figure",{class:"highlight"}),p("",c)}):f.forEach(function(c){p("",c,"hl")})};function $(){document.querySelectorAll("#article-container img").forEach(function(e){const t=e.parentNode,n=e.title||e.alt;if(n&&!t.parentNode.classList.contains("justified-gallery")){const o=document.createElement("div");o.className="img-alt is-center",o.textContent=n,t.insertBefore(o,e.nextSibling)}})}const _=()=>{btf.loadLightbox(document.querySelectorAll("#article-container img:not(.no-lightbox)"))},D=function(e){if(e.forEach(n=>{n.querySelectorAll("img").forEach(i=>{const l=i.getAttribute("data-lazy-src");l&&(i.src=l),btf.wrap(i,"div",{class:"fj-gallery-item"})})}),window.fjGallery){setTimeout(()=>{btf.initJustifiedGallery(e)},100);return}const t=document.createElement("link");t.rel="stylesheet",t.href=GLOBAL_CONFIG.source.justifiedGallery.css,document.body.appendChild(t),getScript(`${GLOBAL_CONFIG.source.justifiedGallery.js}`).then(()=>{btf.initJustifiedGallery(e)})},H=function(){const e=document.getElementById("rightside"),t=window.innerHeight+56;if(document.body.scrollHeight<=t){e.style.cssText="opacity: 1; transform: translateX(-58px)";return}function n(m){const u=m>o;return o=m,u}let o=0,i=!0;const l=document.getElementById("page-header"),f=typeof chatBtnHide=="function",L=typeof chatBtnShow=="function";l.classList.add("nav-fixed"),l.classList.add("nav-visible"),window.scrollCollect=()=>btf.throttle(function(m){const u=window.scrollY||document.documentElement.scrollTop,v=n(u);l.classList.add("nav-fixed"),l.classList.add("nav-visible"),u>0?(v?(l.classList.contains("nav-visible")&&l.classList.add("nav-visible"),L&&i===!0&&(chatBtnHide(),i=!1)):(l.classList.contains("nav-visible")||l.classList.add("nav-visible"),f&&i===!1&&(chatBtnShow(),i=!0)),l.classList.add("nav-fixed"),window.getComputedStyle(e).getPropertyValue("opacity")==="0"&&(e.style.cssText="opacity: 1; transform: translateX(-58px)")):(u===0&&l.classList.remove("nav-fixed","nav-visible"),e.style.cssText="opacity: ''; transform: ''"),document.body.scrollHeight<=t&&(e.style.cssText="opacity: 1; transform: translateX(-58px)")},200)(),window.addEventListener("scroll",scrollCollect)},q=function(){const e=GLOBAL_CONFIG_SITE.isToc,t=GLOBAL_CONFIG.isAnchor,n=document.getElementById("article-container");if(!(n&&(e||t)))return;let o,i,l,f,L;if(e){const g=document.getElementById("card-toc");i=g.getElementsByClassName("toc-content")[0],o=i.querySelectorAll(".toc-link");const E=g.querySelector(".toc-percentage");L=i.classList.contains("is-expand"),l=h=>{const r=n.clientHeight,d=document.documentElement.clientHeight,p=n.offsetTop,c=r>d?r-d:document.documentElement.scrollHeight-d,s=(h-p)/c,a=Math.round(s*100),b=a>100?100:a<=0?0:a;E.textContent=b},window.mobileToc={open:()=>{g.style.cssText="animation: toc-open .3s; opacity: 1; right: 55px"},close:()=>{g.style.animation="toc-close .2s",setTimeout(()=>{g.style.cssText="opacity:''; animation: ''; right: ''"},100)}},i.addEventListener("click",h=>{h.preventDefault();const r=h.target.classList;if(r.contains("toc-content"))return;const d=r.contains("toc-link")?h.target:h.target.parentElement;btf.scrollToDest(btf.getEleTop(document.getElementById(decodeURI(d.getAttribute("href")).replace("#",""))),300),window.innerWidth<900&&window.mobileToc.close()}),f=h=>{const r=h.getBoundingClientRect().top,d=i.scrollTop;r>document.documentElement.clientHeight-100&&(i.scrollTop=d+150),r<100&&(i.scrollTop=d-150)}}const m=n.querySelectorAll("h1,h2,h3,h4,h5,h6");let u="";const v=function(g){if(g===0)return!1;let E="",h="";if(m.forEach(function(r,d){if(g>btf.getEleTop(r)-80){const p=r.id;E=p?"#"+encodeURI(p):"",h=d}}),u!==h&&(t&&btf.updateAnchor(E),u=h,e)){if(i.querySelectorAll(".active").forEach(p=>{p.classList.remove("active")}),E==="")return;const r=o[h];if(r.classList.add("active"),setTimeout(()=>{f(r)},0),L)return;let d=r.parentNode;for(;!d.matches(".toc");d=d.parentNode)d.matches("li")&&d.classList.add("active")}};window.tocScrollFn=function(){return btf.throttle(function(){const g=window.scrollY||document.documentElement.scrollTop;e&&l(g),v(g)},100)()},window.addEventListener("scroll",tocScrollFn)},w={switchReadMode:()=>{const e=document.body;e.classList.add("read-mode");const t=document.createElement("button");t.type="button",t.className="fas fa-sign-out-alt exit-readmode",e.appendChild(t);function n(){e.classList.remove("read-mode"),t.remove(),t.removeEventListener("click",n)}t.addEventListener("click",n)},switchDarkMode:()=>{(document.documentElement.getAttribute("data-theme")==="dark"?"dark":"light")==="light"?(activateDarkMode(),saveToLocal.set("theme","dark",2),GLOBAL_CONFIG.Snackbar!==void 0&&btf.snackbarShow(GLOBAL_CONFIG.Snackbar.day_to_night)):(activateLightMode(),saveToLocal.set("theme","light",2),GLOBAL_CONFIG.Snackbar!==void 0&&btf.snackbarShow(GLOBAL_CONFIG.Snackbar.night_to_day)),typeof utterancesTheme=="function"&&utterancesTheme(),typeof changeGiscusTheme=="function"&&changeGiscusTheme(),typeof FB=="object"&&window.loadFBComment(),window.DISQUS&&document.getElementById("disqus_thread").children.length&&setTimeout(()=>window.disqusReset(),200),typeof runMermaid=="function"&&window.runMermaid()},showOrHideBtn:e=>{const t=document.getElementById("rightside-config-hide").classList;t.toggle("show"),e.classList.contains("show")&&(t.add("status"),setTimeout(()=>{t.remove("status")},300)),e.classList.toggle("show")},scrollToTop:()=>{btf.scrollToDest(0,500)},hideAsideBtn:()=>{const e=document.documentElement.classList;e.contains("hide-aside")?saveToLocal.set("aside-status","show",2):saveToLocal.set("aside-status","hide",2),e.toggle("hide-aside")},runMobileToc:()=>{window.getComputedStyle(document.getElementById("card-toc")).getPropertyValue("opacity")==="0"?window.mobileToc.open():window.mobileToc.close()}};document.getElementById("rightside").addEventListener("click",function(e){const t=e.target.id?e.target:e.target.parentNode;switch(t.id){case"go-up":w.scrollToTop();break;case"rightside_config":w.showOrHideBtn(t);break;case"mobile-toc-button":w.runMobileToc();break;case"readmode":w.switchReadMode();break;case"darkmode":w.switchDarkMode();break;case"hide-aside-btn":w.hideAsideBtn();break;default:break}});const P=()=>{document.querySelectorAll("#sidebar-menus .site-page.group").forEach(function(e){e.addEventListener("click",function(){this.classList.toggle("hide")})})},M=()=>{const e=GLOBAL_CONFIG.copyright;document.body.oncopy=t=>{t.preventDefault();let n;const o=window.getSelection(0).toString();return o.length>e.limitCount?n=o+`
`+e.languages.author+`
`+e.languages.link+window.location.href+`
`+e.languages.source+`
`+e.languages.info:n=o,t.clipboardData?t.clipboardData.setData("text",n):window.clipboardData.setData("text",n)}},j=()=>{const e=document.getElementById("runtimeshow");if(e){const t=e.getAttribute("data-publishDate");e.innerText=btf.diffDate(t)+" "+GLOBAL_CONFIG.runtime}},R=()=>{const e=document.getElementById("last-push-date");if(e){const t=e.getAttribute("data-lastPushDate");e.innerText=btf.diffDate(t,!0)}},W=()=>{const e=document.querySelectorAll("#article-container :not(.highlight) > table, #article-container > table");e.length&&e.forEach(t=>{btf.wrap(t,"div",{class:"table-wrap"})})},z=function(){const e=document.querySelectorAll("#article-container .hide-button");e.length&&e.forEach(function(t){t.addEventListener("click",function(n){const o=this;o.classList.add("open");const i=o.nextElementSibling.querySelectorAll(".fj-gallery");i.length&&btf.initJustifiedGallery(i)})})},G={clickFnOfTabs:function(){document.querySelectorAll("#article-container .tab > button").forEach(function(e){e.addEventListener("click",function(t){const n=this,o=n.parentNode;if(!o.classList.contains("active")){const i=o.parentNode.nextElementSibling,l=btf.siblings(o,".active")[0];l&&l.classList.remove("active"),o.classList.add("active");const f=n.getAttribute("data-href").replace("#","");[...i.children].forEach(u=>{u.id===f?u.classList.add("active"):u.classList.remove("active")});const m=i.querySelectorAll(`#${f} .fj-gallery`);m.length>0&&btf.initJustifiedGallery(m)}})})},backToTop:()=>{document.querySelectorAll("#article-container .tabs .tab-to-top").forEach(function(e){e.addEventListener("click",function(){btf.scrollToDest(btf.getEleTop(btf.getParents(this,".tabs")),300)})})}},J=function(){const e=document.querySelectorAll("#aside-cat-list .card-category-list-item.parent i");e.length&&e.forEach(function(t){t.addEventListener("click",function(n){n.preventDefault();const o=this;o.classList.toggle("expand");const i=o.parentNode.nextElementSibling;btf.isHidden(i)?i.style.display="block":i.style.display="none"})})},U=function(){let e=!1;const t=document.querySelector("#comment-switch > .switch-btn");t&&t.addEventListener("click",function(){this.classList.toggle("move"),document.querySelectorAll("#post-comment > .comment-wrap > div").forEach(function(n){btf.isHidden(n)?n.style.cssText="display: block;animation: tabshow .5s":n.style.cssText="display: none;animation: ''"}),!e&&typeof loadOtherComment=="function"&&(e=!0,loadOtherComment())})},V=function(){const e=GLOBAL_CONFIG.noticeOutdate,t=btf.diffDate(GLOBAL_CONFIG_SITE.postUpdate);if(t>=e.limitDay){const n=document.createElement("div");n.className="post-outdate-notice",n.textContent=e.messagePrev+" "+t+" "+e.messageNext;const o=document.getElementById("article-container");e.position==="top"?o.insertBefore(n,o.firstChild):o.appendChild(n)}},X=()=>{window.lazyLoadInstance=new LazyLoad({elements_selector:"img",threshold:0,data_src:"lazy-src"})},k=function(e){e.forEach(t=>{const n=t,o=n.getAttribute("datetime");n.innerText=btf.diffDate(o,!0),n.style.display="inline"})},Y=function(){window.addEventListener("resize",()=>{B(!1),btf.isHidden(document.getElementById("toggle-menu"))&&C&&I.close()}),document.getElementById("menu-mask").addEventListener("click",e=>{I.close()}),P(),GLOBAL_CONFIG.islazyload&&X(),GLOBAL_CONFIG.copyright!==void 0&&M()};window.refreshFn=function(){F(),GLOBAL_CONFIG_SITE.isPost?(GLOBAL_CONFIG.noticeOutdate!==void 0&&V(),GLOBAL_CONFIG.relativeDate.post&&k(document.querySelectorAll("#post-meta time"))):(GLOBAL_CONFIG.relativeDate.homepage&&k(document.querySelectorAll("#recent-posts time")),GLOBAL_CONFIG.runtime&&j(),R(),J()),q(),GLOBAL_CONFIG_SITE.isHome&&N(),x(),GLOBAL_CONFIG.isPhotoFigcaption&&$(),H();const e=document.querySelectorAll("#article-container .fj-gallery");e.length&&D(e),_(),W(),z(),G.clickFnOfTabs(),G.backToTop(),U(),document.getElementById("toggle-menu").addEventListener("click",()=>{I.open()})},refreshFn(),Y()});
|