Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
159 lines (137 loc) · 4.89 KB
/
Copy pathscript.js
File metadata and controls
159 lines (137 loc) · 4.89 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
function getNavOffset() {
const nav = document.getElementById('nav');
return nav ? nav.offsetHeight + 12 : 80;
}
function scrollToSection(id) {
const el = document.getElementById(id);
if (!el) return;
const top = el.getBoundingClientRect().top + window.pageYOffset - getNavOffset();
window.scrollTo({ top, behavior: 'smooth' });
}
window.scrollToSection = scrollToSection;
document.getElementById('year').textContent = new Date().getFullYear();
const html = document.documentElement;
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'dark') {
html.setAttribute('data-theme', 'dark');
} else {
html.removeAttribute('data-theme');
}
function toggleTheme() {
const isDark = html.getAttribute('data-theme') === 'dark';
if (isDark) {
html.removeAttribute('data-theme');
localStorage.setItem('theme', 'light');
} else {
html.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
}
}
const nav = document.getElementById('nav');
const sections = ['home', 'about', 'projects', 'achievements'];
const navLinks = document.querySelectorAll('[data-section]');
let lastScrollY = 0;
document.querySelectorAll('[data-scroll-target]').forEach(button => {
button.addEventListener('click', () => {
scrollToSection(button.dataset.scrollTarget);
if (button.closest('#mobile-menu')) {
closeMenu();
}
});
});
function updateNav() {
const y = window.scrollY;
nav.classList.toggle('scrolled', y > 50);
if (y > lastScrollY && y > 120) {
nav.classList.add('hidden-nav');
} else {
nav.classList.remove('hidden-nav');
}
lastScrollY = y;
let active = 'home';
for (const id of sections) {
const el = document.getElementById(id);
if (!el) continue;
const rect = el.getBoundingClientRect();
if (rect.top <= 100 && rect.bottom >= 100) { active = id; break; }
}
navLinks.forEach(l => l.classList.toggle('active', l.dataset.section === active));
document.getElementById('back-top').classList.toggle('show', y > 400);
}
window.addEventListener('scroll', updateNav, { passive: true });
function toggleMenu() {
document.getElementById('nav-toggle').classList.toggle('open');
document.getElementById('mobile-menu').classList.toggle('open');
}
function closeMenu() {
document.getElementById('nav-toggle').classList.remove('open');
document.getElementById('mobile-menu').classList.remove('open');
}
const revealObs = new IntersectionObserver((entries) => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
const fill = e.target.querySelector('.skill-fill');
if (fill) {
const level = e.target.dataset.level || 0;
setTimeout(() => { fill.style.width = level + '%'; }, 200);
}
revealObs.unobserve(e.target);
}
});
}, { threshold: 0.15 });
document.querySelectorAll('.reveal, .reveal-left, .reveal-right, .reveal-scale, .skill-card')
.forEach(el => revealObs.observe(el));
const introScreen = document.getElementById('intro-screen');
if (introScreen) {
let introStarted = false;
const finishIntro = () => {
if (introStarted) return;
introStarted = true;
introScreen.classList.add('is-leaving');
window.setTimeout(() => introScreen.remove(), 2100);
};
if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
introScreen.remove();
} else {
window.addEventListener('load', () => window.setTimeout(finishIntro, 700), { once: true });
window.setTimeout(finishIntro, 2500);
}
}
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', async (event) => {
event.preventDefault();
const submitButton = contactForm.querySelector('.contact-submit');
const status = contactForm.querySelector('.contact-status');
const originalButtonText = submitButton.firstChild;
submitButton.disabled = true;
originalButtonText.textContent = 'Sending...';
status.className = 'contact-status';
status.textContent = '';
try {
const response = await fetch(contactForm.action, {
method: 'POST',
body: new FormData(contactForm),
headers: { Accept: 'application/json' }
});
if (!response.ok) throw new Error('Form submission failed');
contactForm.reset();
status.classList.add('success');
status.textContent = 'Your message was sent successfully.';
} catch (error) {
status.classList.add('error');
status.textContent = 'Something went wrong. Please try emailing me directly.';
} finally {
submitButton.disabled = false;
originalButtonText.textContent = 'Send Message';
}
});
}
function toggleAch(card) {
const hl = card.querySelector('.ach-highlights');
const hint = card.querySelector('.ach-hint');
const open = hl.classList.toggle('open');
card.classList.toggle('expanded', open);
hint.textContent = open ? 'Click to collapse' : 'Click to expand';
}