From 8ccb48fd937619db64e28d62a87b0ea38337429c Mon Sep 17 00:00:00 2001 From: zzossig Date: Sun, 26 Jan 2020 21:05:58 +0900 Subject: [PATCH] toc folding bug fix --- layouts/partials/head/scripts.html | 11 +++++++---- layouts/partials/script/single-script.html | 17 ++++++----------- 2 files changed, 13 insertions(+), 15 deletions(-) diff --git a/layouts/partials/head/scripts.html b/layouts/partials/head/scripts.html index 36931f1..9992671 100644 --- a/layouts/partials/head/scripts.html +++ b/layouts/partials/head/scripts.html @@ -268,12 +268,14 @@ tocElem.querySelector('a[href="#' + id + '"]') ? tocElem.querySelector('a[href="#' + id + '"]').classList.add('active') : null; - tableOfContentsElem.querySelector('ul') ? - tableOfContentsElem.querySelector('ul').querySelectorAll('li').forEach(function (liElem) { + tableOfContentsElem.querySelectorAll('ul') ? + tableOfContentsElem.querySelectorAll('ul').forEach(function (rootUl) { + rootUl.querySelectorAll('li').forEach(function (liElem) { liElem.querySelectorAll('ul').forEach(function (ulElem) { ulElem.style.display = 'none'; }); - }) : null; + }); + }) : null; var curElem = tableOfContentsElem.querySelector("[href='#" + id + "']"); if (curElem && curElem.nextElementSibling) { @@ -332,13 +334,14 @@ tocElem.querySelector('a[href="#' + id + '"]') ? tocElem.querySelector('a[href="#' + id + '"]').classList.add('active') : null; + tableOfContentsElem.querySelectorAll('ul') ? tableOfContentsElem.querySelectorAll('ul').forEach(function (rootUl) { rootUl.querySelectorAll('li').forEach(function (liElem) { liElem.querySelectorAll('ul').forEach(function (ulElem) { ulElem.style.display = 'none'; }); }); - }); + }) : null; var curElem = tableOfContentsElem.querySelector("[href='#" + id + "']"); if (curElem && curElem.nextElementSibling) { diff --git a/layouts/partials/script/single-script.html b/layouts/partials/script/single-script.html index 4a1f157..f115020 100644 --- a/layouts/partials/script/single-script.html +++ b/layouts/partials/script/single-script.html @@ -121,10 +121,12 @@ if ((enableToc || toc) && document.querySelector('.toc')) { var tableOfContentsElem = document.querySelector('.toc').querySelector('#TableOfContents'); - tableOfContentsElem.querySelector('ul') ? - tableOfContentsElem.querySelector('ul').querySelectorAll('li').forEach(function (liElem) { - liElem.querySelectorAll('ul').forEach(function (ulElem) { - ulElem.style.display = 'none'; + tableOfContentsElem.querySelectorAll('ul') ? + tableOfContentsElem.querySelectorAll('ul').forEach(function (rootUl) { + rootUl.querySelectorAll('li').forEach(function (liElem) { + liElem.querySelectorAll('ul').forEach(function (ulElem) { + ulElem.style.display = 'none'; + }); }); }) : null; @@ -142,13 +144,6 @@ }); elem.classList.add('active'); - tableOfContentsElem.querySelector('ul') ? - tableOfContentsElem.querySelector('ul').querySelectorAll('li').forEach(function (liElem) { - liElem.querySelectorAll('ul').forEach(function (ulElem) { - ulElem.style.display = 'none'; - }); - }) : null; - var curElem = tableOfContentsElem.querySelector('[href="#' + id + '"]'); if (curElem && curElem.nextElementSibling) { curElem.nextElementSibling.style.display = 'block';