Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
148 lines (127 loc) · 4.73 KB
/
Copy pathscript.js
File metadata and controls
148 lines (127 loc) · 4.73 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
/**
* Portfolio JavaScript — Md. Rakibul Islam (Baadal)
* Lightweight, 60fps, Zero-dependency Executive Script
*/
document.addEventListener('DOMContentLoaded', () => {
// ================= 1. MOBILE NAVIGATION TOGGLE =================
const mobileToggle = document.getElementById('mobile-toggle');
const navMenu = document.getElementById('nav-menu');
if (mobileToggle && navMenu) {
mobileToggle.addEventListener('click', () => {
const isOpen = navMenu.classList.toggle('open');
mobileToggle.innerHTML = isOpen
? '<i class="fa-solid fa-xmark"></i>'
: '<i class="fa-solid fa-bars"></i>';
});
// Close menu when clicking any nav link
document.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navMenu.classList.remove('open');
mobileToggle.innerHTML = '<i class="fa-solid fa-bars"></i>';
});
});
}
// ================= 2. ACTIVE NAVIGATION SPY =================
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-link');
function updateActiveNavLink() {
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) {
navLinks.forEach(link => {
link.classList.remove('active');
if (link.getAttribute('href') === `#${sectionId}`) {
link.classList.add('active');
}
});
}
});
}
window.addEventListener('scroll', updateActiveNavLink, { passive: true });
// ================= 3. PROJECT FILTER TABS =================
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'));
btn.classList.add('active');
const filterValue = btn.dataset.filter;
projectCards.forEach(card => {
const categories = (card.dataset.category || '').split(' ');
if (filterValue === 'all' || categories.includes(filterValue)) {
card.style.display = 'flex';
card.style.animation = 'fadeIn 0.3s ease-out';
} else {
card.style.display = 'none';
}
});
});
});
// ================= 4. COPY EMAIL TO CLIPBOARD =================
const copyBtn = document.getElementById('copy-email-btn');
const emailText = document.getElementById('email-text');
const copyTooltip = document.getElementById('copy-tooltip');
if (copyBtn && emailText && copyTooltip) {
copyBtn.addEventListener('click', async () => {
const email = emailText.textContent.trim();
try {
await navigator.clipboard.writeText(email);
copyTooltip.textContent = 'Copied!';
copyBtn.style.background = 'var(--accent-emerald)';
copyBtn.style.color = 'var(--text-dark)';
setTimeout(() => {
copyTooltip.textContent = 'Copy';
copyBtn.style.background = '';
copyBtn.style.color = '';
}, 2000);
} catch (err) {
// Fallback for older browsers
const textarea = document.createElement('textarea');
textarea.value = email;
document.body.appendChild(textarea);
textarea.select();
document.execCommand('copy');
document.body.removeChild(textarea);
copyTooltip.textContent = 'Copied!';
setTimeout(() => {
copyTooltip.textContent = 'Copy';
}, 2000);
}
});
}
// ================= 5. HEADER SCROLL ELEVATION =================
const header = document.getElementById('header');
window.addEventListener('scroll', () => {
if (window.scrollY > 40) {
header.style.boxShadow = '0 10px 30px rgba(0, 0, 0, 0.5)';
header.style.background = 'rgba(7, 10, 18, 0.9)';
} else {
header.style.boxShadow = '';
header.style.background = 'rgba(7, 10, 18, 0.75)';
}
}, { passive: true });
});
// ================= 6. RESUME MODAL HANDLERS (GLOBAL) =================
function openResumeModal() {
const modal = document.getElementById('resume-modal');
if (modal) {
modal.classList.add('active');
document.body.style.overflow = 'hidden';
}
}
function closeResumeModal(event) {
if (event) event.preventDefault();
const modal = document.getElementById('resume-modal');
if (modal) {
modal.classList.remove('active');
document.body.style.overflow = '';
}
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') {
closeResumeModal();
}
});