diff options
author | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2017-10-12 23:01:06 +0800 |
---|---|---|
committer | olOwOlo <26087907+olOwOlo@users.noreply.github.com> | 2017-10-12 23:01:06 +0800 |
commit | 0ba82dd1768e941a5c7014b47a5eacaaefcc4f58 (patch) | |
tree | 5028ec809874af388fe88a70df4cd49c8322e876 /src | |
parent | 3483df9d839671bfd944fdaec6145ef87a54cdec (diff) |
feat: only init toc when there are headings
release 2.6.3
Diffstat (limited to 'src')
-rw-r--r-- | src/js/even.js | 18 | ||||
-rw-r--r-- | src/js/main.js | 1 | ||||
-rw-r--r-- | src/package.json | 2 |
3 files changed, 17 insertions, 4 deletions
diff --git a/src/js/even.js b/src/js/even.js index 8aa8459..87494c4 100644 --- a/src/js/even.js +++ b/src/js/even.js @@ -48,7 +48,7 @@ Even.mobileNavbar = function () { }) } -Even.toc = function () { +Even._initToc = function () { var SPACING = 20 var $toc = $('.post-toc') var $footer = $('.post-footer') @@ -152,7 +152,21 @@ Even.highlight = function () { } } -Even.beforeToc = function () { +Even.toc = function () { + const tocContainer = document.getElementById('post-toc') + if (tocContainer !== null) { + const toc = document.getElementById('TableOfContents') + if (toc === null) { + // toc = true, but there are no headings + tocContainer.parentNode.removeChild(tocContainer) + } else { + this._linkToc() + this._initToc() + } + } +} + +Even._linkToc = function () { const links = document.querySelectorAll('#TableOfContents a') for (let i = 0; i < links.length; i++) links[i].className += ' toc-link' diff --git a/src/js/main.js b/src/js/main.js index 6539cf2..1764dfd 100644 --- a/src/js/main.js +++ b/src/js/main.js @@ -5,7 +5,6 @@ import '../css/style.scss' $(document).ready(function () { Even.backToTop() Even.mobileNavbar() - Even.beforeToc() Even.toc() Even.fancybox() }) diff --git a/src/package.json b/src/package.json index d44cdaa..2a9fa73 100644 --- a/src/package.json +++ b/src/package.json @@ -1,6 +1,6 @@ { "name": "even-src", - "version": "2.6.2", + "version": "2.6.3", "description": "even source file", "main": "index.js", "scripts": { |