-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain JavaScript File.code.javascript
More file actions
69 lines (62 loc) · 2.18 KB
/
Main JavaScript File.code.javascript
File metadata and controls
69 lines (62 loc) · 2.18 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
// js/main.js
import { initAnimations, initParallax } from './modules/animations.js';
import { initNavbar } from './modules/navbar.js';
import { initStats, updateLiveStats } from './modules/stats.js';
import { copyToClipboard, showToast, formatNumber, debounce } from './modules/utils.js';
// Initialize all modules when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
// Initialize core functionality
initNavbar();
initAnimations();
initParallax();
initStats();
updateLiveStats();
// Initialize copy buttons
document.querySelectorAll('[data-copy]').forEach(button => {
button.addEventListener('click', () => {
const textToCopy = button.getAttribute('data-copy');
copyToClipboard(textToCopy);
});
});
// Initialize lazy loading for images
const lazyImages = document.querySelectorAll('img[loading="lazy"]');
if ('loading' in HTMLImageElement.prototype) {
lazyImages.forEach(img => {
img.src = img.dataset.src;
});
} else {
// Fallback for browsers that don't support lazy loading
const lazyLoadScript = document.createElement('script');
lazyLoadScript.src = 'https://cdnjs.cloudflare.com/ajax/libs/lozad.js/1.16.0/lozad.min.js';
document.body.appendChild(lazyLoadScript);
lazyLoadScript.onload = () => {
const observer = lozad();
observer.observe();
};
}
// Handle theme toggle
const themeToggle = document.querySelector('.theme-toggle');
if (themeToggle) {
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('dark-mode');
localStorage.setItem('theme',
document.body.classList.contains('dark-mode') ? 'dark' : 'light'
);
});
}
// Initialize smooth scroll behavior
document.documentElement.style.scrollBehavior = 'smooth';
// Handle window resize events (debounced)
window.addEventListener('resize', debounce(() => {
// Update any responsive elements
document.documentElement.style.setProperty(
'--vh',
`${window.innerHeight * 0.01}px`
);
}, 250));
});
// Handle loading state
window.addEventListener('load', () => {
document.body.classList.remove('loading');
document.body.classList.add('loaded');
});