未验证 提交 16320fa9 编写于 作者: D Dillon 提交者: GitHub

Merge pull request #80 from dillonzq/fix/toc_script

fix(toc): fix toc script bug
......@@ -147,7 +147,7 @@
initToc() {
const tocContainer = document.getElementById('post-toc');
if (tocContainer !== null) {
const toc = tocContainer.getElementById('TableOfContents');
const toc = document.getElementById('TableOfContents');
if (toc === null) {
tocContainer.parentElement.removeChild(tocContainer);
} else {
......
"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}(function(){'use strict';var a=/*#__PURE__*/function(){function a(){_classCallCheck(this,a)}return _createClass(a,[{key:"forEach",value:function forEach(a,b){a=a||[];for(var c=0;c<a.length;c++)b(a[c])}},{key:"getScrollTop",value:function getScrollTop(){return document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop}}]),a}(),b=/*#__PURE__*/function(){function b(){_classCallCheck(this,b),this.util=new a,this.scrollTop=0,this.scrollEvents=[]}return _createClass(b,[{key:"initMobileMenu",value:function initMobileMenu(){document.getElementById("menu-toggle").onclick=function(){document.getElementById("menu-toggle").classList.toggle("active"),document.getElementById("menu-mobile").classList.toggle("active")}}},{key:"initSwitchTheme",value:function initSwitchTheme(){var a=this;this.util.forEach(document.getElementsByClassName("theme-switch"),function(b){b.onclick=function(){document.body.classList.toggle("dark-theme"),window.isDark=!window.isDark,window.localStorage&&window.localStorage.setItem("theme",window.isDark?"dark":"light"),a.initEcharts()}})}},{key:"initHighlight",value:function initHighlight(){this.util.forEach(document.querySelectorAll(".highlight > .chroma"),function(a){var b=a.querySelectorAll("pre.chroma > code"),c=b[b.length-1],d=c?c.className.toLowerCase():"";a.className+=" "+d}),this.util.forEach(document.querySelectorAll(".highlight > pre.chroma"),function(a){var b=document.createElement("div");b.className=a.className;var c=document.createElement("table");b.appendChild(c);var d=document.createElement("tbody");c.appendChild(d);var e=document.createElement("tr");d.appendChild(e);var f=document.createElement("td");e.appendChild(f),a.parentElement.replaceChild(b,a),f.appendChild(a)})}},{key:"initTable",value:function initTable(){this.util.forEach(document.querySelectorAll(".content table"),function(a){var b=document.createElement("div");b.className="table-wrapper",a.parentElement.replaceChild(b,a),b.appendChild(a)})}},{key:"initHeaderLink",value:function initHeaderLink(){for(var a=1;6>=a;a++)this.util.forEach(document.querySelectorAll(".content > h"+a),function(a){a.classList.add("headerLink"),a.innerHTML="<a href=\"#".concat(a.id,"\"></a>").concat(a.innerHTML)})}},{key:"_refactorToc",value:function _refactorToc(a){this.util.forEach(a.querySelectorAll("a:first-child"),function(a){a.classList.add("toc-link")})}},{key:"_initTocState",value:function _initTocState(a){var b=this;if("none"!==window.getComputedStyle(a,null).display){var c="normal"!==window.desktopHeaderMode,d=document.getElementById("header-desktop").getBoundingClientRect().height,e=20+(c?d:0),f=a.offsetTop,g=f-e+(c?0:d),h=document.getElementById("post-footer").offsetTop,j=a.getElementsByClassName("toc-link"),k=document.getElementsByClassName("headerLink")||[],l=a.querySelectorAll(".post-toc-content li"),m=5+(c?d:0),n=function(){var n=b.util.getScrollTop(),o=h-a.getBoundingClientRect().height,p=o-e+(c?0:d);n<g?(a.style.position="absolute",a.style.top="".concat(f,"px")):n>p?(a.style.position="absolute",a.style.top="".concat(o,"px")):(a.style.position="fixed",a.style.top="".concat(e,"px")),b.util.forEach(j,function(a){a.classList.remove("active")}),b.util.forEach(l,function(a){a.classList.remove("has-active")});for(var q=k.length-1,r=0;r<k.length-1;r++){var s=k[r].getBoundingClientRect().top,t=k[r+1].getBoundingClientRect().top;if(0==r&&s>m||s<=m&&t>m){q=r;break}}if(-1!==q){j[q].classList.add("active");for(var u=j[q].parentElement;"NAV"!==u.tagName;)u.classList.add("has-active"),u=u.parentElement.parentElement}};n(),this._initTocOnce||(this.scrollEvents.push(n),this._initTocOnce=!0)}}},{key:"initToc",value:function initToc(){var a=this,b=document.getElementById("post-toc");if(null!==b){var c=b.getElementById("TableOfContents");null===c?b.parentElement.removeChild(b):(this._refactorToc(c),this._initTocState(b),window.addEventListener("resize",function(){window.setTimeout(function(){a._initTocState(b)},0)},!1))}}},{key:"initMermaid",value:function initMermaid(){window.mermaidMap&&(mermaid.initialize({startOnLoad:!1,theme:null}),Object.keys(mermaidMap).forEach(function(a){var b=document.getElementById(a);mermaid.mermaidAPI.render("d"+a,mermaidMap[a],function(a){b.innerHTML=a;var c=b.firstChild;c.style.width="100%"},b)}))}},{key:"initEcharts",value:function initEcharts(){if(window.echartsMap){for(var a=0;a<echartsArr.length;a++)echartsArr[a].dispose();echartsArr=[],Object.keys(echartsMap).forEach(function(a){var b=echarts.init(document.getElementById(a),window.isDark?"dark":"macarons",{renderer:"svg"});b.setOption(echartsMap[a]),echartsArr.push(b)}),window.addEventListener("resize",function(){this.setTimeout(function(){for(var a=0;a<echartsArr.length;a++)echartsArr[a].resize()},0)},!1)}}},{key:"initTypeit",value:function initTypeit(){if(window.typeitArr)for(var a=function(a){var b=typeitArr[a];(function a(c){var d=document.getElementById("r".concat(b[c])).innerHTML;if(c===b.length-1)return void new TypeIt("#".concat(b[c]),{strings:d}).go();var e=new TypeIt("#".concat(b[c]),{strings:d,afterComplete:function afterComplete(){e.destroy(),a(c+1)}}).go()})(0)},b=0;b<typeitArr.length;b++)a(b)}},{key:"initScroll",value:function initScroll(){for(var a=this,b=0;b<this.scrollEvents.length;b++)document.addEventListener("scroll",this.scrollEvents[b],!1);var c=function(){var a=window.matchMedia("only screen and (max-width: 560px)").matches;!a&&"normal"===window.desktopHeaderMode||a&&"normal"===window.mobileHeaderMode?new SmoothScroll("[href^=\"#\"]",{speed:300,speedAsDuration:!0}):new SmoothScroll("[href^=\"#\"]",{speed:300,speedAsDuration:!0,header:"#header-desktop"})};c(),window.addEventListener("resize",function(){window.setTimeout(function(){c()},0)},!1);var d=[];"auto"===window.desktopHeaderMode&&d.push(document.getElementById("header-desktop")),"auto"===window.mobileHeaderMode&&d.push(document.getElementById("header-mobile")),this.util.forEach(d,function(a){a.classList.add("animated"),a.classList.add("faster")});var e=document.getElementById("dynamic-to-top");document.addEventListener("scroll",function(){var b=a.util.getScrollTop();a.util.forEach(d,function(c){a.scrollTop<b?!c.classList.contains("fadeOutUp")&&(c.classList.remove("fadeInDown"),c.classList.add("fadeOutUp")):!c.classList.contains("fadeInDown")&&(c.classList.remove("fadeOutUp"),c.classList.add("fadeInDown")),600<b?a.scrollTop<b?!e.classList.contains("fadeOut")&&(e.classList.remove("fadeIn"),e.classList.add("fadeOut")):(e.style.display="block",!e.classList.contains("fadeIn")&&(e.classList.remove("fadeOut"),e.classList.add("fadeIn"))):e.style.display="none"}),a.scrollTop=b},!1)}},{key:"init",value:function init(){this.initMobileMenu(),this.initSwitchTheme(),this.initHighlight(),this.initTable(),this.initHeaderLink(),this.initMermaid(),this.initEcharts(),this.initTypeit(),this.initToc(),this.initScroll()}}]),b}(),c=function(){var a=new b;a.init()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c,!1):c()})();
"use strict";function _classCallCheck(a,b){if(!(a instanceof b))throw new TypeError("Cannot call a class as a function")}function _defineProperties(a,b){for(var c,d=0;d<b.length;d++)c=b[d],c.enumerable=c.enumerable||!1,c.configurable=!0,"value"in c&&(c.writable=!0),Object.defineProperty(a,c.key,c)}function _createClass(a,b,c){return b&&_defineProperties(a.prototype,b),c&&_defineProperties(a,c),a}(function(){'use strict';var a=/*#__PURE__*/function(){function a(){_classCallCheck(this,a)}return _createClass(a,[{key:"forEach",value:function forEach(a,b){a=a||[];for(var c=0;c<a.length;c++)b(a[c])}},{key:"getScrollTop",value:function getScrollTop(){return document.documentElement&&document.documentElement.scrollTop||document.body.scrollTop}}]),a}(),b=/*#__PURE__*/function(){function b(){_classCallCheck(this,b),this.util=new a,this.scrollTop=0,this.scrollEvents=[]}return _createClass(b,[{key:"initMobileMenu",value:function initMobileMenu(){document.getElementById("menu-toggle").onclick=function(){document.getElementById("menu-toggle").classList.toggle("active"),document.getElementById("menu-mobile").classList.toggle("active")}}},{key:"initSwitchTheme",value:function initSwitchTheme(){var a=this;this.util.forEach(document.getElementsByClassName("theme-switch"),function(b){b.onclick=function(){document.body.classList.toggle("dark-theme"),window.isDark=!window.isDark,window.localStorage&&window.localStorage.setItem("theme",window.isDark?"dark":"light"),a.initEcharts()}})}},{key:"initHighlight",value:function initHighlight(){this.util.forEach(document.querySelectorAll(".highlight > .chroma"),function(a){var b=a.querySelectorAll("pre.chroma > code"),c=b[b.length-1],d=c?c.className.toLowerCase():"";a.className+=" "+d}),this.util.forEach(document.querySelectorAll(".highlight > pre.chroma"),function(a){var b=document.createElement("div");b.className=a.className;var c=document.createElement("table");b.appendChild(c);var d=document.createElement("tbody");c.appendChild(d);var e=document.createElement("tr");d.appendChild(e);var f=document.createElement("td");e.appendChild(f),a.parentElement.replaceChild(b,a),f.appendChild(a)})}},{key:"initTable",value:function initTable(){this.util.forEach(document.querySelectorAll(".content table"),function(a){var b=document.createElement("div");b.className="table-wrapper",a.parentElement.replaceChild(b,a),b.appendChild(a)})}},{key:"initHeaderLink",value:function initHeaderLink(){for(var a=1;6>=a;a++)this.util.forEach(document.querySelectorAll(".content > h"+a),function(a){a.classList.add("headerLink"),a.innerHTML="<a href=\"#".concat(a.id,"\"></a>").concat(a.innerHTML)})}},{key:"_refactorToc",value:function _refactorToc(a){this.util.forEach(a.querySelectorAll("a:first-child"),function(a){a.classList.add("toc-link")})}},{key:"_initTocState",value:function _initTocState(a){var b=this;if("none"!==window.getComputedStyle(a,null).display){var c="normal"!==window.desktopHeaderMode,d=document.getElementById("header-desktop").getBoundingClientRect().height,e=20+(c?d:0),f=a.offsetTop,g=f-e+(c?0:d),h=document.getElementById("post-footer").offsetTop,j=a.getElementsByClassName("toc-link"),k=document.getElementsByClassName("headerLink")||[],l=a.querySelectorAll(".post-toc-content li"),m=5+(c?d:0),n=function(){var n=b.util.getScrollTop(),o=h-a.getBoundingClientRect().height,p=o-e+(c?0:d);n<g?(a.style.position="absolute",a.style.top="".concat(f,"px")):n>p?(a.style.position="absolute",a.style.top="".concat(o,"px")):(a.style.position="fixed",a.style.top="".concat(e,"px")),b.util.forEach(j,function(a){a.classList.remove("active")}),b.util.forEach(l,function(a){a.classList.remove("has-active")});for(var q=k.length-1,r=0;r<k.length-1;r++){var s=k[r].getBoundingClientRect().top,t=k[r+1].getBoundingClientRect().top;if(0==r&&s>m||s<=m&&t>m){q=r;break}}if(-1!==q){j[q].classList.add("active");for(var u=j[q].parentElement;"NAV"!==u.tagName;)u.classList.add("has-active"),u=u.parentElement.parentElement}};n(),this._initTocOnce||(this.scrollEvents.push(n),this._initTocOnce=!0)}}},{key:"initToc",value:function initToc(){var a=this,b=document.getElementById("post-toc");if(null!==b){var c=document.getElementById("TableOfContents");null===c?b.parentElement.removeChild(b):(this._refactorToc(c),this._initTocState(b),window.addEventListener("resize",function(){window.setTimeout(function(){a._initTocState(b)},0)},!1))}}},{key:"initMermaid",value:function initMermaid(){window.mermaidMap&&(mermaid.initialize({startOnLoad:!1,theme:null}),Object.keys(mermaidMap).forEach(function(a){var b=document.getElementById(a);mermaid.mermaidAPI.render("d"+a,mermaidMap[a],function(a){b.innerHTML=a;var c=b.firstChild;c.style.width="100%"},b)}))}},{key:"initEcharts",value:function initEcharts(){if(window.echartsMap){for(var a=0;a<echartsArr.length;a++)echartsArr[a].dispose();echartsArr=[],Object.keys(echartsMap).forEach(function(a){var b=echarts.init(document.getElementById(a),window.isDark?"dark":"macarons",{renderer:"svg"});b.setOption(echartsMap[a]),echartsArr.push(b)}),window.addEventListener("resize",function(){this.setTimeout(function(){for(var a=0;a<echartsArr.length;a++)echartsArr[a].resize()},0)},!1)}}},{key:"initTypeit",value:function initTypeit(){if(window.typeitArr)for(var a=function(a){var b=typeitArr[a];(function a(c){var d=document.getElementById("r".concat(b[c])).innerHTML;if(c===b.length-1)return void new TypeIt("#".concat(b[c]),{strings:d}).go();var e=new TypeIt("#".concat(b[c]),{strings:d,afterComplete:function afterComplete(){e.destroy(),a(c+1)}}).go()})(0)},b=0;b<typeitArr.length;b++)a(b)}},{key:"initScroll",value:function initScroll(){for(var a=this,b=0;b<this.scrollEvents.length;b++)document.addEventListener("scroll",this.scrollEvents[b],!1);var c=function(){var a=window.matchMedia("only screen and (max-width: 560px)").matches;!a&&"normal"===window.desktopHeaderMode||a&&"normal"===window.mobileHeaderMode?new SmoothScroll("[href^=\"#\"]",{speed:300,speedAsDuration:!0}):new SmoothScroll("[href^=\"#\"]",{speed:300,speedAsDuration:!0,header:"#header-desktop"})};c(),window.addEventListener("resize",function(){window.setTimeout(function(){c()},0)},!1);var d=[];"auto"===window.desktopHeaderMode&&d.push(document.getElementById("header-desktop")),"auto"===window.mobileHeaderMode&&d.push(document.getElementById("header-mobile")),this.util.forEach(d,function(a){a.classList.add("animated"),a.classList.add("faster")});var e=document.getElementById("dynamic-to-top");document.addEventListener("scroll",function(){var b=a.util.getScrollTop();a.util.forEach(d,function(c){a.scrollTop<b?!c.classList.contains("fadeOutUp")&&(c.classList.remove("fadeInDown"),c.classList.add("fadeOutUp")):!c.classList.contains("fadeInDown")&&(c.classList.remove("fadeOutUp"),c.classList.add("fadeInDown")),600<b?a.scrollTop<b?!e.classList.contains("fadeOut")&&(e.classList.remove("fadeIn"),e.classList.add("fadeOut")):(e.style.display="block",!e.classList.contains("fadeIn")&&(e.classList.remove("fadeOut"),e.classList.add("fadeIn"))):e.style.display="none"}),a.scrollTop=b},!1)}},{key:"init",value:function init(){this.initMobileMenu(),this.initSwitchTheme(),this.initHighlight(),this.initTable(),this.initHeaderLink(),this.initMermaid(),this.initEcharts(),this.initTypeit(),this.initToc(),this.initScroll()}}]),b}(),c=function(){var a=new b;a.init()};"loading"===document.readyState?document.addEventListener("DOMContentLoaded",c,!1):c()})();
//# sourceMappingURL=theme.min.js.map
\ No newline at end of file
此差异已折叠。
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册