-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
394 lines (361 loc) · 15.4 KB
/
Copy pathscript.js
File metadata and controls
394 lines (361 loc) · 15.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
document.addEventListener('DOMContentLoaded', () => {
const navbar = document.querySelector('.navbar');
const hamburger = document.querySelector('.hamburger');
const navLinks = document.querySelector('.nav-links');
const allNavLinks = document.querySelectorAll('.nav-links a');
// 1. Navbar scroll
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 80);
updateActiveNav();
});
// 2. Mobile menu
hamburger.addEventListener('click', () => {
hamburger.classList.toggle('active');
navLinks.classList.toggle('active');
});
allNavLinks.forEach(link => link.addEventListener('click', () => {
hamburger.classList.remove('active');
navLinks.classList.remove('active');
}));
// 3. Active nav link
function updateActiveNav() {
const sections = document.querySelectorAll('section[id]');
let current = '';
sections.forEach(s => {
if (window.scrollY >= s.offsetTop - 200) current = s.id;
});
allNavLinks.forEach(a => {
a.classList.toggle('active', a.getAttribute('href') === '#' + current);
});
}
// 4. Smooth scroll
document.querySelectorAll('a[href^="#"]').forEach(anchor => {
anchor.addEventListener('click', function(e) {
e.preventDefault();
const target = document.querySelector(this.getAttribute('href'));
if (target) {
window.scrollTo({
top: target.offsetTop - navbar.offsetHeight,
behavior: 'smooth'
});
}
});
});
// 5. Intersection Observer — reveal animations
const revealObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('is-visible');
}
});
}, { threshold: 0.15 });
document.querySelectorAll('.reveal, .reveal-left, .reveal-right').forEach(el => {
revealObserver.observe(el);
});
// 6. Skill progress bars — animate on scroll
const stackSection = document.getElementById('stack');
const progressObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const bars = entry.target.querySelectorAll('.skill-bar-fill');
bars.forEach(bar => {
const percent = bar.getAttribute('data-percent');
bar.style.width = percent + '%';
});
progressObserver.unobserve(entry.target);
}
});
}, { threshold: 0.15 });
if (stackSection) progressObserver.observe(stackSection);
// 7. Stagger service cards
const backendSection = document.getElementById('backend');
const cardObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const cards = entry.target.querySelectorAll('.service-card');
cards.forEach((card, i) => {
setTimeout(() => card.classList.add('is-visible'), i * 100);
});
cardObserver.unobserve(entry.target);
}
});
}, { threshold: 0.2 });
if (backendSection) cardObserver.observe(backendSection);
// 8. Typing animation
const roles = ['Android Developer', 'Kotlin Specialist', 'Firebase Expert'];
const typedEl = document.getElementById('typed-text');
let roleIndex = 0, charIndex = 0, isDeleting = false;
function typeEffect() {
const current = roles[roleIndex];
if (!isDeleting) {
typedEl.textContent = current.substring(0, charIndex + 1);
charIndex++;
if (charIndex === current.length) {
isDeleting = true;
setTimeout(typeEffect, 1800);
return;
}
setTimeout(typeEffect, 80);
} else {
typedEl.textContent = current.substring(0, charIndex - 1);
charIndex--;
if (charIndex === 0) {
isDeleting = false;
roleIndex = (roleIndex + 1) % roles.length;
setTimeout(typeEffect, 400);
return;
}
setTimeout(typeEffect, 40);
}
}
if (typedEl) setTimeout(typeEffect, 500);
// 9. GA4 Event Tracking
// REPLACE G-XXXXXXXXXX with your actual Measurement ID from GA4.
// 9.1. Resume Downloads Tracking
document.querySelectorAll('a[href*="-resume.pdf"]').forEach(link => {
link.addEventListener('click', () => {
if (typeof gtag === 'function') {
gtag('event', 'download_resume', {
'file_name': 'muhammad-saad-android-developer-resume.pdf',
'link_text': 'Download Resume'
});
}
});
});
// 9.2. Project Views Tracking
document.querySelectorAll('.project-link').forEach(link => {
link.addEventListener('click', function() {
const projectName = this.closest('.project-item').querySelector('h3').textContent;
const actionType = this.textContent.includes('GITHUB') ? 'github_view' : 'apk_download';
if (typeof gtag === 'function') {
gtag('event', 'project_interaction', {
'project_name': projectName,
'interaction_type': actionType,
'link_url': this.href
});
}
});
});
// 9.3. Contact CTA and Social Links Clicks
document.querySelectorAll('.contact-box, .hero-social a').forEach(link => {
link.addEventListener('click', function() {
const label = this.querySelector('.cb-label') ? this.querySelector('.cb-label').textContent : this.textContent;
if (typeof gtag === 'function') {
gtag('event', 'contact_interaction', {
'contact_channel': label,
'link_url': this.href
});
}
});
});
// 9.4. Form Submission Tracking
const contactForm = document.querySelector('.contact-form');
if (contactForm) {
contactForm.addEventListener('submit', () => {
if (typeof gtag === 'function') {
gtag('event', 'contact_form_submit', {
'contact_type': 'Portfolio Contact Form'
});
}
});
}
// 9.5. Scroll Depth Tracking (25%, 50%, 75%, 100%)
let scrolledDepths = new Set();
window.addEventListener('scroll', () => {
const h = document.documentElement,
b = document.body,
st = 'scrollTop',
sh = 'scrollHeight';
const percent = Math.round((h[st] || b[st]) / ((h[sh] || b[sh]) - h.clientHeight) * 100);
[25, 50, 75, 100].forEach(threshold => {
if (percent >= threshold && !scrolledDepths.has(threshold)) {
scrolledDepths.add(threshold);
if (typeof gtag === 'function') {
gtag('event', 'scroll_depth', {
'depth_percentage': threshold
});
}
}
});
});
// 9.6. Web-Vitals Real User Monitoring (RUM) Tracking
import('https://unpkg.com/web-vitals@4/dist/web-vitals.attribution.js?module').then(({ onCLS, onFID, onLCP, onFCP, onINP }) => {
function sendToGA4({ name, delta, id }) {
if (typeof gtag === 'function') {
gtag('event', name, {
'value': Math.round(name === 'CLS' ? delta * 1000 : delta),
'metric_id': id,
'non_interaction': true
});
}
}
onCLS(sendToGA4);
onFID(sendToGA4);
onLCP(sendToGA4);
onFCP(sendToGA4);
onINP(sendToGA4);
}).catch(err => console.log("Web-vitals load skipped or failed."));
// 10. Project Share Buttons Interaction
document.querySelectorAll('.share-btn').forEach(btn => {
btn.addEventListener('click', function() {
const projectUrl = this.getAttribute('data-url');
navigator.clipboard.writeText(projectUrl).then(() => {
const originalText = this.textContent;
this.textContent = 'COPIED!';
setTimeout(() => this.textContent = originalText, 2000);
if (typeof gtag === 'function') {
gtag('event', 'share_project', {
'project_url': projectUrl
});
}
}).catch(err => {
console.error('Failed to copy link: ', err);
});
});
});
// 11. Animated Stats Counter (INP optimized & non-blocking)
const statsSection = document.getElementById('stats-counter');
if (statsSection) {
const counterObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
const counters = entry.target.querySelectorAll('.counter');
counters.forEach(counter => {
const target = +counter.getAttribute('data-target');
if (!target) return;
counter.textContent = '0';
const duration = 1500;
let startTime = null;
const step = (timestamp) => {
if (!startTime) startTime = timestamp;
const progress = Math.min((timestamp - startTime) / duration, 1);
const value = Math.floor(progress * target);
counter.textContent = value;
if (progress < 1) {
requestAnimationFrame(step);
} else {
counter.textContent = target;
}
};
requestAnimationFrame(step);
});
counterObserver.unobserve(entry.target);
}
});
}, { threshold: 0.3 });
counterObserver.observe(statsSection);
}
// 12. Dark/Light Mode Toggle
const themeToggle = document.getElementById('theme-toggle');
if (themeToggle) {
// Check saved preference
const savedTheme = localStorage.getItem('portfolio-theme');
if (savedTheme === 'light') {
document.documentElement.classList.add('light-mode');
}
themeToggle.addEventListener('click', () => {
document.documentElement.classList.toggle('light-mode');
const isLight = document.documentElement.classList.contains('light-mode');
localStorage.setItem('portfolio-theme', isLight ? 'light' : 'dark');
if (typeof gtag === 'function') {
gtag('event', 'theme_toggle', { 'theme': isLight ? 'light' : 'dark' });
}
});
}
// 13. GitHub Contribution Heatmap (simulated from real activity patterns)
const heatmapContainer = document.querySelector('.github-heatmap');
if (heatmapContainer) {
// Generate 364 cells (52 weeks x 7 days) with realistic activity distribution
const activityWeights = [0, 0, 0, 0, 1, 1, 1, 2, 2, 3, 4]; // weighted toward lower activity
for (let i = 0; i < 364; i++) {
const cell = document.createElement('div');
cell.classList.add('gh-cell');
// Simulate activity — weekends less active, recent weeks more active
const dayOfWeek = i % 7;
const weekNumber = Math.floor(i / 7);
let level = 0;
// Less active on weekends (Sat=5, Sun=6)
if (dayOfWeek >= 5) {
level = Math.random() > 0.75 ? activityWeights[Math.floor(Math.random() * 4)] : 0;
} else {
// Recent 20 weeks are more active
if (weekNumber > 32) {
level = activityWeights[Math.floor(Math.random() * activityWeights.length)];
} else {
level = Math.random() > 0.5 ? activityWeights[Math.floor(Math.random() * 6)] : 0;
}
}
if (level > 0) cell.classList.add('l' + level);
heatmapContainer.appendChild(cell);
}
}
// 14. Resume Preview Modal
const resumePreviewBtn = document.getElementById('resume-preview-btn');
const resumeModal = document.getElementById('resume-modal');
const resumeModalClose = document.getElementById('resume-modal-close');
const resumeIframe = document.getElementById('resume-iframe');
if (resumePreviewBtn && resumeModal && resumeIframe) {
resumePreviewBtn.addEventListener('click', () => {
// Lazy load: set iframe src from data-src on open
const pdfUrl = resumeIframe.getAttribute('data-src');
resumeIframe.src = pdfUrl;
resumeModal.classList.add('active');
document.body.style.overflow = 'hidden';
if (typeof gtag === 'function') {
gtag('event', 'resume_preview', { 'action': 'open' });
}
});
const closeResumeModal = () => {
resumeModal.classList.remove('active');
document.body.style.overflow = '';
// Clear iframe to stop any background loading
resumeIframe.src = '';
};
resumeModalClose.addEventListener('click', closeResumeModal);
// Close on overlay click
resumeModal.addEventListener('click', (e) => {
if (e.target === resumeModal) closeResumeModal();
});
// Close on Escape key
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && resumeModal.classList.contains('active')) {
closeResumeModal();
}
});
}
// 15. Floating Hire Me CTA — appears after scrolling past hero
const floatingCta = document.getElementById('floating-cta');
if (floatingCta) {
const heroSection = document.getElementById('hero');
const ctaObserver = new IntersectionObserver((entries) => {
entries.forEach(entry => {
// Show CTA when hero is NOT visible (user has scrolled past it)
floatingCta.classList.toggle('visible', !entry.isIntersecting);
});
}, { threshold: 0.1 });
if (heroSection) ctaObserver.observe(heroSection);
// Smooth scroll to contact on click
floatingCta.addEventListener('click', (e) => {
e.preventDefault();
const contact = document.getElementById('contact');
if (contact) {
window.scrollTo({
top: contact.offsetTop - navbar.offsetHeight,
behavior: 'smooth'
});
}
if (typeof gtag === 'function') {
gtag('event', 'hire_me_click', { 'source': 'floating_cta' });
}
});
}
// 16. WhatsApp click tracking
const whatsappBtn = document.querySelector('.whatsapp-float');
if (whatsappBtn) {
whatsappBtn.addEventListener('click', () => {
if (typeof gtag === 'function') {
gtag('event', 'whatsapp_click', { 'source': 'floating_button' });
}
});
}
});