-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
440 lines (367 loc) · 12.6 KB
/
Copy pathscript.js
File metadata and controls
440 lines (367 loc) · 12.6 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
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/* Gestion du thème */
const themeToggleBtn = document.getElementById('theme-toggle');
const htmlElement = document.documentElement;
if (localStorage.getItem('theme') === 'light') {
htmlElement.classList.remove('dark');
} else {
htmlElement.classList.add('dark');
}
themeToggleBtn.addEventListener('click', () => {
htmlElement.classList.toggle('dark');
if (htmlElement.classList.contains('dark')) {
localStorage.setItem('theme', 'dark');
} else {
localStorage.setItem('theme', 'light');
}
});
/* Typing text */
var typed = new Typed('#typing-text', {
strings: [
'Mathématicien.',
'Data Analyst.',
'Business Analyst.',
'Étudiant en 2ème année de BUT en Science des Données.'
],
typeSpeed: 50,
backSpeed: 30,
backDelay: 2000,
loop: true
});
/* Particules */
// 1. Configuration des particules
const particlesConfig = {
"particles": {
"number": {
"value": 70,
"density": {"enable": true, "value_area": 1200}
},
"color": {
"value":
"#3b82f6"
},
"shape": {"type": "circle"},
"opacity": {
"value": 0.5,
"random": false,
"anim": {
"enable": false,
"speed": 1,
"opacity_min": 0.1,
"sync": false
}
},
"size": {
"value": 5,
"random": true,
"anim": {
"enable": false,
"speed": 40,
"size_min": 0.1,
"sync": false
}
},
"line_linked": {
"enable": true,
"distance": 150,
"color": "#3b82f6",
"opacity": 0.3,
"width": 1
},
"move": {
"enable": true,
"speed": 4,
"direction": "none",
"random": false,
"straight": false,
"out_mode": "out",
"attract": {
"enable": false,
"rotateX": 600,
"rotateY": 1200
}
}
},
"interactivity": {
"detect_on": "canvas",
"events": {
"onhover": {"enable": true, "mode": "repulse"},
"onclick": {"enable": true, "mode": "push"},
"resize": true
},
"modes": {
"grab": {
"distance": 400,
"line_linked": {"opacity": 1}
},
"bubble": {
"distance": 400,
"size": 40,
"duration": 2,
"opacity": 8,
"speed": 3
},
"repulse": {"distance": 200},
"push": {"particles_nb": 4},
"remove": {"particles_nb": 2}
}
},
"retina_detect": true
}
// 2. Définir le seuil critique (en pixels)
const MAX_SCREEN_WIDTH = 3000;
// 3. Fonction pour gérer le lancement ou l'arrêt
function manageParticles() {
if (window.innerWidth <= MAX_SCREEN_WIDTH) {
// On vérifie si les particules ne sont pas déjà lancées pour éviter les doublons
if (!window.pJSDom || window.pJSDom.length === 0) {
particlesJS("particles-js", particlesConfig);
console.log("Particules activées (Largeur : " + window.innerWidth + "px)");
}
} else {
// On vérifie si les particules existent, et on les détruit proprement
if (window.pJSDom && window.pJSDom.length > 0) {
window.pJSDom[0].pJS.fn.vendors.destroypJS();
window.pJSDom = [];
console.log("Particules désactivées pour performance (Largeur : " + window.innerWidth + "px)");
}
}
}
// 4. Lancement initial
manageParticles();
// 5. Écouteur intelligent sur le redimensionnement
let resizeTimer;
window.addEventListener('resize', () => {
clearTimeout(resizeTimer);
resizeTimer = setTimeout(manageParticles, 50);
});
/* Scroll Nav */
const navbar = document.getElementById('navbar');
const sections = document.querySelectorAll("section");
const navLinks = document.querySelectorAll(".nav-link");
window.addEventListener('scroll', () => {
// A. Effet Verre
if (window.scrollY > 20) {
navbar.classList.add('scrolled');
} else {
navbar.classList.remove('scrolled');
}
// B. Soulignement automatique
let current = "";
sections.forEach((section) => {
const sectionTop = section.offsetTop;
if (scrollY >= (sectionTop - 200)) {
current = section.getAttribute("id");
}
});
navLinks.forEach((link) => {
link.classList.remove("active");
if (link.getAttribute("href").includes(current)) {
link.classList.add("active");
}
});
});
/* Bouton bot to top */
const scrollTopBtn = document.getElementById('scroll-top');
window.addEventListener('scroll', () => {
if (window.scrollY > 500) {
scrollTopBtn.classList.add('active');
} else {
scrollTopBtn.classList.remove('active');
}
});
/* Projets : Navigation */
const track = document.getElementById('track');
const nextBtn = document.getElementById('nextBtn');
const prevBtn = document.getElementById('prevBtn');
function getVisibleCards() {
return [...document.querySelectorAll('#track .project-card')].filter(card => {
const st = getComputedStyle(card);
return st.display !== 'none' && st.visibility !== 'hidden' && card.offsetParent !== null;
});
}
function getStep() {
if (!track) return 372;
return track.clientWidth; // page
}
function getMaxScroll() {
if (!track) return 0;
return Math.max(0, track.scrollWidth - track.clientWidth);
}
function getPositions() {
if (!track) return [0];
const cards = getVisibleCards();
if (cards.length === 0) return [0];
const step = Math.max(1, getStep());
const maxScroll = getMaxScroll();
const positions = [0];
let pos = step;
while (pos < maxScroll) {
positions.push(pos);
pos += step;
}
if (maxScroll > 0 && positions[positions.length - 1] !== maxScroll) {
positions.push(maxScroll);
}
return positions;
}
function setActiveDot(index) {
const dotsContainer = document.getElementById('projectDots');
if (!dotsContainer) return;
const dots = [...dotsContainer.querySelectorAll('.carousel-dot')];
dots.forEach(d => d.classList.remove('active'));
if (dots[index]) dots[index].classList.add('active');
}
function renderDots() {
if (!track) return;
const dotsContainer = document.getElementById('projectDots');
if (!dotsContainer) return;
const positions = getPositions();
// reset
dotsContainer.replaceChildren();
positions.forEach((left, idx) => {
const dot = document.createElement('button');
dot.className = 'carousel-dot';
dot.type = 'button';
dot.setAttribute('aria-label', `Aller à la page ${idx + 1}`);
dot.addEventListener('click', () => {
track.scrollTo({ left, behavior: 'smooth' });
});
dotsContainer.appendChild(dot);
});
setActiveDot(0);
}
function updateActiveDotFromScroll() {
if (!track) return;
const dotsContainer = document.getElementById('projectDots');
if (!dotsContainer) return;
const positions = getPositions();
if (positions.length === 0) return;
const step = Math.max(1, getStep());
const maxScroll = getMaxScroll();
let index = Math.floor((track.scrollLeft + step / 2) / step);
if (track.scrollLeft >= maxScroll - 1) {
index = positions.length - 1;
}
const clamped = Math.max(0, Math.min(index, positions.length - 1));
setActiveDot(clamped);
}
function scrollToNext() {
if (!track) return;
const step = Math.max(1, getStep());
const maxScroll = getMaxScroll();
const target = Math.min(track.scrollLeft + step, maxScroll);
track.scrollTo({ left: target, behavior: 'smooth' });
}
function scrollToPrev() {
if (!track) return;
const step = Math.max(1, getStep());
const target = Math.max(track.scrollLeft - step, 0);
track.scrollTo({ left: target, behavior: 'smooth' });
}
if (track && nextBtn && prevBtn) {
nextBtn.addEventListener('click', scrollToNext);
prevBtn.addEventListener('click', scrollToPrev);
track.addEventListener('scroll', () => {
updateActiveDotFromScroll();
}, { passive: true });
window.addEventListener('resize', () => {
renderDots();
updateActiveDotFromScroll();
});
renderDots();
updateActiveDotFromScroll();
}
/* Projets : Filtre*/
const filterBtns = document.querySelectorAll('.filter-btn');
const projectCards = document.querySelectorAll('.project-card');
const carouselTrack = document.getElementById('track');
if (filterBtns.length > 0) {
filterBtns.forEach(btn => {
btn.addEventListener('click', () => {
// 1. Gérer la classe 'active' sur les boutons
filterBtns.forEach(b => b.classList.remove('active'));
btn.classList.add('active');
// 2. Récupérer le filtre choisi
const filterValue = btn.getAttribute('data-filter');
// 3. Remettre le carrousel au début (scroll à gauche)
if(carouselTrack) {
carouselTrack.scrollTo({ left: 0, behavior: 'smooth' });
}
// 4. Afficher ou masquer les cartes
projectCards.forEach(card => {
const categories = card.getAttribute('data-category');
if (filterValue === 'all' || categories.includes(filterValue)) {
card.style.display = 'flex';
card.style.opacity = '0';
setTimeout(() => card.style.opacity = '1', 50);
} else {
card.style.display = 'none';
}
});
renderDots();
updateActiveDotFromScroll();
});
});
}
/* Frise : Experience*/
const timelineSteps = document.querySelectorAll('.timeline-step');
const expDetails = document.querySelectorAll('.exp-detail-card');
timelineSteps.forEach(step => {
step.addEventListener('click', () => {
// 1. Retirer la classe active de tous les points
timelineSteps.forEach(s => s.classList.remove('active'));
// 2. Ajouter la classe active au point cliqué
step.classList.add('active');
// 3. Masquer tous les détails
expDetails.forEach(detail => detail.classList.remove('active'));
// 4. Afficher le détail correspondant (via data-target)
const targetId = step.getAttribute('data-target');
const targetDetail = document.getElementById(targetId);
if (targetDetail) {
targetDetail.classList.add('active');
}
});
});
/* Compétences : Système d'onglets */
const skillTabs = document.querySelectorAll('.skill-tab');
const skillContents = document.querySelectorAll('.skills-content');
if (skillTabs.length > 0) {
skillTabs.forEach(tab => {
tab.addEventListener('click', () => {
// 1. Retirer la classe active de tous les onglets
skillTabs.forEach(t => t.classList.remove('active'));
// 2. Ajouter la classe active à l'onglet cliqué
tab.classList.add('active');
// 3. Masquer tous les contenus
skillContents.forEach(content => content.classList.remove('active'));
// 4. Afficher le contenu correspondant
const target = tab.getAttribute('data-tab');
const targetContent = document.getElementById(`tab-${target}`);
if (targetContent) {
targetContent.classList.add('active');
}
});
});
}
/* Compteur de vues */
const counterWrapper = document.querySelector('.view-counter-wrapper');
const counterElement = document.getElementById('view-counter');
if (counterWrapper && counterElement) {
fetch('https://api.counterapi.dev/v1/ibrahim-benkherfellah-portfolio/views/up')
.then(response => {
if (!response.ok) {
throw new Error('Erreur API');
}
return response.json();
})
.then(data => {
// SUCCÈS : on affiche le nombre
counterElement.innerText = data.count;
counterWrapper.style.opacity = '1';
})
.catch(error => {
// ÉCHEC (Bloqueur de pub ou hors ligne) : on cache
console.log('Compteur masqué (AdBlock ou Erreur):', error);
counterWrapper.style.display = 'none';
});
}