-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
117 lines (102 loc) · 3.43 KB
/
script.js
File metadata and controls
117 lines (102 loc) · 3.43 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
document.addEventListener('DOMContentLoaded', () => {
const navToggle = document.querySelector('.nav__toggle');
const navLinks = document.querySelector('.nav__links');
const yearEl = document.getElementById('year');
if (yearEl) {
yearEl.textContent = new Date().getFullYear();
}
if (navToggle && navLinks) {
const setExpanded = (isOpen) => {
navLinks.classList.toggle('is-open', isOpen);
navToggle.setAttribute('aria-expanded', isOpen ? 'true' : 'false');
};
navToggle.addEventListener('click', () => {
const nextState = !navLinks.classList.contains('is-open');
setExpanded(nextState);
});
navLinks.addEventListener('click', (event) => {
if (event.target.closest('a')) {
setExpanded(false);
}
});
document.addEventListener('keydown', (event) => {
if (event.key === 'Escape' && navLinks.classList.contains('is-open')) {
setExpanded(false);
navToggle.focus();
}
});
}
document.querySelectorAll('[data-copy]').forEach((button) => {
const defaultLabel = button.textContent;
const setStatus = (label) => {
button.textContent = label;
setTimeout(() => {
button.textContent = defaultLabel;
}, 1800);
};
button.addEventListener('click', () => {
const target = document.querySelector(button.dataset.copy);
if (!target) {
return;
}
const textToCopy = target.textContent.trim();
const clipboard = navigator.clipboard;
if (clipboard && typeof clipboard.writeText === 'function') {
clipboard.writeText(textToCopy).then(() => {
setStatus('Copied!');
}).catch(() => {
setStatus('Copy manually');
});
return;
}
try {
const range = document.createRange();
range.selectNodeContents(target);
const selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
const successful = document.execCommand('copy');
selection.removeAllRanges();
setStatus(successful ? 'Copied!' : 'Copy manually');
} catch (error) {
setStatus('Copy manually');
}
});
});
// Smooth scroll for anchor links
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
const href = this.getAttribute('href');
if (href === '#' || href === '#top') return;
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Intersection Observer for fade-in animations
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 sections and cards for fade-in effect (exclude hero section)
const animatedElements = document.querySelectorAll('.section:not(.hero), .card, .metric, figure, .install-steps li');
animatedElements.forEach(el => {
el.style.opacity = '0';
el.style.transform = 'translateY(20px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
observer.observe(el);
});
});