-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
180 lines (153 loc) · 5.23 KB
/
Copy pathscript.js
File metadata and controls
180 lines (153 loc) · 5.23 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
// ==================== THEME TOGGLE ====================
const themeToggle = document.getElementById('theme-toggle');
const html = document.documentElement;
const themeIcon = themeToggle.querySelector('i');
// Check for saved theme preference or default to dark mode
const currentTheme = localStorage.getItem('theme') || 'dark';
html.setAttribute('data-theme', currentTheme);
updateThemeIcon(currentTheme);
themeToggle.addEventListener('click', () => {
const currentTheme = html.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
html.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
});
function updateThemeIcon(theme) {
if (theme === 'dark') {
themeIcon.classList.remove('fa-moon');
themeIcon.classList.add('fa-sun');
} else {
themeIcon.classList.remove('fa-sun');
themeIcon.classList.add('fa-moon');
}
}
// ==================== MOBILE MENU ====================
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
if (hamburger) {
hamburger.addEventListener('click', () => {
navMenu.classList.toggle('active');
hamburger.classList.toggle('active');
});
// Close menu when clicking on a link
document.querySelectorAll('.nav-menu a').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
});
});
// Close menu when clicking outside
document.addEventListener('click', (e) => {
if (!hamburger.contains(e.target) && !navMenu.contains(e.target)) {
navMenu.classList.remove('active');
hamburger.classList.remove('active');
}
});
}
// ==================== SMOOTH SCROLL ====================
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function (e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// ==================== SCROLL 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 cards and sections for animation
document.addEventListener('DOMContentLoaded', () => {
const animatedElements = document.querySelectorAll(
'.highlight-card, .project-card, .resume-section, .contact-method'
);
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);
});
});
// ==================== FORM HANDLING ====================
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
// If using custom form handling instead of Formspree
// e.preventDefault();
// Add your custom form submission logic here
});
}
// ==================== ACTIVE NAV LINK ====================
function setActiveNavLink() {
const currentPage = window.location.pathname.split('/').pop() || 'index.html';
const navLinks = document.querySelectorAll('.nav-menu a');
navLinks.forEach(link => {
const href = link.getAttribute('href');
if (href === currentPage) {
link.classList.add('active');
} else {
link.classList.remove('active');
}
});
}
setActiveNavLink();
// ==================== KEYBOARD SHORTCUTS ====================
document.addEventListener('keydown', (e) => {
// Don't trigger shortcuts if user is typing in an input or textarea
if (e.target.tagName === 'INPUT' || e.target.tagName === 'TEXTAREA') {
return;
}
const key = e.key.toLowerCase();
// Navigation shortcuts
const shortcuts = {
'h': 'index.html',
'1': 'index.html',
'a': 'about.html',
'2': 'about.html',
'p': 'projects.html',
'3': 'projects.html',
'r': 'resume.html',
'4': 'resume.html',
's': 'swimming.html',
'5': 'swimming.html',
'c': 'contact.html',
'6': 'contact.html'
};
if (shortcuts[key]) {
window.location.href = shortcuts[key];
return;
}
// Theme toggle with 't' key
if (key === 't') {
e.preventDefault();
themeToggle.click();
return;
}
// Go to top with 'g' key
if (key === 'g') {
e.preventDefault();
window.scrollTo({ top: 0, behavior: 'smooth' });
return;
}
// Go to bottom with 'b' key
if (key === 'b') {
e.preventDefault();
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
return;
}
});