clean the expand-nav implementation up a bit
parent
924be4c7d8
commit
a088f648b1
|
@ -2,16 +2,22 @@ document.querySelector('.navframe').addEventListener('load', function() {
|
||||||
// Get the current page URL without the suffix after #
|
// Get the current page URL without the suffix after #
|
||||||
var currentPageURL = window.location.href.split('#')[0];
|
var currentPageURL = window.location.href.split('#')[0];
|
||||||
|
|
||||||
// Get all detail elements
|
// Get all anchor tags
|
||||||
var as = document.querySelector('.navframe').contentWindow.document.body.querySelectorAll('a');
|
var as = document.querySelector('.navframe').contentWindow.document.body.querySelectorAll('a');
|
||||||
for (const a of as) {
|
for (const a of as) {
|
||||||
if (a.href) {
|
if (a.href) {
|
||||||
var href = a.href.split('#')[0];
|
var href = a.href.split('#')[0];
|
||||||
|
// find the one with the current url
|
||||||
if (href === currentPageURL) {
|
if (href === currentPageURL) {
|
||||||
a.style.fontStyle = 'italic';
|
a.style.fontStyle = 'italic';
|
||||||
|
// open all detail tags above the current
|
||||||
var el = a.parentNode.closest('details');
|
var el = a.parentNode.closest('details');
|
||||||
while (el) {
|
while (el) {
|
||||||
el.open = true;
|
el.open = true;
|
||||||
el = el.parentNode.closest('details');
|
el = el.parentNode.closest('details');
|
||||||
}}}}
|
}}
|
||||||
|
// seeing as we found the link we were looking for, stop
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue