Skip to content

Commit

Permalink
Small cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
lauzadis committed Jul 2, 2024
1 parent 9ee4f5f commit fd4f885
Showing 1 changed file with 12 additions and 20 deletions.
32 changes: 12 additions & 20 deletions docs/dokka-presets/templates/base.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@
}
}
const observerConfig = {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['class']
};
function handleChanges(mutationsList) {
for (const mutation of mutationsList) {
if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
Expand All @@ -70,9 +63,14 @@
}
}
}
// Create a MutationObserver with the callback function
const observer = new MutationObserver(handleChanges);
// Start observing changes in the document
const observerConfig = {
childList: true,
subtree: true,
attributes: true,
attributeFilter: ['class']
};
observer.observe(document.body, observerConfig);
});
Expand All @@ -86,7 +84,7 @@
navButton.setAttribute('role', 'button');
navButton.setAttribute('aria-expanded', 'false');
// Grab the grandparent element's page ID, use it for aria-label and aria-controls
// Grab the page ID, use it for aria-label and aria-controls
const sectionName = navButton.parentElement.parentElement.getAttribute('pageid')
// Remove the page ID suffix auto-generated by Dokka
const cleanedSectionName = sectionName.substring(0, sectionName.indexOf("////PointingToDeclaration"))
Expand Down Expand Up @@ -129,22 +127,16 @@
toggleContent.setAttribute('aria-label', 'Toggle code block for' + element.getAttribute("data-togglable"));
toggleContent.setAttribute('aria-controls', element.id);
if (!initiallyVisible) {
element.style.display = 'none';
}
// Set initial visibility based on window size
element.style.display = initiallyVisible ? 'block' : 'none'
// Toggle visibility onclick
toggleContent.onclick = function() {
const isExpanded = toggleContent.getAttribute('aria-expanded') === 'true';
toggleContent.setAttribute('aria-expanded', (!isExpanded).toString());
if (isExpanded) {
element.style.display = 'none';
} else {
element.style.display = 'block';
}
element.style.display = isExpanded ? 'none' : 'block'
};
// Insert the hamburger button before the content element
element.parentNode.insertBefore(toggleContent, element);
}
Expand Down

0 comments on commit fd4f885

Please sign in to comment.