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