-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs-navigation.js
More file actions
164 lines (144 loc) · 5.06 KB
/
docs-navigation.js
File metadata and controls
164 lines (144 loc) · 5.06 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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
// Tab switching functionality
function switchTab(tabId) {
// Hide all tab contents
document.querySelectorAll('.tab-content').forEach(content => {
content.classList.remove('active');
content.style.display = 'none';
});
// Hide all sidebars
document.querySelectorAll('.sidebar-section').forEach(sidebar => {
sidebar.style.display = 'none';
});
// Show selected tab content
const selectedTab = document.getElementById(tabId);
if (selectedTab) {
selectedTab.classList.add('active');
selectedTab.style.display = 'block';
// Show the first content section (overview) of the tab
const firstSection = selectedTab.querySelector('.content-section');
if (firstSection) {
showSection(firstSection.id);
}
}
// Show corresponding sidebar
const sidebar = document.getElementById('sidebar-' + tabId);
if (sidebar) {
sidebar.style.display = 'block';
// Reset sidebar active states
sidebar.querySelectorAll('.sidebar-link').forEach(link => {
link.classList.remove('active');
});
sidebar.querySelector('.sidebar-link').classList.add('active');
}
// Update main navigation active state
document.querySelectorAll('.nav-menu a').forEach(link => {
link.classList.remove('active');
const href = link.getAttribute('href');
if (href && href.includes('#' + tabId)) {
link.classList.add('active');
}
});
// Scroll to top
window.scrollTo({ top: 0, behavior: 'smooth' });
}
// Show specific section within a tab
function showSection(sectionId) {
// Get the parent tab
const section = document.getElementById(sectionId);
if (!section) return;
const parentTab = section.closest('.tab-content');
if (!parentTab) return;
// Hide all sections in this tab
parentTab.querySelectorAll('.content-section').forEach(s => {
s.style.display = 'none';
});
// Show selected section
section.style.display = 'block';
// Update sidebar active state
const sidebarId = 'sidebar-' + parentTab.id;
const sidebar = document.getElementById(sidebarId);
if (sidebar) {
sidebar.querySelectorAll('.sidebar-link').forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === '#' + sectionId) {
link.classList.add('active');
}
});
}
// Scroll to top of main content
const docsMain = document.querySelector('.docs-main');
if (docsMain) {
docsMain.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
// Initialize navigation menu links for tab switching
document.querySelectorAll('.nav-menu a[href*="#phase"]').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const href = link.getAttribute('href');
const hash = href.split('#')[1];
if (hash) {
switchTab(hash);
// Update URL without page reload
history.pushState(null, '', href);
}
});
});
// Initialize sidebar links
document.querySelectorAll('.sidebar-link').forEach(link => {
link.addEventListener('click', (e) => {
e.preventDefault();
const href = link.getAttribute('href');
if (href && href.startsWith('#')) {
const sectionId = href.substring(1);
showSection(sectionId);
}
});
});
// Initialize navigation buttons within content
document.addEventListener('click', (e) => {
// Handle links to sections
if (e.target.matches('a[href^="#"]')) {
e.preventDefault();
const href = e.target.getAttribute('href');
if (href && href.length > 1) {
const sectionId = href.substring(1);
showSection(sectionId);
}
}
});
// Handle browser back/forward buttons
window.addEventListener('popstate', () => {
const hash = window.location.hash;
if (hash && hash.length > 1) {
const sectionId = hash.substring(1);
// Determine which tab this section belongs to
const section = document.getElementById(sectionId);
if (section) {
const parentTab = section.closest('.tab-content');
if (parentTab) {
switchTab(parentTab.id);
setTimeout(() => showSection(sectionId), 100);
}
}
}
});
// Initialize on page load
document.addEventListener('DOMContentLoaded', () => {
// Check for hash in URL
const hash = window.location.hash;
if (hash && hash.length > 1) {
const sectionId = hash.substring(1);
const section = document.getElementById(sectionId);
if (section) {
const parentTab = section.closest('.tab-content');
if (parentTab) {
switchTab(parentTab.id);
setTimeout(() => showSection(sectionId), 100);
return;
}
}
}
// Default: show first tab and overview
switchTab('phase1');
});