-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
646 lines (558 loc) · 19.4 KB
/
Copy pathscript.js
File metadata and controls
646 lines (558 loc) · 19.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
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
/* =====================================================
AVINASH RAI - DATA ENGINEER PORTFOLIO
Interactive Features & Animations
===================================================== */
// =====================
// GLOBAL VARIABLES
// =====================
const navbar = document.getElementById('navbar');
const navToggle = document.getElementById('navToggle');
const navMenu = document.getElementById('navMenu');
const navLinks = document.querySelectorAll('.nav-link');
const backToTopButton = document.getElementById('backToTop');
const sections = document.querySelectorAll('section[id]');
const filterButtons = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
// =====================
// STICKY NAVBAR
// =====================
let lastScroll = 0;
window.addEventListener('scroll', () => {
const currentScroll = window.pageYOffset;
// Add shadow when scrolled
if (currentScroll > 50) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
lastScroll = currentScroll;
});
// =====================
// MOBILE MENU TOGGLE
// =====================
if (navToggle) {
navToggle.addEventListener('click', () => {
navMenu.classList.toggle('active');
// Animate hamburger
const spans = navToggle.querySelectorAll('span');
if (navMenu.classList.contains('active')) {
spans[0].style.transform = 'rotate(45deg) translateY(8px)';
spans[1].style.opacity = '0';
spans[2].style.transform = 'rotate(-45deg) translateY(-8px)';
} else {
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
}
// Close mobile menu when clicking a link
navLinks.forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('active');
// Reset hamburger
const spans = navToggle?.querySelectorAll('span');
if (spans) {
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
});
});
// Close mobile menu when clicking outside
document.addEventListener('click', (e) => {
if (!navMenu.contains(e.target) && !navToggle.contains(e.target)) {
navMenu.classList.remove('active');
const spans = navToggle?.querySelectorAll('span');
if (spans) {
spans[0].style.transform = 'none';
spans[1].style.opacity = '1';
spans[2].style.transform = 'none';
}
}
});
// =====================
// ACTIVE NAVIGATION LINK ON SCROLL
// =====================
function highlightNav() {
let current = '';
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 100;
const sectionId = section.getAttribute('id');
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
current = sectionId;
}
});
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('active');
}
});
}
window.addEventListener('scroll', highlightNav);
// =====================
// SMOOTH SCROLL FOR ANCHOR 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 - 80;
window.scrollTo({
top: offsetTop,
behavior: 'smooth'
});
}
});
});
// =====================
// BACK TO TOP BUTTON
// =====================
window.addEventListener('scroll', () => {
if (window.pageYOffset > 400) {
backToTopButton.classList.add('visible');
} else {
backToTopButton.classList.remove('visible');
}
});
if (backToTopButton) {
backToTopButton.addEventListener('click', () => {
window.scrollTo({
top: 0,
behavior: 'smooth'
});
});
}
// =====================
// PROJECT FILTER FUNCTIONALITY
// =====================
if (filterButtons.length > 0) {
filterButtons.forEach(button => {
button.addEventListener('click', () => {
// Remove active class from all buttons
filterButtons.forEach(btn => btn.classList.remove('active'));
// Add active class to clicked button
button.classList.add('active');
// Get filter value
const filterValue = button.getAttribute('data-filter');
// Filter projects
projectCards.forEach(card => {
const categories = card.getAttribute('data-category');
if (filterValue === 'all' || categories.includes(filterValue)) {
card.style.display = 'flex';
card.style.animation = 'fadeIn 0.5s ease-in';
} else {
card.style.display = 'none';
}
});
});
});
}
// =====================
// ANIMATED PARTICLES BACKGROUND
// =====================
function createParticles() {
const particlesContainer = document.getElementById('particles');
if (!particlesContainer) return;
const particleCount = 50;
for (let i = 0; i < particleCount; i++) {
const particle = document.createElement('div');
particle.className = 'particle';
// Random position
particle.style.left = Math.random() * 100 + '%';
particle.style.top = Math.random() * 100 + '%';
// Random size
const size = Math.random() * 4 + 1;
particle.style.width = size + 'px';
particle.style.height = size + 'px';
// Random animation duration
const duration = Math.random() * 20 + 10;
particle.style.animationDuration = duration + 's';
// Random delay
const delay = Math.random() * 5;
particle.style.animationDelay = delay + 's';
particlesContainer.appendChild(particle);
}
}
// Add particle styles dynamically
const style = document.createElement('style');
style.textContent = `
.particle {
position: absolute;
background: radial-gradient(circle, rgba(56, 182, 255, 0.8) 0%, transparent 70%);
border-radius: 50%;
pointer-events: none;
animation: float-particle linear infinite;
}
@keyframes float-particle {
0% {
transform: translateY(0) translateX(0) scale(1);
opacity: 0;
}
10% {
opacity: 1;
}
90% {
opacity: 1;
}
100% {
transform: translateY(-100vh) translateX(${Math.random() * 100 - 50}px) scale(0);
opacity: 0;
}
}
`;
document.head.appendChild(style);
// Initialize particles
document.addEventListener('DOMContentLoaded', createParticles);
// =====================
// INTERSECTION OBSERVER FOR FADE-IN ANIMATIONS
// =====================
const observerOptions = {
threshold: 0.1,
rootMargin: '0px 0px -50px 0px'
};
const fadeInObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
// Support for legacy inline styles
entry.target.style.opacity = '1';
entry.target.style.transform = 'translateY(0)';
// Support for new CSS class approach
entry.target.classList.add('active');
fadeInObserver.unobserve(entry.target);
}
});
}, observerOptions);
// Observe elements for fade-in effect
document.addEventListener('DOMContentLoaded', () => {
const animatedElements = document.querySelectorAll(`
.project-card,
.expertise-card,
.highlight-card,
.tech-category,
.contact-card,
.reveal
`);
animatedElements.forEach(el => {
// Only apply inline styles if NOT using .reveal class
if (!el.classList.contains('reveal')) {
el.style.opacity = '0';
el.style.transform = 'translateY(30px)';
el.style.transition = 'opacity 0.6s ease, transform 0.6s ease';
}
fadeInObserver.observe(el);
});
});
// =====================
// TYPING EFFECT FOR HERO SUBTITLE (Optional)
// =====================
function typeWriter(element, texts, speed = 100) {
if (!element) return;
let textIndex = 0;
let charIndex = 0;
let isDeleting = false;
let currentText = '';
function type() {
const fullText = texts[textIndex];
if (isDeleting) {
currentText = fullText.substring(0, charIndex - 1);
charIndex--;
} else {
currentText = fullText.substring(0, charIndex + 1);
charIndex++;
}
element.textContent = currentText;
let typeSpeed = isDeleting ? speed / 2 : speed;
if (!isDeleting && charIndex === fullText.length) {
typeSpeed = 2000; // Pause at end
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
textIndex = (textIndex + 1) % texts.length;
typeSpeed = 500; // Pause before next text
}
setTimeout(type, typeSpeed);
}
type();
}
// Initialize typing effect (optional - remove if not needed)
// Uncomment if you want animated typing in hero subtitle
/*
document.addEventListener('DOMContentLoaded', () => {
const subtitleElement = document.querySelector('.hero-subtitle');
if (subtitleElement) {
const texts = [
'Data Engineer & Analytics Architect',
'Snowflake & dbt Specialist',
'AI/ML Pipeline Expert',
'Modern Data Stack Architect'
];
typeWriter(subtitleElement, texts, 80);
}
});
*/
// =====================
// DYNAMIC YEAR IN FOOTER
// =====================
document.addEventListener('DOMContentLoaded', () => {
const yearElements = document.querySelectorAll('.current-year');
const currentYear = new Date().getFullYear();
yearElements.forEach(el => {
el.textContent = currentYear;
});
});
// =====================
// PARALLAX SCROLL EFFECT (Optional)
// =====================
function parallaxScroll() {
const scrolled = window.pageYOffset;
const parallaxElements = document.querySelectorAll('[data-parallax]');
parallaxElements.forEach(el => {
const speed = el.getAttribute('data-parallax') || 0.5;
const yPos = -(scrolled * speed);
el.style.transform = `translateY(${yPos}px)`;
});
}
// Uncomment to enable parallax
// window.addEventListener('scroll', parallaxScroll);
// =====================
// LAZY LOADING IMAGES
// =====================
if ('IntersectionObserver' in window) {
const imageObserver = new IntersectionObserver((entries, observer) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const img = entry.target;
img.src = img.dataset.src;
img.classList.add('loaded');
observer.unobserve(img);
}
});
});
document.querySelectorAll('img[data-src]').forEach(img => {
imageObserver.observe(img);
});
}
// =====================
// COPY EMAIL TO CLIPBOARD
// =====================
function copyToClipboard(text) {
navigator.clipboard.writeText(text).then(() => {
// Show success message
const notification = document.createElement('div');
notification.textContent = 'Email copied to clipboard!';
notification.style.cssText = `
position: fixed;
bottom: 30px;
left: 50%;
transform: translateX(-50%);
background: linear-gradient(135deg, #38B6FF 0%, #8B5CF6 100%);
color: white;
padding: 1rem 2rem;
border-radius: 50px;
font-weight: 600;
box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
z-index: 10000;
animation: slideUp 0.3s ease;
`;
document.body.appendChild(notification);
setTimeout(() => {
notification.style.animation = 'slideDown 0.3s ease';
setTimeout(() => notification.remove(), 300);
}, 2000);
});
}
// Add click event to email links
document.querySelectorAll('a[href^="mailto:"]').forEach(link => {
link.addEventListener('click', (e) => {
if (e.ctrlKey || e.metaKey) {
e.preventDefault();
const email = link.getAttribute('href').replace('mailto:', '');
copyToClipboard(email);
}
});
});
// =====================
// STATS COUNTER ANIMATION
// =====================
function animateCounter(element, target, duration = 2000) {
const start = 0;
const increment = target / (duration / 16);
let current = start;
const timer = setInterval(() => {
current += increment;
if (current >= target) {
element.textContent = target + '+';
clearInterval(timer);
} else {
element.textContent = Math.floor(current) + '+';
}
}, 16);
}
// Animate stats when visible
const statsObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const statNumber = entry.target.querySelector('.stat-number');
if (statNumber && !statNumber.classList.contains('animated')) {
const target = parseInt(statNumber.textContent);
animateCounter(statNumber, target);
statNumber.classList.add('animated');
statsObserver.unobserve(entry.target);
}
}
});
}, { threshold: 0.5 });
document.querySelectorAll('.stat').forEach(stat => {
statsObserver.observe(stat);
});
// =====================
// CONSOLE EASTER EGG
// =====================
console.log('%c👋 Hello, Fellow Developer!', 'font-size: 24px; font-weight: bold; color: #38B6FF;');
console.log('%c🚀 Thanks for checking out my portfolio!', 'font-size: 16px; color: #FF6B9D;');
console.log('%c📧 Let\'s connect: masteravinashrai@gmail.com', 'font-size: 14px; color: #00D9A3;');
console.log('%c💼 LinkedIn: linkedin.com/in/avinashanalytics', 'font-size: 14px; color: #8892a6;');
console.log('%c⭐ GitHub: github.com/AvinashAnalytics', 'font-size: 14px; color: #8892a6;');
console.log('%c\n🎨 Built with vanilla JavaScript, CSS, and lots of ☕', 'font-size: 12px; font-style: italic; color: #b8c5d6;');
// =====================
// PERFORMANCE MONITORING
// =====================
window.addEventListener('load', () => {
// Log page load time
const loadTime = window.performance.timing.domContentLoadedEventEnd - window.performance.timing.navigationStart;
console.log(`⚡ Page loaded in ${loadTime}ms`);
// Check for reduced motion preference
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches;
if (prefersReducedMotion) {
document.documentElement.style.scrollBehavior = 'auto';
console.log('♿ Reduced motion mode enabled');
}
});
// =====================
// KEYBOARD NAVIGATION ENHANCEMENT
// =====================
document.addEventListener('keydown', (e) => {
// Press 'Escape' to close mobile menu
if (e.key === 'Escape' && navMenu.classList.contains('active')) {
navMenu.classList.remove('active');
}
// Press 'Home' to scroll to top
if (e.key === 'Home' && !e.shiftKey) {
e.preventDefault();
window.scrollTo({ top: 0, behavior: 'smooth' });
}
// Press 'End' to scroll to bottom
if (e.key === 'End' && !e.shiftKey) {
e.preventDefault();
window.scrollTo({ top: document.body.scrollHeight, behavior: 'smooth' });
}
});
// =====================
// FOCUS VISIBLE ENHANCEMENT
// =====================
document.addEventListener('DOMContentLoaded', () => {
let isUsingMouse = false;
document.addEventListener('mousedown', () => {
isUsingMouse = true;
});
document.addEventListener('keydown', () => {
isUsingMouse = false;
});
document.addEventListener('focusin', (e) => {
if (isUsingMouse) {
e.target.classList.add('mouse-focus');
} else {
e.target.classList.remove('mouse-focus');
}
});
});
// =====================
// THEME COLOR META UPDATE (for mobile browsers)
// =====================
function updateThemeColor() {
const scrolled = window.pageYOffset;
const metaThemeColor = document.querySelector('meta[name="theme-color"]');
if (!metaThemeColor) {
const meta = document.createElement('meta');
meta.name = 'theme-color';
meta.content = '#0a0e27';
document.head.appendChild(meta);
} else {
metaThemeColor.content = scrolled > 50 ? '#050711' : '#0a0e27';
}
}
window.addEventListener('scroll', updateThemeColor);
// =====================
// EXTERNAL LINK SECURITY
// =====================
document.querySelectorAll('a[target="_blank"]').forEach(link => {
link.setAttribute('rel', 'noopener noreferrer');
});
// =====================
// ANALYTICS EVENT TRACKING (Optional - for Google Analytics)
// =====================
function trackEvent(category, action, label) {
if (typeof gtag !== 'undefined') {
gtag('event', action, {
'event_category': category,
'event_label': label
});
}
console.log(`📊 Event tracked: ${category} - ${action} - ${label}`);
}
// Track project clicks
document.querySelectorAll('.project-link').forEach(link => {
link.addEventListener('click', () => {
const projectName = link.closest('.project-card').querySelector('h3').textContent;
trackEvent('Projects', 'Click', projectName);
});
});
// Track social media clicks
document.querySelectorAll('.social-icon, .social-link').forEach(link => {
link.addEventListener('click', () => {
const platform = link.getAttribute('title') || 'Social Link';
trackEvent('Social', 'Click', platform);
});
});
// Track contact button clicks
document.querySelectorAll('.btn').forEach(button => {
button.addEventListener('click', () => {
const buttonText = button.textContent.trim();
trackEvent('CTA', 'Click', buttonText);
});
});
// =====================
// INITIALIZATION
// =====================
document.addEventListener('DOMContentLoaded', () => {
console.log('✅ Portfolio initialized successfully');
// Highlight initial nav item
highlightNav();
// Update theme color
updateThemeColor();
// Add loaded class to body
document.body.classList.add('loaded');
});
// =====================
// SERVICE WORKER REGISTRATION (Optional - for PWA)
// =====================
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
// Uncomment to enable service worker
/*
navigator.serviceWorker.register('/sw.js')
.then(reg => console.log('✅ Service Worker registered'))
.catch(err => console.log('❌ Service Worker registration failed', err));
*/
});
}
/* =====================================================
🤖 AVINASH AI DIGITAL TWIN — CHAT WIDGET
Safe Integration With Existing Portfolio JS
===================================================== */
/* Chat behavior moved to `bot/ai-chat.js` to avoid duplication. */