-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
372 lines (318 loc) · 12.4 KB
/
script.js
File metadata and controls
372 lines (318 loc) · 12.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
// ==============================
// Portfolio JavaScript for GitHub Pages
// ==============================
// DOM Elements Cache
const menuToggle = document.querySelector('.menu-toggle');
const navLinks = document.querySelector('.nav-links');
const contactForm = document.getElementById('contactForm');
const skillBars = document.querySelectorAll('.level-bar');
// Configuration
const CONFIG = {
EMAIL: 'saiyedatibali@gmail.com',
// Use same-origin file for a more reliable download on GitHub Pages.
RESUME_URL: './Atibali_Saiyed_Resume.pdf',
RESUME_FILENAME: 'Atibali_Saiyed_Resume.pdf',
GITHUB_USERNAME: 'atibali',
LINKEDIN_URL: 'https://www.linkedin.com/in/atibali-saiyed/'
};
/* -----------------------------
MOBILE NAVIGATION TOGGLE
------------------------------ */
const toggleMenu = () => {
navLinks.classList.toggle('active');
const isActive = navLinks.classList.contains('active');
menuToggle.innerHTML = isActive
? '<i class="fas fa-times"></i>'
: '<i class="fas fa-bars"></i>';
menuToggle.setAttribute('aria-expanded', String(isActive));
document.body.style.overflow = isActive ? 'hidden' : '';
};
if (menuToggle) {
menuToggle.addEventListener('click', toggleMenu);
}
window.addEventListener('resize', () => {
if (window.innerWidth > 768 && navLinks.classList.contains('active')) {
navLinks.classList.remove('active');
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
menuToggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
}
});
document.addEventListener('click', e => {
if (!navLinks.classList.contains('active')) return;
const isToggle = menuToggle.contains(e.target);
const isInsideNav = navLinks.contains(e.target);
if (isToggle || isInsideNav) return;
navLinks.classList.remove('active');
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
menuToggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
});
// Close menu when clicking on nav links
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
menuToggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
});
});
/* -----------------------------
ENHANCED SMOOTH SCROLLING
------------------------------ */
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', e => {
const targetId = anchor.getAttribute('href');
if (targetId === '#') return;
const target = document.querySelector(targetId);
if (!target) return;
e.preventDefault();
// Close mobile menu
if (navLinks.classList.contains('active')) {
navLinks.classList.remove('active');
menuToggle.innerHTML = '<i class="fas fa-bars"></i>';
menuToggle.setAttribute('aria-expanded', 'false');
document.body.style.overflow = '';
}
// Smooth scroll to target
window.scrollTo({
top: target.offsetTop - 100,
behavior: 'smooth'
});
});
});
/* -----------------------------
WORKING RESUME DOWNLOAD FUNCTIONALITY
------------------------------ */
function downloadResume() {
try {
// Show loading state on all resume buttons
const resumeBtns = document.querySelectorAll('.btn-resume, .btn-resume-small');
resumeBtns.forEach(btn => {
const originalText = btn.innerHTML;
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Preparing...';
btn.disabled = true;
// Reset button after 3 seconds
setTimeout(() => {
btn.innerHTML = originalText;
btn.disabled = false;
}, 3000);
});
// Method 1: Direct anchor download (works with raw GitHub URL)
const a = document.createElement('a');
a.href = CONFIG.RESUME_URL;
a.download = CONFIG.RESUME_FILENAME;
a.target = '_blank'; // Open in new tab if direct download doesn't work
a.rel = 'noopener noreferrer';
// Append to body, click, and remove
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
// Show success notification
setTimeout(() => {
showNotification('Resume download started.', 'success');
}, 1000);
} catch (error) {
console.error('Resume download failed:', error);
// Fallback: Open in new tab
window.open(CONFIG.RESUME_URL, '_blank', 'noopener,noreferrer');
showNotification('Opening resume in new tab...', 'info');
}
}
// Add event listeners to all resume buttons
document.addEventListener('DOMContentLoaded', () => {
// Add to existing resume buttons
document.querySelectorAll('.btn-resume, .btn-resume-small').forEach(btn => {
btn.addEventListener('click', (e) => {
e.preventDefault();
downloadResume();
});
});
// Add resume button to navbar dynamically
const navContainer = document.querySelector('.nav-links');
if (navContainer && !document.querySelector('.nav-resume-btn')) {
const resumeBtn = document.createElement('a');
resumeBtn.href = CONFIG.RESUME_URL;
resumeBtn.download = CONFIG.RESUME_FILENAME;
resumeBtn.className = 'btn-resume nav-resume-btn';
resumeBtn.innerHTML = '<i class="fas fa-download"></i> Resume';
resumeBtn.addEventListener('click', (e) => {
e.preventDefault();
downloadResume();
});
navContainer.appendChild(resumeBtn);
}
});
/* -----------------------------
WORKING EMAIL COPY FUNCTIONALITY
------------------------------ */
function copyEmail() {
// Method 1: Modern clipboard API
if (navigator.clipboard && window.isSecureContext) {
navigator.clipboard.writeText(CONFIG.EMAIL)
.then(() => {
showNotification('Email copied to clipboard.', 'success');
// Update button text temporarily
document.querySelectorAll('.btn-email').forEach(btn => {
const originalText = btn.textContent;
btn.innerHTML = '<i class="fas fa-check"></i> Copied!';
setTimeout(() => {
btn.innerHTML = originalText;
}, 2000);
});
})
.catch(err => {
console.error('Clipboard API failed:', err);
fallbackCopyEmail();
});
} else {
// Method 2: Fallback for older browsers
fallbackCopyEmail();
}
}
function fallbackCopyEmail() {
const textArea = document.createElement('textarea');
textArea.value = CONFIG.EMAIL;
// Make the textarea out of viewport
textArea.style.position = 'fixed';
textArea.style.left = '-999999px';
textArea.style.top = '-999999px';
document.body.appendChild(textArea);
textArea.focus();
textArea.select();
try {
const successful = document.execCommand('copy');
if (successful) {
showNotification('Email copied to clipboard.', 'success');
} else {
throw new Error('Copy command failed');
}
} catch (err) {
console.error('Fallback copy failed:', err);
showNotification('Failed to copy. Email: ' + CONFIG.EMAIL, 'info');
} finally {
document.body.removeChild(textArea);
}
}
// Add click event to all email buttons
document.querySelectorAll('.btn-email').forEach(btn => {
btn.addEventListener('click', e => {
e.preventDefault();
copyEmail();
});
});
/* -----------------------------
CONTACT FORM HANDLER FOR GITHUB PAGES
------------------------------ */
if (contactForm) {
contactForm.addEventListener('submit', async e => {
e.preventDefault();
const formData = new FormData(contactForm);
const data = Object.fromEntries(formData);
// Validation
if (!data.name || !data.email || !data.subject || !data.message) {
showNotification('Please fill in all required fields.', 'error');
return;
}
if (!isValidEmail(data.email)) {
showNotification('Please enter a valid email address.', 'error');
return;
}
const btn = contactForm.querySelector('button[type="submit"]');
const oldText = btn.innerHTML;
btn.innerHTML = '<i class="fas fa-spinner fa-spin"></i> Sending...';
btn.disabled = true;
try {
// Simulate sending
await new Promise(resolve => setTimeout(resolve, 1500));
// For GitHub Pages, open mail client with pre-filled details
const subject = encodeURIComponent(data.subject);
const body = encodeURIComponent(`Name: ${data.name}\nEmail: ${data.email}\n\nMessage: ${data.message}`);
const mailtoLink = `mailto:${CONFIG.EMAIL}?subject=${subject}&body=${body}`;
// Open mail client
window.open(mailtoLink, '_blank', 'noopener,noreferrer');
// Reset form
contactForm.reset();
// Show success message
showNotification('Opening email client... Please send the message.', 'info');
} catch (err) {
console.error('Form submission error:', err);
showNotification('Failed to send message. Please try again.', 'error');
} finally {
btn.innerHTML = oldText;
btn.disabled = false;
}
});
}
/* -----------------------------
NOTIFICATION SYSTEM
------------------------------ */
function showNotification(message, type = 'success') {
// Remove existing notification
const existing = document.querySelector('.notification');
if (existing) existing.remove();
// Create notification element
const notification = document.createElement('div');
notification.className = `notification ${type}`;
notification.innerHTML = `
<i class="fas fa-${type === 'success' ? 'check-circle' :
type === 'error' ? 'exclamation-circle' :
type === 'info' ? 'info-circle' : 'check-circle'}"></i>
<span>${message}</span>
`;
// Add to DOM
document.body.appendChild(notification);
// Auto remove after 4 seconds
setTimeout(() => {
if (notification.parentNode) {
notification.style.opacity = '0';
notification.style.transform = 'translateY(-20px)';
setTimeout(() => notification.remove(), 300);
}
}, 4000);
}
/* -----------------------------
SKILL BAR ANIMATION
------------------------------ */
const skillObserver = new IntersectionObserver(entries => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const bar = entry.target;
const width = bar.dataset.width;
setTimeout(() => {
bar.style.width = width;
}, 200);
skillObserver.unobserve(bar);
}
});
}, { threshold: 0.3 });
skillBars.forEach(bar => {
bar.style.width = '0';
bar.style.transition = 'width 1s ease-out';
skillObserver.observe(bar);
});
/* -----------------------------
NAVBAR SCROLL EFFECT
------------------------------ */
window.addEventListener('scroll', () => {
const navbar = document.querySelector('.navbar');
if (navbar) {
navbar.classList.toggle('scrolled', window.scrollY > 50);
}
});
/* -----------------------------
UTILITY FUNCTIONS
------------------------------ */
function isValidEmail(email) {
const re = /^[^\s@]+@[^\s@]+\.[^\s@]+$/;
return re.test(email);
}
/* -----------------------------
INITIALIZE ON LOAD
------------------------------ */
document.addEventListener('DOMContentLoaded', () => {
// Initialize animations
skillBars.forEach(bar => {
bar.style.width = '0';
});
});