hide toc when no titles
This commit is contained in:
parent
d314aa4f85
commit
f6c6469cd6
|
@ -192,6 +192,8 @@
|
|||
var toggleTocElem = document.getElementById('toggle-toc');
|
||||
var singleContentsElem = document.querySelector('.single__contents');
|
||||
var navbar = document.querySelector('.navbar');
|
||||
var tocFlexbox = document.querySelector('.toc__flexbox');
|
||||
var tocFlexboxOuter = document.querySelector('.toc__flexbox--outer');
|
||||
|
||||
window.onscroll = function () {
|
||||
scrollFunction();
|
||||
|
@ -214,8 +216,9 @@
|
|||
navbar.classList.remove('navbar--show');
|
||||
}
|
||||
|
||||
singleContentsElem ?
|
||||
singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function(elem) {
|
||||
if (singleContentsElem) {
|
||||
if (singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").length > 0) {
|
||||
singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (elem) {
|
||||
if (toggleTocElem && !toggleTocElem.checked) {
|
||||
return null;
|
||||
}
|
||||
|
@ -246,7 +249,22 @@
|
|||
}) : null;
|
||||
}
|
||||
}
|
||||
}) : null;
|
||||
});
|
||||
} else {
|
||||
if (tocFlexbox) {
|
||||
tocFlexbox.setAttribute('data-position', '');
|
||||
if (!tocFlexbox.classList.contains('hide')) {
|
||||
tocFlexbox.classList.add('hide');
|
||||
}
|
||||
}
|
||||
if (tocFlexboxOuter) {
|
||||
tocFlexboxOuter.setAttribute('data-position', '');
|
||||
if (!tocFlexboxOuter.classList.contains('hide')) {
|
||||
tocFlexboxOuter.classList.add('hide');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // scroll up
|
||||
if (st < 250) {
|
||||
gttBtn.style.display = "none";
|
||||
|
@ -258,8 +276,9 @@
|
|||
navbar.classList.add('navbar--show');
|
||||
}
|
||||
|
||||
singleContentsElem ?
|
||||
singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function(elem) {
|
||||
if (singleContentsElem) {
|
||||
if (singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").length > 0) {
|
||||
singleContentsElem.querySelectorAll("h1, h2, h3, h4, h5, h6").forEach(function (elem) {
|
||||
if (toggleTocElem && !toggleTocElem.checked) {
|
||||
return null;
|
||||
}
|
||||
|
@ -291,7 +310,17 @@
|
|||
}) : null;
|
||||
}
|
||||
}
|
||||
}) : null;
|
||||
});
|
||||
} else {
|
||||
if (tocFlexbox && !tocFlexbox.classList.contains('hide')) {
|
||||
tocFlexbox.classList.add('hide');
|
||||
}
|
||||
if (tocFlexboxOuter && !tocFlexboxOuter.classList.contains('hide')) {
|
||||
tocFlexboxOuter.classList.add('hide');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if (tableOfContentsElem && document.documentElement.scrollTop < 250) {
|
||||
tableOfContentsElem.querySelector('ul') ?
|
||||
|
|
|
@ -116,6 +116,8 @@
|
|||
var enableToc = JSON.parse({{ $enableToc | jsonify }});
|
||||
var toc = JSON.parse({{ $toc | jsonify }});
|
||||
var hideToc = JSON.parse({{ $hideToc | jsonify }});
|
||||
var tocFlexbox = document.querySelector('.toc__flexbox');
|
||||
var tocFlexboxOuter = document.querySelector('.toc__flexbox--outer');
|
||||
|
||||
if ((enableToc || toc) && document.querySelector('.toc')) {
|
||||
var tableOfContentsElem = document.querySelector('.toc').querySelector('#TableOfContents');
|
||||
|
@ -126,14 +128,16 @@
|
|||
});
|
||||
}) : null;
|
||||
|
||||
tableOfContentsElem.querySelectorAll('a').forEach(function(elem) {
|
||||
elem.addEventListener('click', function() {
|
||||
if (tableOfContentsElem) {
|
||||
if (tableOfContentsElem.querySelectorAll('a').length > 0) {
|
||||
tableOfContentsElem.querySelectorAll('a').forEach(function (elem) {
|
||||
elem.addEventListener('click', function () {
|
||||
var id = elem.getAttribute('id');
|
||||
navbar.classList.remove('navbar--show');
|
||||
navbar.classList.remove('navbar--hide');
|
||||
navbar.classList.add('navbar--hide');
|
||||
|
||||
document.querySelector('.toc').querySelectorAll('a').forEach(function(elem) {
|
||||
document.querySelector('.toc').querySelectorAll('a').forEach(function (elem) {
|
||||
elem.classList.remove('active');
|
||||
});
|
||||
elem.classList.add('active');
|
||||
|
@ -157,6 +161,21 @@
|
|||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
if (tocFlexbox) {
|
||||
tocFlexbox.setAttribute('data-position', '');
|
||||
if (!tocFlexbox.classList.contains('hide')) {
|
||||
tocFlexbox.classList.add('hide');
|
||||
}
|
||||
}
|
||||
if (tocFlexboxOuter) {
|
||||
tocFlexboxOuter.setAttribute('data-position', '');
|
||||
if (!tocFlexboxOuter.classList.contains('hide')) {
|
||||
tocFlexboxOuter.classList.add('hide');
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// toc visibility
|
||||
var toggleTocElem = document.getElementById("toggle-toc");
|
||||
|
|
Loading…
Reference in New Issue