-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
452 lines (382 loc) · 14.8 KB
/
Copy pathscript.js
File metadata and controls
452 lines (382 loc) · 14.8 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
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
// Navigation Menu Toggle
document.addEventListener('DOMContentLoaded', function() {
const mobileMenu = document.getElementById('mobile-menu');
const navMenu = document.getElementById('nav-menu');
mobileMenu.addEventListener('click', function() {
mobileMenu.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close menu when clicking on a link
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.remove('active');
navMenu.classList.remove('active');
});
});
});
// Smooth Scrolling for Navigation Links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
const navHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = target.offsetTop - navHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
}
});
});
// Back to Top Button
const backToTopButton = document.getElementById('back-to-top');
function toggleBackToTopButton() {
if (window.pageYOffset > 300) {
backToTopButton.classList.add('visible');
} else {
backToTopButton.classList.remove('visible');
}
}
window.addEventListener('scroll', toggleBackToTopButton);
backToTopButton.addEventListener('click', function() {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
// Navbar Background on Scroll
function updateNavbarBackground() {
const navbar = document.querySelector('.navbar');
if (window.pageYOffset > 50) {
navbar.style.backgroundColor = 'rgba(15, 15, 15, 0.98)';
navbar.style.borderBottom = '1px solid #404040';
} else {
navbar.style.backgroundColor = 'rgba(15, 15, 15, 0.95)';
navbar.style.borderBottom = '1px solid #262626';
}
}
window.addEventListener('scroll', updateNavbarBackground);
// Intersection Observer for Animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver(function(entries) {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', function() {
const animatedElements = document.querySelectorAll(
'.overview-card, .detail-card, .usecase-card, .step, .tech-category, .api-section'
);
animatedElements.forEach(element => {
observer.observe(element);
});
});
// Active Navigation Link Highlighting
function updateActiveNavLink() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
let current = '';
const navHeight = document.querySelector('.navbar').offsetHeight;
sections.forEach(section => {
const sectionTop = section.offsetTop - navHeight - 100;
const sectionHeight = section.offsetHeight;
if (window.pageYOffset >= sectionTop &&
window.pageYOffset < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
}
window.addEventListener('scroll', updateActiveNavLink);
// Add active class styles
const style = document.createElement('style');
style.textContent = `
.nav-link.active {
color: var(--text-primary) !important;
background-color: var(--bg-tertiary) !important;
}
`;
document.head.appendChild(style);
// Copy Code Functionality
function addCopyButtons() {
const codeBlocks = document.querySelectorAll('.code-block pre, .code-content pre');
codeBlocks.forEach(block => {
const wrapper = block.parentElement;
wrapper.style.position = 'relative';
const button = document.createElement('button');
button.textContent = 'Copy';
button.className = 'copy-button';
button.style.cssText = `
position: absolute;
top: 10px;
right: 10px;
background: var(--primary);
color: white;
border: none;
padding: 6px 12px;
border-radius: 4px;
font-size: 12px;
cursor: pointer;
opacity: 0;
transition: opacity 0.3s ease;
z-index: 10;
`;
wrapper.appendChild(button);
wrapper.addEventListener('mouseenter', () => {
button.style.opacity = '1';
});
wrapper.addEventListener('mouseleave', () => {
button.style.opacity = '0';
});
button.addEventListener('click', async () => {
try {
await navigator.clipboard.writeText(block.textContent);
button.textContent = 'Copied!';
button.style.background = 'var(--success)';
setTimeout(() => {
button.textContent = 'Copy';
button.style.background = 'var(--primary)';
}, 2000);
} catch (err) {
console.error('Failed to copy code:', err);
button.textContent = 'Failed';
button.style.background = 'var(--error)';
setTimeout(() => {
button.textContent = 'Copy';
button.style.background = 'var(--primary)';
}, 2000);
}
});
});
}
document.addEventListener('DOMContentLoaded', addCopyButtons);
// Search Functionality
function addSearchFeature() {
const searchContainer = document.createElement('div');
searchContainer.className = 'search-container';
searchContainer.style.cssText = `
position: fixed;
top: 80px;
right: 20px;
z-index: 999;
opacity: 0;
visibility: hidden;
transition: all 0.3s ease;
`;
const searchInput = document.createElement('input');
searchInput.type = 'text';
searchInput.placeholder = 'Search documentation...';
searchInput.className = 'search-input';
searchInput.style.cssText = `
width: 300px;
padding: 10px 16px;
border: 1px solid var(--border-primary);
border-radius: 8px;
background: var(--bg-card);
color: var(--text-primary);
font-size: 14px;
outline: none;
`;
searchContainer.appendChild(searchInput);
document.body.appendChild(searchContainer);
// Toggle search with Ctrl+K or Cmd+K
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'k') {
e.preventDefault();
if (searchContainer.style.opacity === '0') {
searchContainer.style.opacity = '1';
searchContainer.style.visibility = 'visible';
searchInput.focus();
} else {
searchContainer.style.opacity = '0';
searchContainer.style.visibility = 'hidden';
searchInput.blur();
}
}
if (e.key === 'Escape') {
searchContainer.style.opacity = '0';
searchContainer.style.visibility = 'hidden';
searchInput.blur();
}
});
// Search functionality
searchInput.addEventListener('input', (e) => {
const query = e.target.value.toLowerCase();
const sections = document.querySelectorAll('section[id]');
if (query.length < 2) return;
sections.forEach(section => {
const text = section.textContent.toLowerCase();
const heading = section.querySelector('h2, h3');
if (text.includes(query) && heading) {
// Highlight the section briefly
section.style.boxShadow = '0 0 20px rgba(59, 130, 246, 0.3)';
setTimeout(() => {
section.style.boxShadow = '';
}, 2000);
// Scroll to section
const navHeight = document.querySelector('.navbar').offsetHeight;
const targetPosition = section.offsetTop - navHeight - 20;
window.scrollTo({
top: targetPosition,
behavior: 'smooth'
});
// Close search
searchContainer.style.opacity = '0';
searchContainer.style.visibility = 'hidden';
searchInput.value = '';
searchInput.blur();
}
});
});
// Close search when clicking outside
document.addEventListener('click', (e) => {
if (!searchContainer.contains(e.target)) {
searchContainer.style.opacity = '0';
searchContainer.style.visibility = 'hidden';
searchInput.blur();
}
});
}
document.addEventListener('DOMContentLoaded', addSearchFeature);
// Theme Switcher (Optional Enhancement)
function addThemeSwitcher() {
const themeButton = document.createElement('button');
themeButton.innerHTML = '🌙';
themeButton.className = 'theme-switcher';
themeButton.style.cssText = `
position: fixed;
top: 20px;
right: 80px;
width: 40px;
height: 40px;
border: none;
border-radius: 50%;
background: var(--bg-tertiary);
color: var(--text-primary);
font-size: 18px;
cursor: pointer;
transition: all 0.3s ease;
z-index: 1001;
border: 1px solid var(--border-primary);
`;
document.body.appendChild(themeButton);
// Theme switching functionality (can be extended for light mode)
themeButton.addEventListener('click', () => {
// Currently only dark theme is implemented
// This can be extended to toggle between light and dark themes
themeButton.style.transform = 'rotate(360deg)';
setTimeout(() => {
themeButton.style.transform = 'rotate(0deg)';
}, 300);
});
themeButton.addEventListener('mouseenter', () => {
themeButton.style.background = 'var(--primary)';
});
themeButton.addEventListener('mouseleave', () => {
themeButton.style.background = 'var(--bg-tertiary)';
});
}
document.addEventListener('DOMContentLoaded', addThemeSwitcher);
// Performance Monitor
function addPerformanceMonitor() {
if ('performance' in window) {
window.addEventListener('load', () => {
const perfData = performance.timing;
const loadTime = perfData.loadEventEnd - perfData.navigationStart;
if (loadTime > 3000) {
console.warn('Page load time is high:', loadTime + 'ms');
}
// Monitor largest contentful paint
if ('PerformanceObserver' in window) {
const observer = new PerformanceObserver((list) => {
const entries = list.getEntries();
const lastEntry = entries[entries.length - 1];
if (lastEntry.renderTime > 2500) {
console.warn('Largest Contentful Paint is slow:', lastEntry.renderTime);
}
});
observer.observe({ entryTypes: ['largest-contentful-paint'] });
}
});
}
}
document.addEventListener('DOMContentLoaded', addPerformanceMonitor);
// Error Handling
window.addEventListener('error', (e) => {
console.error('JavaScript Error:', e.error);
// Optional: Send error to analytics or logging service
// analytics.track('js_error', { message: e.message, filename: e.filename });
});
// Service Worker Registration (if needed for offline functionality)
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
// Uncomment if you want to add a service worker
// navigator.serviceWorker.register('/sw.js')
// .then(registration => console.log('SW registered:', registration))
// .catch(error => console.log('SW registration failed:', error));
});
}
// Accessibility Improvements
function enhanceAccessibility() {
// Add skip link
const skipLink = document.createElement('a');
skipLink.href = '#main-content';
skipLink.textContent = 'Skip to main content';
skipLink.className = 'skip-link';
skipLink.style.cssText = `
position: absolute;
top: -40px;
left: 6px;
background: var(--primary);
color: white;
padding: 8px;
text-decoration: none;
border-radius: 4px;
z-index: 10000;
transition: top 0.3s ease;
`;
skipLink.addEventListener('focus', () => {
skipLink.style.top = '6px';
});
skipLink.addEventListener('blur', () => {
skipLink.style.top = '-40px';
});
document.body.insertBefore(skipLink, document.body.firstChild);
// Add aria-current to active nav links
const navLinks = document.querySelectorAll('.nav-link');
navLinks.forEach(link => {
link.addEventListener('click', () => {
navLinks.forEach(l => l.removeAttribute('aria-current'));
link.setAttribute('aria-current', 'page');
});
});
// Add aria-labels to buttons
const backToTop = document.getElementById('back-to-top');
if (backToTop) {
backToTop.setAttribute('aria-label', 'Go back to top of page');
}
}
document.addEventListener('DOMContentLoaded', enhanceAccessibility);
// Initialize all features
document.addEventListener('DOMContentLoaded', function() {
console.log('📚 Documentation site loaded successfully!');
console.log('💡 Tip: Press Ctrl+K (or Cmd+K) to search the documentation');
// Add main content ID for accessibility
const mainContent = document.querySelector('.main-content');
if (mainContent) {
mainContent.id = 'main-content';
}
});