-
Notifications
You must be signed in to change notification settings - Fork 44
Expand file tree
/
Copy pathexpand-nav.js
More file actions
91 lines (80 loc) · 2.19 KB
/
expand-nav.js
File metadata and controls
91 lines (80 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
// Expand all navigation folders on page load
(function () {
'use strict';
function expandAllNavigation() {
// Find all details elements in various navigation contexts
const selectors = [
'.tsd-navigation details',
'#tsd-nav-container details',
'.site-menu details',
'.tsd-accordion',
'nav details',
];
let foundAny = false;
selectors.forEach((selector) => {
const elements = document.querySelectorAll(selector);
if (elements.length > 0) {
foundAny = true;
elements.forEach((el) => {
if (el.tagName === 'DETAILS') {
el.open = true;
}
});
}
});
return foundAny;
}
// Strategy 1: Try immediately
expandAllNavigation();
// Strategy 2: Hook into TypeDoc's app if available
let checkCount = 0;
const maxChecks = 50; // Check for up to 5 seconds
function checkAndExpand() {
checkCount++;
if (expandAllNavigation()) {
// Keep expanding even if found, in case more navigation loads
if (checkCount < maxChecks) {
setTimeout(checkAndExpand, 100);
}
} else if (checkCount < maxChecks) {
setTimeout(checkAndExpand, 100);
}
}
// Strategy 3: MutationObserver for dynamic content
// eslint-disable-next-line no-undef
const observer = new MutationObserver(() => {
expandAllNavigation();
});
// Strategy 4: Multiple event listeners
window.addEventListener('load', () => {
expandAllNavigation();
checkAndExpand();
// Start observing after page load
const navContainer = document.querySelector(
'#tsd-nav-container, .site-menu'
);
if (navContainer) {
observer.observe(navContainer, {
childList: true,
subtree: true,
});
}
});
// Strategy 5: Check for TypeDoc's app initialization
if (window.app) {
expandAllNavigation();
} else {
Object.defineProperty(window, 'app', {
configurable: true,
set: function (value) {
delete window.app;
window.app = value;
setTimeout(expandAllNavigation, 100);
setTimeout(expandAllNavigation, 500);
},
get: function () {
return window._app;
},
});
}
})();