From fd4f885946ba546a8bab6ca9978fe35719408208 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 2 Jul 2024 10:24:43 -0400 Subject: [PATCH] Small cleanup --- docs/dokka-presets/templates/base.ftl | 32 ++++++++++----------------- 1 file changed, 12 insertions(+), 20 deletions(-) diff --git a/docs/dokka-presets/templates/base.ftl b/docs/dokka-presets/templates/base.ftl index a9df316acb7..d46a585446e 100644 --- a/docs/dokka-presets/templates/base.ftl +++ b/docs/dokka-presets/templates/base.ftl @@ -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) { @@ -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); }); @@ -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")) @@ -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); }