-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
520 lines (451 loc) · 16.4 KB
/
script.js
File metadata and controls
520 lines (451 loc) · 16.4 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
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
// Mobile Navigation Toggle
const hamburger = document.querySelector('.hamburger');
const navMenu = document.querySelector('.nav-menu');
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navMenu.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(n => n.addEventListener('click', () => {
hamburger.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) {
target.scrollIntoView({
behavior: 'smooth',
block: 'start'
});
}
});
});
// Navbar background change on scroll (class-based for theme awareness)
function updateNavbarScrolled() {
const navbar = document.querySelector('.navbar');
if (!navbar) return;
if (window.scrollY > 100) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
}
window.addEventListener('scroll', updateNavbarScrolled);
document.addEventListener('DOMContentLoaded', updateNavbarScrolled);
// Theme toggle (light/dark) with persistence
function applyTheme(theme) {
const root = document.documentElement;
const themeToggleBtn = document.querySelector('.theme-toggle');
if (theme === 'dark') {
root.classList.add('dark');
} else {
root.classList.remove('dark');
}
if (themeToggleBtn) {
const icon = themeToggleBtn.querySelector('i');
if (icon) {
if (root.classList.contains('dark')) {
icon.classList.remove('fa-moon');
icon.classList.add('fa-sun');
themeToggleBtn.setAttribute('aria-pressed', 'true');
themeToggleBtn.setAttribute('title', 'Switch to light mode');
} else {
icon.classList.remove('fa-sun');
icon.classList.add('fa-moon');
themeToggleBtn.setAttribute('aria-pressed', 'false');
themeToggleBtn.setAttribute('title', 'Switch to dark mode');
}
}
}
}
document.addEventListener('DOMContentLoaded', () => {
const prefersDark = window.matchMedia && window.matchMedia('(prefers-color-scheme: dark)').matches;
const stored = localStorage.getItem('theme');
const initialTheme = stored === 'dark' || stored === 'light' ? stored : (prefersDark ? 'dark' : 'light');
applyTheme(initialTheme);
const themeToggleBtn = document.querySelector('.theme-toggle');
if (themeToggleBtn) {
themeToggleBtn.addEventListener('click', () => {
const isDark = document.documentElement.classList.contains('dark');
const next = isDark ? 'light' : 'dark';
applyTheme(next);
localStorage.setItem('theme', next);
});
}
// If user hasn't set a preference, react to OS changes
if (!stored && window.matchMedia) {
const media = window.matchMedia('(prefers-color-scheme: dark)');
const handleChange = (e) => {
applyTheme(e.matches ? 'dark' : 'light');
};
if (typeof media.addEventListener === 'function') {
media.addEventListener('change', handleChange);
} else if (typeof media.addListener === 'function') {
media.addListener(handleChange);
}
}
});
// Intersection Observer for animations
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('fade-in-up');
}
});
}, observerOptions);
// Observe elements for animation
document.addEventListener('DOMContentLoaded', () => {
const animateElements = document.querySelectorAll('.project-card, .skill-item, .stat-item, .contact-method');
animateElements.forEach(el => observer.observe(el));
});
// Contact form handling with EmailJS integration
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
// Load EmailJS script dynamically
// const script = document.createElement('script');
// script.src = 'https://cdn.jsdelivr.net/npm/@emailjs/browser@3/dist/email.min.js';
// script.onload = function() {
// // Initialize EmailJS with your public key
// emailjs.init('YOUR_PUBLIC_KEY'); // Replace with your actual EmailJS public key
// };
// document.head.appendChild(script);
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
// Get form data
const formData = new FormData(this);
const name = formData.get('name');
const email = formData.get('email');
const subject = formData.get('subject');
const message = formData.get('message');
// Simple validation
if (!name || !email || !subject || !message) {
showNotification('Please fill in all fields', 'error');
return;
}
if (!isValidEmail(email)) {
showNotification('Please enter a valid email address', 'error');
return;
}
// Show loading state
const submitBtn = this.querySelector('button[type="submit"]');
const originalText = submitBtn.textContent;
submitBtn.textContent = 'Sending...';
submitBtn.disabled = true;
// Prepare email template parameters
const templateParams = {
from_name: name,
from_email: email,
subject: subject,
message: message,
to_name: 'Your Name' // Replace with your name
};
// Send email using EmailJS
// emailjs.send('YOUR_SERVICE_ID', 'YOUR_TEMPLATE_ID', templateParams)
// .then(function(response) {
// showNotification('Message sent successfully! I\'ll get back to you soon.', 'success');
// contactForm.reset();
// }, function(error) {
// showNotification('Failed to send message. Please try again or contact me directly.', 'error');
// })
// .finally(function() {
// // Reset button state
// submitBtn.textContent = originalText;
// submitBtn.disabled = false;
// });
// For now, use mailto fallback
const mailtoLink = `mailto:dev.sheth@utdallas.edu?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(`Name: ${name}\nEmail: ${email}\n\nMessage:\n${message}`)}`;
// Open default email client
window.location.href = mailtoLink;
showNotification('Opening your email client...', 'info');
// Reset button state
submitBtn.textContent = originalText;
submitBtn.disabled = false;
});
}
// Alternative: Simple mailto link fallback
function setupMailtoFallback() {
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', function(e) {
e.preventDefault();
const formData = new FormData(this);
const name = formData.get('name');
const email = formData.get('email');
const subject = formData.get('subject');
const message = formData.get('message');
// Validation
if (!name || !email || !subject || !message) {
showNotification('Please fill in all fields', 'error');
return;
}
if (!isValidEmail(email)) {
showNotification('Please enter a valid email address', 'error');
return;
}
// Create mailto link
const mailtoLink = `mailto:dev.sheth@utdallas.edu?subject=${encodeURIComponent(subject)}&body=${encodeURIComponent(`Name: ${name}\nEmail: ${email}\n\nMessage:\n${message}`)}`;
// Open default email client
window.location.href = mailtoLink;
showNotification('Opening your email client...', 'info');
});
}
}
// Email validation
function isValidEmail(email) {
const emailRegex = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return emailRegex.test(email);
}
// Notification system
function showNotification(message, type = 'info') {
// Remove existing notifications
const existingNotification = document.querySelector('.notification');
if (existingNotification) {
existingNotification.remove();
}
// Create notification element
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.innerHTML = `
<div class="notification-content">
<span class="notification-message">${message}</span>
<button class="notification-close">×</button>
</div>
`;
// Add styles
notification.style.cssText = `
position: fixed;
top: 20px;
right: 20px;
background: ${type === 'success' ? '#10b981' : type === 'error' ? '#ef4444' : '#3b82f6'};
color: white;
padding: 1rem 1.5rem;
border-radius: 8px;
box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
z-index: 10000;
transform: translateX(100%);
transition: transform 0.3s ease;
max-width: 400px;
`;
// Add to page
document.body.appendChild(notification);
// Animate in
setTimeout(() => {
notification.style.transform = 'translateX(0)';
}, 100);
// Close button functionality
const closeBtn = notification.querySelector('.notification-close');
closeBtn.addEventListener('click', () => {
notification.style.transform = 'translateX(100%)';
setTimeout(() => notification.remove(), 300);
});
// Auto remove after 5 seconds
setTimeout(() => {
if (notification.parentNode) {
notification.style.transform = 'translateX(100%)';
setTimeout(() => notification.remove(), 300);
}
}, 5000);
}
// Typing animation for hero title
function typeWriter(element, text, speed = 100) {
let i = 0;
element.innerHTML = '';
function type() {
if (i < text.length) {
element.innerHTML += text.charAt(i);
i++;
setTimeout(type, speed);
}
}
type();
}
// Initialize typing animation when page loads
document.addEventListener('DOMContentLoaded', () => {
const heroTitle = document.querySelector('.hero-title');
if (heroTitle) {
const originalText = heroTitle.textContent;
setTimeout(() => {
typeWriter(heroTitle, originalText, 50);
}, 1000);
}
});
// Project card hover effects
document.querySelectorAll('.project-card').forEach(card => {
card.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-10px) scale(1.02)';
});
card.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Skill item hover effects
document.querySelectorAll('.skill-item').forEach(item => {
item.addEventListener('mouseenter', function() {
this.style.transform = 'translateY(-5px) scale(1.05)';
});
item.addEventListener('mouseleave', function() {
this.style.transform = 'translateY(0) scale(1)';
});
});
// Parallax effect for hero section
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const hero = document.querySelector('.hero');
if (hero) {
const rate = scrolled * -0.5;
hero.style.transform = `translateY(${rate}px)`;
}
});
// Active navigation link highlighting
function updateActiveNavLink() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop;
const sectionHeight = section.clientHeight;
if (window.scrollY >= (sectionTop - 200)) {
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 to CSS
const style = document.createElement('style');
style.textContent = `
.nav-link.active {
color: #2563eb !important;
}
.nav-link.active::after {
width: 100% !important;
}
.notification-content {
display: flex;
align-items: center;
justify-content: space-between;
gap: 1rem;
}
.notification-close {
background: none;
border: none;
color: white;
font-size: 1.5rem;
cursor: pointer;
padding: 0;
line-height: 1;
}
.notification-close:hover {
opacity: 0.8;
}
`;
document.head.appendChild(style);
// Lazy loading for images (if you add real images later)
function lazyLoadImages() {
const images = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.remove('lazy');
imageObserver.unobserve(img);
}
});
});
images.forEach(img => imageObserver.observe(img));
}
// Initialize lazy loading
document.addEventListener('DOMContentLoaded', lazyLoadImages);
// Add some interactive particle effects to the hero section
function createParticles() {
const hero = document.querySelector('.hero');
if (!hero) return;
for (let i = 0; i < 50; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
particle.style.cssText = `
position: absolute;
width: 2px;
height: 2px;
background: rgba(255, 255, 255, 0.5);
border-radius: 50%;
pointer-events: none;
animation: float-particle ${Math.random() * 10 + 10}s linear infinite;
left: ${Math.random() * 100}%;
top: ${Math.random() * 100}%;
`;
hero.appendChild(particle);
}
}
// Add particle animation styles
const particleStyle = document.createElement('style');
particleStyle.textContent = `
@keyframes float-particle {
0% {
transform: translateY(100vh) rotate(0deg);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
transform: translateY(-100px) rotate(360deg);
opacity: 0;
}
}
`;
document.head.appendChild(particleStyle);
// Initialize particles
document.addEventListener('DOMContentLoaded', createParticles);
// Add a simple loading animation
window.addEventListener('load', () => {
document.body.classList.add('loaded');
});
// Add loading styles
const loadingStyle = document.createElement('style');
loadingStyle.textContent = `
body {
opacity: 0;
transition: opacity 0.5s ease;
}
body.loaded {
opacity: 1;
}
`;
document.head.appendChild(loadingStyle);
// Scroll to About section when profile picture is clicked
const profilePic = document.querySelector('.profile-pic');
if (profilePic) {
profilePic.addEventListener('click', function() {
const aboutSection = document.getElementById('about');
if (aboutSection) {
aboutSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
}
// Scroll to About section when hero arrow is clicked
const scrollArrow = document.querySelector('.scroll-arrow');
if (scrollArrow) {
scrollArrow.addEventListener('click', function() {
const aboutSection = document.getElementById('about');
if (aboutSection) {
aboutSection.scrollIntoView({ behavior: 'smooth', block: 'start' });
}
});
}