From 16b7302269622b0f183c7093678dff2faf3ddb44 Mon Sep 17 00:00:00 2001 From: Matas Lauzadis Date: Tue, 2 Jul 2024 11:08:12 -0400 Subject: [PATCH] cleanup --- docs/dokka-presets/scripts/accessibility.js | 32 ++++++++++++++------- 1 file changed, 21 insertions(+), 11 deletions(-) diff --git a/docs/dokka-presets/scripts/accessibility.js b/docs/dokka-presets/scripts/accessibility.js index 8522b9ba3b8..0ce01eed3b4 100644 --- a/docs/dokka-presets/scripts/accessibility.js +++ b/docs/dokka-presets/scripts/accessibility.js @@ -1,7 +1,8 @@ -// Fix for accessibiliy violation: "Provide a mechanism for skipping past repetitive content" -document.addEventListener('DOMContentLoaded', applySkipLinks); -if (document.readyState === "interactive" || document.readyState === "complete" ) { applySkipLinks() } - +/** + * Apply "skip to main content" buttons after each active left sidebar `sideMenuPart`. + * These are invisible and only accessible via keyboard + * Fix for accessibility violation: "Provide a mechanism for skipping past repetitive content" + */ function applySkipLinks() { console.log("DOMContentLoaded") function insertSkipLink(element) { @@ -25,10 +26,7 @@ function applySkipLinks() { function handleChanges(mutationsList) { for (const mutation of mutationsList) { if (mutation.type === 'attributes' && mutation.target.classList.contains('sideMenuPart') && !mutation.target.classList.contains('hidden')) { - // Handle changes in the 'class' attribute of existing elements - // Check if the element is 'sideMenuPart' and not 'hidden' insertSkipLink(mutation.target); - console.log("Inserting skip link on mutation.target: " + mutation.target.id) } } @@ -45,12 +43,17 @@ function applySkipLinks() { attributes: true, attributeFilter: ['class'] }; - console.log("observing for changes") observer.observe(document.body, observerConfig); } +document.addEventListener('DOMContentLoaded', applySkipLinks); +if (document.readyState === "interactive" || document.readyState === "complete" ) { applySkipLinks() } -// Fix for accessibilty violation: "Ensure all interactive functionality is operable with the keyboard" -window.onload = function() { + +/** + * Ensure `navButton` elements are interactable and have proper accessibility properties + * Fix for accessibilty violation: "Ensure all interactive functionality is operable with the keyboard" + */ +function ensureNavButtonInteractable() { const navButtons = document.querySelectorAll('.navButton'); navButtons.forEach(function(navButton) { @@ -84,8 +87,15 @@ window.onload = function() { }); } -// Fix for accessibility violation: "Ensure pages reflow without requiring two-dimensional scrolling without loss of content or functionality" +window.onload = function() { + ensureNavButtonInteractable() +} +// +/** + * Ensure that content (specifically, code blocks) reflows on small page sizes. + * Fix for accessibility violation: "Ensure pages reflow without requiring two-dimensional scrolling without loss of content or functionality" + */ function ensureContentReflow() { const MIN_WINDOW_SIZE = 550