|
| 1 | +/** |
| 2 | + * Check for elements with a navButton class, which indicates the sidebar has finished loading. |
| 3 | + */ |
| 4 | +async function dispatchNavigationLoadedEvent() { |
| 5 | + while (!document.querySelectorAll('.navButton').length > 0) { |
| 6 | + await new Promise(resolve => setTimeout(resolve, 100)); |
| 7 | + } |
| 8 | + window.dispatchEvent(new Event('navigationLoaded')); |
| 9 | +} |
| 10 | + |
| 11 | +document.addEventListener('DOMContentLoaded', dispatchNavigationLoadedEvent); |
| 12 | +if (document.readyState === "interactive" || document.readyState === "complete" ) { dispatchNavigationLoadedEvent() } |
| 13 | + |
1 | 14 | /** |
2 | 15 | * Apply "skip to main content" buttons after each active left sidebar `sideMenuPart`. |
3 | 16 | * These are invisible and only accessible via keyboard |
@@ -48,9 +61,7 @@ function applySkipLinks() { |
48 | 61 | }; |
49 | 62 | observer.observe(document.body, observerConfig); |
50 | 63 | } |
51 | | -document.addEventListener('DOMContentLoaded', applySkipLinks); |
52 | | -if (document.readyState === "interactive" || document.readyState === "complete" ) { applySkipLinks() } |
53 | | - |
| 64 | +window.addEventListener('navigationLoaded', applySkipLinks); |
54 | 65 |
|
55 | 66 | /** |
56 | 67 | * Ensure `navButton` elements are interactable and have proper accessibility properties |
@@ -89,9 +100,7 @@ function ensureNavButtonInteractable() { |
89 | 100 | }); |
90 | 101 | }); |
91 | 102 | } |
92 | | - |
93 | | -document.addEventListener('DOMContentLoaded', ensureNavButtonInteractable) |
94 | | -if (document.readyState === "interactive" || document.readyState === "complete" ) { ensureNavButtonInteractable() } |
| 103 | +window.addEventListener('navigationLoaded', ensureNavButtonInteractable); |
95 | 104 |
|
96 | 105 | /** |
97 | 106 | * Ensure that content (specifically, code blocks) reflows on small page sizes. |
@@ -143,6 +152,4 @@ function ensureContentReflow() { |
143 | 152 | }); |
144 | 153 | }); |
145 | 154 | } |
146 | | - |
147 | | -document.addEventListener('DOMContentLoaded', ensureContentReflow) |
148 | | -if (document.readyState === "interactive" || document.readyState === "complete" ) { ensureContentReflow() } |
| 155 | +window.addEventListener('navigationLoaded', ensureContentReflow); |
0 commit comments