Skip to content

Commit

Permalink
misc(docs): only run accessibility scripts after the sidebar has full…
Browse files Browse the repository at this point in the history
…y loaded (#1123)
  • Loading branch information
lauzadis authored Jul 15, 2024
1 parent 683ae66 commit 1ae66a0
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions docs/dokka-presets/scripts/accessibility.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
/**
* Check for elements with a navButton class, which indicates the sidebar has finished loading.
*/
async function dispatchNavigationLoadedEvent() {
while (!document.querySelectorAll('.navButton').length > 0) {
await new Promise(resolve => setTimeout(resolve, 100));
}
window.dispatchEvent(new Event('navigationLoaded'));
}

document.addEventListener('DOMContentLoaded', dispatchNavigationLoadedEvent);
if (document.readyState === "interactive" || document.readyState === "complete" ) { dispatchNavigationLoadedEvent() }

/**
* Apply "skip to main content" buttons after each active left sidebar `sideMenuPart`.
* These are invisible and only accessible via keyboard
Expand Down Expand Up @@ -48,9 +61,7 @@ function applySkipLinks() {
};
observer.observe(document.body, observerConfig);
}
document.addEventListener('DOMContentLoaded', applySkipLinks);
if (document.readyState === "interactive" || document.readyState === "complete" ) { applySkipLinks() }

window.addEventListener('navigationLoaded', applySkipLinks);

/**
* Ensure `navButton` elements are interactable and have proper accessibility properties
Expand Down Expand Up @@ -89,9 +100,7 @@ function ensureNavButtonInteractable() {
});
});
}

document.addEventListener('DOMContentLoaded', ensureNavButtonInteractable)
if (document.readyState === "interactive" || document.readyState === "complete" ) { ensureNavButtonInteractable() }
window.addEventListener('navigationLoaded', ensureNavButtonInteractable);

/**
* Ensure that content (specifically, code blocks) reflows on small page sizes.
Expand Down Expand Up @@ -143,6 +152,4 @@ function ensureContentReflow() {
});
});
}

document.addEventListener('DOMContentLoaded', ensureContentReflow)
if (document.readyState === "interactive" || document.readyState === "complete" ) { ensureContentReflow() }
window.addEventListener('navigationLoaded', ensureContentReflow);

0 comments on commit 1ae66a0

Please sign in to comment.