-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
280 lines (248 loc) · 10 KB
/
script.js
File metadata and controls
280 lines (248 loc) · 10 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
// Theme Management
(function() {
const THEME_KEY = 'aidevops-theme';
const themeToggle = document.getElementById('themeToggle');
// Get initial theme from localStorage or system preference
function getInitialTheme() {
const savedTheme = localStorage.getItem(THEME_KEY);
if (savedTheme) {
return savedTheme;
}
// Check system preference
if (window.matchMedia && window.matchMedia('(prefers-color-scheme: light)').matches) {
return 'light';
}
return 'dark';
}
// Apply theme to document
function applyTheme(theme) {
document.documentElement.setAttribute('data-theme', theme);
localStorage.setItem(THEME_KEY, theme);
}
// Initialize theme on page load
applyTheme(getInitialTheme());
// Toggle theme on button click
if (themeToggle) {
themeToggle.addEventListener('click', () => {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'dark' ? 'light' : 'dark';
applyTheme(newTheme);
});
}
// Listen for system preference changes
if (window.matchMedia) {
window.matchMedia('(prefers-color-scheme: dark)').addEventListener('change', (e) => {
// Only apply if user hasn't manually set a preference
if (!localStorage.getItem(THEME_KEY)) {
applyTheme(e.matches ? 'dark' : 'light');
}
});
}
})();
// Clone Install Box — single source of truth for install commands
// The hero section (#install-box-source) is the canonical install component.
// The CTA section (#install-box-clone) receives a deep clone so commands
// only need to be updated in one place. IDs are re-prefixed with "cta-"
// and ARIA cross-references (aria-controls, aria-labelledby) are updated
// to point at the new IDs, keeping both tab widgets independently accessible.
(function() {
const source = document.getElementById('install-box-source');
const target = document.getElementById('install-box-clone');
if (!source || !target) return;
const clone = source.cloneNode(true);
const PREFIX = 'cta-';
// Re-prefix IDs and update ARIA cross-references in a single pass
clone.removeAttribute('id');
clone.querySelectorAll('[id], [aria-controls], [aria-labelledby]').forEach((el) => {
if (el.id) {
el.id = PREFIX + el.id;
}
if (el.hasAttribute('aria-controls')) {
el.setAttribute('aria-controls', PREFIX + el.getAttribute('aria-controls'));
}
if (el.hasAttribute('aria-labelledby')) {
el.setAttribute('aria-labelledby', PREFIX + el.getAttribute('aria-labelledby'));
}
});
target.replaceWith(clone);
})();
// Install Tabs — WAI-ARIA tabs pattern with keyboard navigation
// Implements roving tabindex, Arrow Left/Right (wrapping), Home/End,
// and Enter/Space activation per WAI-ARIA Authoring Practices.
// Scoped per install-box so hero and CTA clones operate independently.
(function() {
document.querySelectorAll('.install-box').forEach((box) => {
const tabs = Array.from(box.querySelectorAll('.install-tab'));
const panels = box.querySelectorAll('.install-panel');
// Activate a tab: update ARIA state, roving tabindex, panels, and focus
const activateTab = (tab, moveFocus) => {
const targetPanel = tab.dataset.tab;
// Deactivate all tabs in this box
tabs.forEach((t) => {
t.classList.remove('active');
t.setAttribute('aria-selected', 'false');
t.setAttribute('tabindex', '-1');
});
// Activate the target tab
tab.classList.add('active');
tab.setAttribute('aria-selected', 'true');
tab.setAttribute('tabindex', '0');
// Switch panels and update aria-hidden
panels.forEach((p) => {
const isTarget = p.dataset.panel === targetPanel;
p.classList.toggle('active', isTarget);
if (isTarget) {
p.removeAttribute('aria-hidden');
} else {
p.setAttribute('aria-hidden', 'true');
}
});
if (moveFocus) {
tab.focus();
}
};
// Click handler — activate on click (mouse or implicit Enter/Space on button)
tabs.forEach((tab) => {
tab.addEventListener('click', () => {
activateTab(tab, false);
});
});
// Keyboard handler on the tablist for arrow navigation
const tablist = box.querySelector('[role="tablist"]');
if (tablist) {
tablist.addEventListener('keydown', (e) => {
const currentIndex = tabs.indexOf(e.target);
if (currentIndex === -1) return;
let nextIndex;
switch (e.key) {
case 'ArrowRight':
nextIndex = (currentIndex + 1) % tabs.length;
break;
case 'ArrowLeft':
nextIndex = (currentIndex - 1 + tabs.length) % tabs.length;
break;
case 'Home':
nextIndex = 0;
break;
case 'End':
nextIndex = tabs.length - 1;
break;
default:
return; // Let other keys propagate normally
}
e.preventDefault();
activateTab(tabs[nextIndex], true);
});
}
});
})();
// Copy to Clipboard
(function() {
function setupCopyButton(button) {
if (!button) return;
button.addEventListener('click', async () => {
const command = button.dataset.command;
try {
await navigator.clipboard.writeText(command);
showCopied(button);
} catch (err) {
// Fallback for older browsers
const textarea = document.createElement('textarea');
textarea.value = command;
textarea.style.position = 'fixed';
textarea.style.opacity = '0';
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
showCopied(button);
}
});
}
function showCopied(button) {
button.classList.add('copied');
setTimeout(() => {
button.classList.remove('copied');
}, 2000);
}
// Setup install command buttons (includes cloned CTA buttons)
document.querySelectorAll('.install-command').forEach(setupCopyButton);
})();
// Auto-generate heading IDs and smooth scroll for anchor links
(function() {
// Generate GitHub-style slug from heading text
// GitHub preserves consecutive dashes (e.g. " - " becomes "---")
const slugify = (text) => {
return text
.toLowerCase()
.trim()
.replace(/[^\w\s-]/g, '')
.replace(/\s+/g, '-')
.replace(/^-|-$/g, '');
};
// Add id attributes to all headings that don't have one.
// Uses DOM-based uniqueness check to avoid duplicate IDs when a heading's
// text naturally produces a slug matching a previous duplicate's suffixed
// slug (e.g. headings "My Title", "My Title", "My Title-2").
document.querySelectorAll('.docs-content h1, .docs-content h2, .docs-content h3, .docs-content h4').forEach((heading) => {
if (heading.id) return;
const baseSlug = slugify(heading.textContent);
if (!baseSlug) return;
let slug = baseSlug;
let counter = 1;
while (document.getElementById(slug)) {
slug = `${baseSlug}-${counter++}`;
}
heading.id = slug;
});
// Smooth scroll for anchor links, update URL hash
document.querySelectorAll('a[href^="#"]').forEach((anchor) => {
anchor.addEventListener('click', (e) => {
const href = anchor.getAttribute('href');
if (href === '#') {
e.preventDefault();
window.scrollTo({ top: 0, behavior: 'smooth' });
history.replaceState(null, '', window.location.pathname);
return;
}
const target = document.getElementById(href.slice(1));
if (target) {
e.preventDefault();
target.scrollIntoView({ behavior: 'smooth', block: 'start' });
history.replaceState(null, '', href);
}
});
});
// On page load, scroll to hash target after all resources (CSS, images)
// are loaded so layout is stable and scrollIntoView positions correctly.
window.addEventListener('load', () => {
if (window.location.hash) {
const hashTarget = document.getElementById(window.location.hash.slice(1));
if (hashTarget) {
hashTarget.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
}
});
})();
// Add intersection observer for fade-in animations
(function() {
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
}
});
}, observerOptions);
// Observe feature cards and service categories
document.querySelectorAll('.feature-card, .service-category').forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.5s ease, transform 0.5s ease';
observer.observe(el);
});
})();