LoveIt/static/js/theme.min.js

3 lines
7.3 KiB
JavaScript
Raw Normal View History

2020-02-18 10:52:19 +01:00
"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,
2020-02-16 17:41:08 +01:00
//# sourceMappingURL=theme.min.js.map