Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
208 lines (183 loc) · 7.21 KB
/
Copy pathscript.js
File metadata and controls
208 lines (183 loc) · 7.21 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
// Portfolio Interactive Scripts for Kavya Krishnan
document.addEventListener('DOMContentLoaded', () => {
// 1. Typing effect for hero headline
const phrases = [
"Software Engineer @ Schneider Electric",
"Microservices & Distributed Systems",
"Large-Scale Telemetry & Cloud Platforms",
"FOSS@Amrita Alum & Open Source Contributor",
"Java, Spring Boot & Azure Developer"
];
const typingElement = document.getElementById('typing-text');
let phraseIndex = 0;
let charIndex = 0;
let isDeleting = false;
let typingDelay = 90;
function typeEffect() {
if (!typingElement) return;
const currentPhrase = phrases[phraseIndex];
if (isDeleting) {
typingElement.textContent = currentPhrase.substring(0, charIndex - 1);
charIndex--;
typingDelay = 40;
} else {
typingElement.textContent = currentPhrase.substring(0, charIndex + 1);
charIndex++;
typingDelay = 80;
}
if (!isDeleting && charIndex === currentPhrase.length) {
isDeleting = true;
typingDelay = 1800; // Pause at end of phrase
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % phrases.length;
typingDelay = 400; // Pause before typing next phrase
}
setTimeout(typeEffect, typingDelay);
}
typeEffect();
// 2. Theme Toggle (Dark / Light)
const themeToggleBtn = document.getElementById('theme-toggle');
const themeIconDark = document.getElementById('theme-icon-dark');
const themeIconLight = document.getElementById('theme-icon-light');
// Check saved theme or default to dark
const savedTheme = localStorage.getItem('kavya-portfolio-theme') || 'dark';
if (savedTheme === 'light') {
document.documentElement.classList.add('light');
if (themeIconDark) themeIconDark.classList.remove('hidden');
if (themeIconLight) themeIconLight.classList.add('hidden');
} else {
document.documentElement.classList.remove('light');
if (themeIconDark) themeIconDark.classList.add('hidden');
if (themeIconLight) themeIconLight.classList.remove('hidden');
}
if (themeToggleBtn) {
themeToggleBtn.addEventListener('click', () => {
const isLight = document.documentElement.classList.toggle('light');
localStorage.setItem('kavya-portfolio-theme', isLight ? 'light' : 'dark');
if (themeIconDark && themeIconLight) {
if (isLight) {
themeIconDark.classList.remove('hidden');
themeIconLight.classList.add('hidden');
} else {
themeIconDark.classList.add('hidden');
themeIconLight.classList.remove('hidden');
}
}
showToast(isLight ? 'Switched to Light mode' : 'Switched to Dark mode');
});
}
// 3. Copy Email to Clipboard
const copyButtons = document.querySelectorAll('.copy-email-btn');
copyButtons.forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
const email = '[email protected]';
navigator.clipboard.writeText(email).then(() => {
showToast('Copied [email protected] to clipboard! 📋');
// Visual indicator
const iconSpan = btn.querySelector('.copy-icon');
if (iconSpan) {
const original = iconSpan.innerHTML;
iconSpan.innerHTML = '✓ Copied';
setTimeout(() => { iconSpan.innerHTML = original; }, 2000);
}
}).catch(err => {
showToast('Email: [email protected]');
});
});
});
// 4. Toast Notification Utility
const toast = document.getElementById('toast');
let toastTimeout;
function showToast(message) {
if (!toast) return;
toast.textContent = message;
toast.classList.add('show');
clearTimeout(toastTimeout);
toastTimeout = setTimeout(() => {
toast.classList.remove('show');
}, 3000);
}
window.showToast = showToast;
// 5. Project Filtering
const filterBtns = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
filterBtns.forEach(b => {
b.classList.remove('active', 'bg-emerald-500/20', 'text-emerald-400', 'border-emerald-500/40');
b.classList.add('bg-slate-800/40', 'text-slate-400', 'border-slate-700/50');
});
btn.classList.add('active', 'bg-emerald-500/20', 'text-emerald-400', 'border-emerald-500/40');
btn.classList.remove('bg-slate-800/40', 'text-slate-400', 'border-slate-700/50');
const filter = btn.getAttribute('data-filter');
projectCards.forEach(card => {
const category = card.getAttribute('data-category') || '';
if (filter === 'all' || category.includes(filter)) {
card.style.display = 'block';
card.classList.add('animate-fade-in');
} else {
card.style.display = 'none';
}
});
});
});
// 6. Mobile Hamburger Menu Toggle
const mobileMenuBtn = document.getElementById('mobile-menu-btn');
const mobileMenu = document.getElementById('mobile-menu');
if (mobileMenuBtn && mobileMenu) {
mobileMenuBtn.addEventListener('click', () => {
mobileMenu.classList.toggle('hidden');
});
// Close mobile menu on clicking any link
mobileMenu.querySelectorAll('a').forEach(link => {
link.addEventListener('click', () => {
mobileMenu.classList.add('hidden');
});
});
}
// 7. Active Navigation Spy on Scroll
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
window.addEventListener('scroll', () => {
let current = '';
const scrollY = window.pageYOffset;
sections.forEach(section => {
const sectionHeight = section.offsetHeight;
const sectionTop = section.offsetTop - 120;
const sectionId = section.getAttribute('id');
if (scrollY > sectionTop && scrollY <= sectionTop + sectionHeight) {
current = sectionId;
}
});
navLinks.forEach(link => {
link.classList.remove('text-emerald-400', 'font-semibold');
if (link.getAttribute('href') === `#${current}`) {
link.classList.add('text-emerald-400', 'font-semibold');
}
});
});
// 8. Contact Form Handling
const contactForm = document.getElementById('contact-form');
if (contactForm) {
contactForm.addEventListener('submit', (e) => {
e.preventDefault();
const name = document.getElementById('sender-name')?.value || '';
const email = document.getElementById('sender-email')?.value || '';
const subject = document.getElementById('sender-subject')?.value || 'Message from Portfolio';
const message = document.getElementById('sender-message')?.value || '';
if (!name || !email || !message) {
showToast('Please fill in all required fields.');
return;
}
// Compose mailto link as direct fallback
const mailtoUrl = `mailto:[email protected]?subject=${encodeURIComponent(subject + ' - via ' + name)}&body=${encodeURIComponent("From: " + name + " (" + email + ")\n\n" + message)}`;
showToast('Opening email client to send message... 🚀');
setTimeout(() => {
window.location.href = mailtoUrl;
contactForm.reset();
}, 700);
});
}
});