-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
170 lines (143 loc) · 4.91 KB
/
Copy pathscript.js
File metadata and controls
170 lines (143 loc) · 4.91 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
// ─── LOADER ───
window.addEventListener('load', function() {
setTimeout(function() {
document.getElementById('loader').classList.add('hidden');
}, 1500);
});
// ─── MOBILE MENU ───
function toggleMobileMenu() {
document.getElementById('navLinks').classList.toggle('active');
}
function closeMobileMenu() {
document.getElementById('navLinks').classList.remove('active');
}
// ─── SCROLL REVEAL ───
const revealObserver = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
e.target.classList.add('visible');
revealObserver.unobserve(e.target);
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.reveal').forEach(el => revealObserver.observe(el));
const cardObserver = new IntersectionObserver(entries => {
entries.forEach(e => {
if (e.isIntersecting) {
const delay = parseInt(e.target.dataset.delay || '0');
setTimeout(() => e.target.classList.add('visible'), delay * 170);
cardObserver.unobserve(e.target);
}
});
}, { threshold: 0.1 });
document.querySelectorAll('.card').forEach(el => cardObserver.observe(el));
// ─── ACTIVE NAV HIGHLIGHT ───
const sections = document.querySelectorAll('section[id]');
const navLinks = document.querySelectorAll('.nav-links a');
const activateLink = () => {
let current = '';
sections.forEach(s => {
if (window.scrollY >= s.offsetTop - 120) current = s.id;
});
navLinks.forEach(a => {
a.style.color = a.getAttribute('href') === `#${current}` ? 'var(--amber)' : '';
});
};
window.addEventListener('scroll', activateLink, { passive: true });
// ─── CERTIFICATE REQUEST ───
function openCertRequest() {
document.getElementById('certModal').style.display = 'flex';
document.getElementById('certRequestForm').style.display = 'block';
const oldSuccess = document.querySelector('.cert-modal-success');
if (oldSuccess) oldSuccess.remove();
document.getElementById('certRequestForm').reset();
}
function closeCertRequest() {
document.getElementById('certModal').style.display = 'none';
}
document.getElementById('certModal').addEventListener('click', function(e) {
if (e.target === this) closeCertRequest();
});
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape') closeCertRequest();
});
async function sendCertRequest(event) {
event.preventDefault();
const form = document.getElementById('certRequestForm');
const formData = new FormData(form);
const selectedCerts = formData.getAll('certificates');
if (selectedCerts.length === 0) {
alert('Please select at least one certificate to request.');
return;
}
try {
const response = await fetch(form.action, {
method: 'POST',
body: formData,
headers: { 'Accept': 'application/json' }
});
if (response.ok) {
form.style.display = 'none';
const successHTML = `
<div class="cert-modal-success">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.5" width="56" height="56">
<circle cx="12" cy="12" r="10"/>
<path d="M8 12l3 3 5-5"/>
</svg>
<h4>Request Sent!</h4>
<p>Thank you! Your request has been received.<br>I will review it and get back to you soon.</p>
</div>
`;
form.insertAdjacentHTML('afterend', successHTML);
setTimeout(closeCertRequest, 4000);
} else {
alert('Oops! Something went wrong. Please try again or email me directly at mksajid087@gmail.com');
}
} catch (error) {
alert('Network error. Please check your connection and try again.');
}
}
// ─── TYPEWRITER EFFECT ───
const words = ["Designer", "Simulator", "Analyst"];
let wordIndex = 0;
let charIndex = 0;
let isDeleting = false;
const typewriterEl = document.getElementById("typewriter");
function typeEffect() {
const currentWord = words[wordIndex];
if (!isDeleting) {
typewriterEl.textContent = currentWord.substring(0, charIndex + 1);
charIndex++;
if (charIndex === currentWord.length) {
setTimeout(() => {
isDeleting = true;
typeEffect(); // <-- continue after changing state
}, 1500);
return;
}
} else {
typewriterEl.textContent = currentWord.substring(0, charIndex - 1);
charIndex--;
if (charIndex === 0) {
isDeleting = false;
wordIndex = (wordIndex + 1) % words.length;
setTimeout(typeEffect, 300);
return;
}
}
const speed = isDeleting ? 50 : 100;
setTimeout(typeEffect, speed);
}
setTimeout(typeEffect, 1200);
// ─── THEME TOGGLE ───
function toggleTheme() {
document.body.classList.toggle('light');
const isLight = document.body.classList.contains('light');
localStorage.setItem('theme', isLight ? 'light' : 'dark');
}
(function() {
const savedTheme = localStorage.getItem('theme');
if (savedTheme === 'light') {
document.body.classList.add('light');
}
})();