-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
544 lines (466 loc) · 17.5 KB
/
Copy pathscript.js
File metadata and controls
544 lines (466 loc) · 17.5 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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
// DOM Elements
const navToggle = document.getElementById('nav-toggle');
const navMenu = document.getElementById('nav-menu');
const themeToggle = document.getElementById('theme-toggle');
const backToTop = document.getElementById('back-to-top');
const contactForm = document.getElementById('contact-form');
const typingText = document.getElementById('typing-text');
const filterBtns = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
const testimonialCards = document.querySelectorAll('.testimonial-card');
const prevBtn = document.getElementById('prev-testimonial');
const nextBtn = document.getElementById('next-testimonial');
const dots = document.querySelectorAll('.dot');
// Global Variables
let currentTestimonial = 0;
let isTyping = false;
let typingIndex = 0;
const typingTexts = [
"I build intuitive, user-focused AI solutions.",
"I create scalable web applications.",
"I solve complex problems with elegant code."
];
// Theme Management
function initTheme() {
const savedTheme = localStorage.getItem('theme') || 'light';
document.documentElement.setAttribute('data-theme', savedTheme);
updateThemeIcon(savedTheme);
}
function toggleTheme() {
const currentTheme = document.documentElement.getAttribute('data-theme');
const newTheme = currentTheme === 'light' ? 'dark' : 'light';
document.documentElement.setAttribute('data-theme', newTheme);
localStorage.setItem('theme', newTheme);
updateThemeIcon(newTheme);
}
function updateThemeIcon(theme) {
const icon = themeToggle.querySelector('i');
icon.className = theme === 'light' ? 'fas fa-moon' : 'fas fa-sun';
}
// Navigation
function initNavigation() {
// Mobile menu toggle
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
navToggle.classList.toggle('active');
});
// Close mobile menu when clicking on a link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
navToggle.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) {
const offsetTop = target.offsetTop - 70; // Account for fixed navbar
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
}
// Typing Animation
function initTypingAnimation() {
function typeText() {
if (isTyping) return;
isTyping = true;
const currentText = typingTexts[typingIndex];
let charIndex = 0;
typingText.textContent = '';
const typeInterval = setInterval(() => {
typingText.textContent += currentText[charIndex];
charIndex++;
if (charIndex >= currentText.length) {
clearInterval(typeInterval);
isTyping = false;
// Wait before starting next text
setTimeout(() => {
typingIndex = (typingIndex + 1) % typingTexts.length;
typeText();
}, 3000);
}
}, 100);
}
// Start typing animation after a delay
setTimeout(typeText, 1000);
}
// Scroll Animations
function initScrollAnimations() {
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('animate-fade-in-up');
}
});
}, observerOptions);
// Observe elements for animation
const animateElements = document.querySelectorAll('.timeline-item, .project-card, .skill-item, .education-card, .value-item');
animateElements.forEach(el => observer.observe(el));
}
// Statistics Counter Animation
function initStatsCounter() {
const stats = document.querySelectorAll('.stat-number');
const countUp = (element, target) => {
let current = 0;
const increment = target / 100;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
current = target;
clearInterval(timer);
}
element.textContent = Math.floor(current);
}, 20);
};
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const target = parseInt(entry.target.getAttribute('data-target'));
countUp(entry.target, target);
statsObserver.unobserve(entry.target);
}
});
}, { threshold: 0.5 });
stats.forEach(stat => statsObserver.observe(stat));
}
// Project Filtering
function initProjectFiltering() {
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// Remove active class from all buttons
filterBtns.forEach(b => b.classList.remove('active'));
// Add active class to clicked button
btn.classList.add('active');
const filter = btn.getAttribute('data-filter');
projectCards.forEach(card => {
const category = card.getAttribute('data-category');
if (filter === 'all' || category === filter) {
card.style.display = 'block';
setTimeout(() => {
card.style.opacity = '1';
card.style.transform = 'scale(1)';
}, 100);
} else {
card.style.opacity = '0';
card.style.transform = 'scale(0.8)';
setTimeout(() => {
card.style.display = 'none';
}, 300);
}
});
});
});
}
// Testimonials Slider
function initTestimonialsSlider() {
function showTestimonial(index) {
testimonialCards.forEach((card, i) => {
card.classList.toggle('active', i === index);
});
dots.forEach((dot, i) => {
dot.classList.toggle('active', i === index);
});
}
function nextTestimonial() {
currentTestimonial = (currentTestimonial + 1) % testimonialCards.length;
showTestimonial(currentTestimonial);
}
function prevTestimonial() {
currentTestimonial = (currentTestimonial - 1 + testimonialCards.length) % testimonialCards.length;
showTestimonial(currentTestimonial);
}
// Event listeners
nextBtn.addEventListener('click', nextTestimonial);
prevBtn.addEventListener('click', prevTestimonial);
dots.forEach((dot, index) => {
dot.addEventListener('click', () => {
currentTestimonial = index;
showTestimonial(currentTestimonial);
});
});
// Auto-advance testimonials
setInterval(nextTestimonial, 5000);
}
// Back to Top Button
function initBackToTop() {
window.addEventListener('scroll', () => {
if (window.pageYOffset > 300) {
backToTop.classList.add('show');
} else {
backToTop.classList.remove('show');
}
});
backToTop.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}
// Contact Form
function initContactForm() {
contactForm.addEventListener('submit', async (e) => {
e.preventDefault();
const formData = new FormData(contactForm);
const submitBtn = contactForm.querySelector('button[type="submit"]');
const originalText = submitBtn.innerHTML;
// Show loading state
submitBtn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending...';
submitBtn.disabled = true;
try {
// Simulate form submission (replace with actual endpoint)
await new Promise(resolve => setTimeout(resolve, 2000));
// Show success message
showNotification('Message sent successfully! I\'ll get back to you soon.', 'success');
contactForm.reset();
} catch (error) {
showNotification('Failed to send message. Please try again.', 'error');
} finally {
// Reset button state
submitBtn.innerHTML = originalText;
submitBtn.disabled = false;
}
});
}
// Notification System
function showNotification(message, type = 'info') {
const notification = document.createElement('div');
notification.className = `notification notification-${type}`;
notification.innerHTML = `
<div class="notification-content">
<i class="fas fa-${type === 'success' ? 'check-circle' : type === 'error' ? 'exclamation-circle' : 'info-circle'}"></i>
<span>${message}</span>
</div>
<button class="notification-close">
<i class="fas fa-times"></i>
</button>
`;
// 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;
display: flex;
align-items: center;
gap: 1rem;
max-width: 400px;
transform: translateX(100%);
transition: transform 0.3s ease;
`;
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(() => {
document.body.removeChild(notification);
}, 300);
});
// Auto remove after 5 seconds
setTimeout(() => {
if (document.body.contains(notification)) {
notification.style.transform = 'translateX(100%)';
setTimeout(() => {
if (document.body.contains(notification)) {
document.body.removeChild(notification);
}
}, 300);
}
}, 5000);
}
// Skills Progress Animation
function initSkillsAnimation() {
const skillBars = document.querySelectorAll('.skill-progress');
const skillsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const progressBar = entry.target;
const width = progressBar.style.width;
progressBar.style.width = '0%';
setTimeout(() => {
progressBar.style.width = width;
}, 200);
skillsObserver.unobserve(progressBar);
}
});
}, { threshold: 0.5 });
skillBars.forEach(bar => skillsObserver.observe(bar));
}
// Parallax Effect
function initParallax() {
window.addEventListener('scroll', () => {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('.hero-image, .about-image');
parallaxElements.forEach(element => {
const speed = 0.5;
element.style.transform = `translateY(${scrolled * speed}px)`;
});
});
}
// Active Navigation Highlight
function initActiveNavigation() {
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
window.addEventListener('scroll', () => {
let current = '';
sections.forEach(section => {
const sectionTop = section.offsetTop - 100;
const sectionHeight = section.clientHeight;
if (window.pageYOffset >= sectionTop && window.pageYOffset < sectionTop + sectionHeight) {
current = section.getAttribute('id');
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
});
}
// Loading Animation
function initLoadingAnimation() {
const loadingElements = document.querySelectorAll('.project-card, .skill-item, .education-card');
const loadingObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('loaded');
}
});
}, { threshold: 0.1 });
loadingElements.forEach(el => {
el.classList.add('loading');
loadingObserver.observe(el);
});
}
// Keyboard Navigation
function initKeyboardNavigation() {
document.addEventListener('keydown', (e) => {
// Escape key to close mobile menu
if (e.key === 'Escape') {
navMenu.classList.remove('active');
navToggle.classList.remove('active');
}
// Arrow keys for testimonials
if (e.key === 'ArrowRight') {
document.getElementById('next-testimonial').click();
}
if (e.key === 'ArrowLeft') {
document.getElementById('prev-testimonial').click();
}
});
}
// Performance Optimization
function initPerformanceOptimizations() {
// Lazy loading for images
const images = document.querySelectorAll('img[data-src]');
const imageObserver = new IntersectionObserver((entries) => {
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));
// Debounce scroll events
let scrollTimeout;
window.addEventListener('scroll', () => {
clearTimeout(scrollTimeout);
scrollTimeout = setTimeout(() => {
// Handle scroll-based animations
}, 16); // ~60fps
});
}
// Initialize all functions when DOM is loaded
document.addEventListener('DOMContentLoaded', () => {
initTheme();
initNavigation();
initTypingAnimation();
initScrollAnimations();
initStatsCounter();
initProjectFiltering();
initTestimonialsSlider();
initBackToTop();
initContactForm();
initSkillsAnimation();
initParallax();
initActiveNavigation();
initLoadingAnimation();
initKeyboardNavigation();
initPerformanceOptimizations();
// Theme toggle event listener
themeToggle.addEventListener('click', toggleTheme);
// Add smooth scrolling to the whole page
document.documentElement.style.scrollBehavior = 'smooth';
// Preload critical resources
const criticalImages = [
'https://via.placeholder.com/300x300/4F46E5/FFFFFF?text=Your+Photo',
'https://via.placeholder.com/400x500/4F46E5/FFFFFF?text=Professional+Photo'
];
criticalImages.forEach(src => {
const img = new Image();
img.src = src;
});
});
// Service Worker Registration (for PWA features)
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('/sw.js')
.then(registration => {
console.log('SW registered: ', registration);
})
.catch(registrationError => {
console.log('SW registration failed: ', registrationError);
});
});
}
// Analytics (replace with your analytics code)
function initAnalytics() {
// Google Analytics or other analytics code can be added here
console.log('Analytics initialized');
}
// Error Handling
window.addEventListener('error', (e) => {
console.error('Global error:', e.error);
// You can send error reports to your analytics service here
});
// Performance Monitoring
window.addEventListener('load', () => {
// Measure page load performance
const loadTime = performance.timing.loadEventEnd - performance.timing.navigationStart;
console.log(`Page loaded in ${loadTime}ms`);
// Report to analytics if needed
if (loadTime > 3000) {
console.warn('Slow page load detected');
}
});
// Export functions for potential external use
window.PortfolioApp = {
showNotification,
toggleTheme,
initTheme
};