-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
410 lines (346 loc) Β· 14 KB
/
Copy pathscript.js
File metadata and controls
410 lines (346 loc) Β· 14 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
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
// ==================== TYPING ANIMATION ====================
const typingPhrases = [
'Master 2 Computer Science β’ University of Algiers',
'Full-Stack Developer',
'Final Year Project, Beez AI for Beehive Management',
];
let phraseIndex = 0;
let charIndex = 0;
let isDeleting = false;
const typingEl = document.getElementById('typing-text');
function typeEffect() {
const current = typingPhrases[phraseIndex];
if (isDeleting) {
typingEl.textContent = current.substring(0, charIndex - 1);
charIndex--;
} else {
typingEl.textContent = current.substring(0, charIndex + 1);
charIndex++;
}
let speed = isDeleting ? 30 : 60;
if (!isDeleting && charIndex === current.length) {
speed = 2000;
isDeleting = true;
} else if (isDeleting && charIndex === 0) {
isDeleting = false;
phraseIndex = (phraseIndex + 1) % typingPhrases.length;
speed = 400;
}
setTimeout(typeEffect, speed);
}
typeEffect();
// ==================== TOAST NOTIFICATION SYSTEM ====================
function showToast(message, type = 'info') {
const existing = document.querySelector('.toast');
if (existing) existing.remove();
const toast = document.createElement('div');
toast.className = 'toast';
const icons = {
info: 'fa-circle-info',
warning: 'fa-triangle-exclamation',
error: 'fa-circle-exclamation',
success: 'fa-circle-check'
};
toast.innerHTML = `
<i class="fas ${icons[type]} toast-icon"></i>
<span class="toast-message">${message}</span>
<button class="toast-close" aria-label="Close">×</button>
`;
document.body.appendChild(toast);
setTimeout(() => toast.classList.add('show'), 10);
const timeout = setTimeout(() => hideToast(toast), 4000);
toast.querySelector('.toast-close').addEventListener('click', () => {
clearTimeout(timeout);
hideToast(toast);
});
}
function hideToast(toast) {
toast.classList.remove('show');
setTimeout(() => toast.remove(), 400);
}
// ==================== LINK INTERCEPTION ====================
function isPlaceholderLink(href) {
return !href || href === '#' || href.endsWith('#') ||
href.toLowerCase().includes('coming soon') ||
href === window.location.href.split('#')[0] + '#';
}
function handleLinkClick(e, href, element) {
const isComingSoon = element.closest('[data-status="coming-soon"]') ||
element.textContent.toLowerCase().includes('coming soon') ||
element.closest('.project-card')?.querySelector('p')?.textContent.toLowerCase().includes('coming soon');
if (isPlaceholderLink(href) || isComingSoon) {
e.preventDefault();
showToast('π§ This feature is coming soon! Check back later.', 'warning');
return false;
}
if (href && !href.startsWith('http') && !href.startsWith('#') && !href.startsWith('mailto:')) {
fetch(href, { method: 'HEAD' })
.then(response => {
if (!response.ok) {
showToast('π File not found. Please check back later!', 'error');
}
})
.catch(() => {
if (href.toLowerCase().endsWith('.pdf') || href.toLowerCase().endsWith('.zip')) {
console.warn(`Could not verify file: ${href}`);
}
});
}
return true;
}
document.addEventListener('click', (e) => {
const link = e.target.closest('a[href]');
if (!link) return;
const href = link.getAttribute('href');
if (href.startsWith('http') || href.startsWith('mailto:') || href.startsWith('tel:')) {
return;
}
if (href.startsWith('#')) {
if (href !== '#') {
e.preventDefault();
const target = document.querySelector(href);
if (target) {
target.scrollIntoView({ behavior: 'smooth' });
navLinks.classList.remove('active');
} else {
showToast('β οΈ Section not found on this page.', 'info');
}
}
return;
}
handleLinkClick(e, href, link);
});
// Modal link handlers
document.addEventListener('DOMContentLoaded', () => {
const modalDemoLink = document.getElementById('modal-demo-link');
const modalGithubLink = document.getElementById('modal-github-link');
if (modalDemoLink) {
modalDemoLink.addEventListener('click', (e) => {
const href = modalDemoLink.getAttribute('href');
if (isPlaceholderLink(href)) {
e.preventDefault();
showToast('π Live demo coming soon! The project is still in development.', 'warning');
}
});
}
if (modalGithubLink) {
modalGithubLink.addEventListener('click', (e) => {
const href = modalGithubLink.getAttribute('href');
if (href === '#' || href.endsWith('/')) {
e.preventDefault();
showToast('π» Source code will be available soon!', 'warning');
}
});
}
});
// ==================== NAVIGATION ====================
const hamburger = document.getElementById('hamburger');
const navLinks = document.getElementById('nav-links');
const navbar = document.getElementById('navbar');
hamburger.addEventListener('click', () => {
navLinks.classList.toggle('active');
hamburger.textContent = navLinks.classList.contains('active') ? 'β' : 'β°';
});
document.querySelectorAll('.nav-links a').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
hamburger.textContent = 'β°';
});
});
// Navbar scroll effect
window.addEventListener('scroll', () => {
navbar.classList.toggle('scrolled', window.scrollY > 50);
});
// Active nav link highlight
const sections = document.querySelectorAll('section[id]');
window.addEventListener('scroll', () => {
const scrollY = window.scrollY + 120;
sections.forEach(section => {
const top = section.offsetTop;
const height = section.offsetHeight;
const id = section.getAttribute('id');
const link = document.querySelector(`.nav-links a[href="#${id}"]`);
if (link) {
link.classList.toggle('active', scrollY >= top && scrollY < top + height);
}
});
});
// ==================== ANIMATIONS ====================
const fadeElements = document.querySelectorAll('.fade-in');
const observer = new IntersectionObserver((entries) => {
entries.forEach(entry => {
if (entry.isIntersecting) {
entry.target.classList.add('visible');
// Animate ALL progress bars in the category with staggered delay
const progressBars = entry.target.querySelectorAll('.progress[data-width]');
progressBars.forEach((bar, index) => {
setTimeout(() => {
bar.style.width = bar.dataset.width + '%';
}, 150 + (index * 60));
});
// Animate stat numbers (if any)
const statNumbers = entry.target.querySelectorAll('.stat-number[data-count]');
statNumbers.forEach(stat => {
animateCounter(stat, parseInt(stat.dataset.count));
});
}
});
}, { threshold: 0.15 });
fadeElements.forEach(el => observer.observe(el));
function animateCounter(el, target) {
let current = 0;
const step = Math.ceil(target / 30);
const interval = setInterval(() => {
current += step;
if (current >= target) {
current = target;
clearInterval(interval);
}
el.textContent = current + '+';
}, 40);
}
// ==================== BACK TO TOP & SHARE BUTTON ====================
const backToTop = document.getElementById('back-to-top');
const shareBtn = document.getElementById('share-btn');
window.addEventListener('scroll', () => {
const scrolled = window.scrollY > 500;
backToTop.style.display = scrolled ? 'flex' : 'none';
if (shareBtn) shareBtn.classList.toggle('shifted', scrolled);
});
backToTop.addEventListener('click', () => window.scrollTo({ top: 0, behavior: 'smooth' }));
// ==================== THEME TOGGLE ====================
const themeToggle = document.getElementById('theme-toggle');
// Check saved preference
if (localStorage.getItem('theme') === 'light') {
document.body.classList.add('light-mode');
themeToggle.innerHTML = '<i class="fas fa-sun" style="color:#f59e0b;"></i>';
}
themeToggle.addEventListener('click', () => {
document.body.classList.toggle('light-mode');
const isLight = document.body.classList.contains('light-mode');
themeToggle.innerHTML = isLight
? '<i class="fas fa-sun" style="color:#f59e0b;"></i>'
: '<i class="fas fa-moon" style="color:white;"></i>';
localStorage.setItem('theme', isLight ? 'light' : 'dark');
});
// ==================== PROJECT MODAL ====================
const modal = document.getElementById('project-modal');
const modalTitle = document.getElementById('modal-title');
const modalFullDesc = document.getElementById('modal-full-desc');
const modalImg = document.getElementById('modal-img');
const modalTechContainer = document.getElementById('modal-tech');
const modalDemoLink = document.getElementById('modal-demo-link');
const modalGithubLink = document.getElementById('modal-github-link');
const modalClose = document.getElementById('modal-close');
function closeModal() {
modal.style.display = 'none';
document.body.style.overflow = '';
}
modalClose.addEventListener('click', closeModal);
modal.addEventListener('click', (e) => {
if (e.target === modal) closeModal();
});
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape') closeModal();
});
document.querySelectorAll('.project-card').forEach(card => {
card.addEventListener('click', () => {
const title = card.getAttribute('data-title');
const description = card.getAttribute('data-description');
const fullDesc = card.getAttribute('data-full-desc');
const techString = card.getAttribute('data-tech');
const demo = card.getAttribute('data-demo');
const github = card.getAttribute('data-github');
modalTitle.textContent = title;
modalFullDesc.innerHTML = `<strong>Short description:</strong> ${description}<br><br>${fullDesc}`;
modalImg.textContent = 'Project Screenshot (larger view)';
modalTechContainer.innerHTML = '';
if (techString) {
techString.split(',').forEach(tech => {
const span = document.createElement('span');
span.textContent = tech.trim();
modalTechContainer.appendChild(span);
});
}
modalDemoLink.href = demo || '#';
modalGithubLink.href = github || '#';
if (isPlaceholderLink(demo)) {
modalDemoLink.style.pointerEvents = 'none';
modalDemoLink.style.opacity = '0.5';
modalDemoLink.title = 'Demo coming soon';
} else {
modalDemoLink.style.pointerEvents = 'auto';
modalDemoLink.style.opacity = '1';
modalDemoLink.title = '';
}
if (isPlaceholderLink(github) || github?.includes('yourusername')) {
modalGithubLink.style.pointerEvents = 'none';
modalGithubLink.style.opacity = '0.5';
modalGithubLink.title = 'GitHub repo coming soon';
} else {
modalGithubLink.style.pointerEvents = 'auto';
modalGithubLink.style.opacity = '1';
modalGithubLink.title = '';
}
modal.style.display = 'flex';
document.body.style.overflow = 'hidden';
});
});
// ==================== QR CODE SHARE MODAL ====================
const qrModal = document.getElementById('qr-modal');
const qrModalClose = document.getElementById('qr-modal-close');
const qrUrlText = document.getElementById('qr-url');
const downloadQrBtn = document.getElementById('download-qr');
const qrImage = document.getElementById('qr-image');
function openQrModal() {
qrUrlText.textContent = window.location.href;
qrModal.style.display = 'flex';
document.body.style.overflow = 'hidden';
}
function closeQrModal() {
qrModal.style.display = 'none';
document.body.style.overflow = '';
}
if (shareBtn) {
shareBtn.addEventListener('click', openQrModal);
}
if (qrModalClose) {
qrModalClose.addEventListener('click', closeQrModal);
}
if (qrModal) {
qrModal.addEventListener('click', (e) => {
if (e.target === qrModal) closeQrModal();
});
}
document.addEventListener('keydown', (e) => {
if (e.key === 'Escape' && qrModal && qrModal.style.display === 'flex') {
closeQrModal();
}
});
if (downloadQrBtn) {
downloadQrBtn.addEventListener('click', () => {
const link = document.createElement('a');
link.href = './assets/qr-code.png';
link.download = 'rouibah-hanine-portfolio-qr.png';
link.click();
showToast('β
QR code downloaded!', 'success');
});
}
// ==================== PROTECTION ====================
document.addEventListener('contextmenu', (event) => event.preventDefault());
document.addEventListener('keydown', (event) => {
if ((event.ctrlKey || event.metaKey) && event.key === 'u') {
event.preventDefault();
}
});
// ==================== LAST UPDATED DATE ====================
document.addEventListener('DOMContentLoaded', () => {
const dateEl = document.getElementById('last-updated-date');
if (!dateEl) return;
const lastMod = new Date(document.lastModified);
dateEl.textContent = lastMod.toLocaleDateString('en-US', {
year: 'numeric',
month: 'long',
day: 'numeric'
});
});