@bebranded/bb-contents 1.0.32-beta → 1.0.33-beta
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bb-contents.js +89 -16
- package/package.json +1 -1
package/bb-contents.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* BeBranded Contents
|
|
3
3
|
* Contenus additionnels français pour Webflow
|
|
4
|
-
* @version 1.0.
|
|
4
|
+
* @version 1.0.33-beta
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
|
|
18
18
|
// Configuration
|
|
19
19
|
const config = {
|
|
20
|
-
version: '1.0.
|
|
20
|
+
version: '1.0.33-beta',
|
|
21
21
|
debug: false, // Désactivé par défaut pour une console propre
|
|
22
22
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
23
23
|
i18n: {
|
|
@@ -31,6 +31,8 @@
|
|
|
31
31
|
modules: {},
|
|
32
32
|
_observer: null,
|
|
33
33
|
_reinitScheduled: false,
|
|
34
|
+
_initRetryCount: 0,
|
|
35
|
+
_maxInitRetries: 3,
|
|
34
36
|
|
|
35
37
|
// Utilitaires
|
|
36
38
|
utils: {
|
|
@@ -100,6 +102,47 @@
|
|
|
100
102
|
|
|
101
103
|
// Activer l'observer DOM pour contenu dynamique
|
|
102
104
|
this.setupObserver();
|
|
105
|
+
|
|
106
|
+
// Vérifier et réinitialiser les éléments non initialisés
|
|
107
|
+
this.checkAndReinitFailedElements();
|
|
108
|
+
},
|
|
109
|
+
|
|
110
|
+
// Nouvelle méthode pour vérifier et réinitialiser les éléments échoués
|
|
111
|
+
checkAndReinitFailedElements: function() {
|
|
112
|
+
const scope = document.querySelector('[data-bb-scope]') || document;
|
|
113
|
+
let needsReinit = false;
|
|
114
|
+
|
|
115
|
+
// Vérifier les marquees non initialisés
|
|
116
|
+
const marqueeElements = scope.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
|
|
117
|
+
if (marqueeElements.length > 0) {
|
|
118
|
+
bbContents.utils.log('Marquees non initialisés détectés:', marqueeElements.length);
|
|
119
|
+
needsReinit = true;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// Vérifier les autres modules si nécessaire
|
|
123
|
+
Object.keys(this.modules).forEach(function(moduleName) {
|
|
124
|
+
const module = bbContents.modules[moduleName];
|
|
125
|
+
if (module.checkFailed && module.checkFailed(scope)) {
|
|
126
|
+
bbContents.utils.log('Module', moduleName, 'a des éléments échoués');
|
|
127
|
+
needsReinit = true;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
// Réinitialiser si nécessaire et si on n'a pas dépassé le nombre max de tentatives
|
|
132
|
+
if (needsReinit && this._initRetryCount < this._maxInitRetries) {
|
|
133
|
+
this._initRetryCount++;
|
|
134
|
+
bbContents.utils.log('Tentative de réinitialisation', this._initRetryCount, '/', this._maxInitRetries);
|
|
135
|
+
|
|
136
|
+
setTimeout(() => {
|
|
137
|
+
this.init();
|
|
138
|
+
}, 500 * this._initRetryCount); // Délai progressif
|
|
139
|
+
}
|
|
140
|
+
},
|
|
141
|
+
|
|
142
|
+
// Méthode publique pour forcer la réinitialisation
|
|
143
|
+
reinit: function() {
|
|
144
|
+
this._initRetryCount = 0;
|
|
145
|
+
this.init();
|
|
103
146
|
},
|
|
104
147
|
|
|
105
148
|
// Observer DOM pour contenu dynamique
|
|
@@ -307,13 +350,20 @@
|
|
|
307
350
|
}
|
|
308
351
|
},
|
|
309
352
|
|
|
310
|
-
// Module Marquee - Version live 1.0.
|
|
353
|
+
// Module Marquee - Version live 1.0.33-beta avec améliorations d'initialisation
|
|
311
354
|
marquee: {
|
|
312
355
|
detect: function(scope) {
|
|
313
356
|
const s = scope || document;
|
|
314
357
|
return s.querySelector(bbContents._attrSelector('marquee')) !== null;
|
|
315
358
|
},
|
|
316
359
|
|
|
360
|
+
// Nouvelle méthode pour vérifier les éléments échoués
|
|
361
|
+
checkFailed: function(scope) {
|
|
362
|
+
const s = scope || document;
|
|
363
|
+
const failedElements = s.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
|
|
364
|
+
return failedElements.length > 0;
|
|
365
|
+
},
|
|
366
|
+
|
|
317
367
|
init: function(root) {
|
|
318
368
|
const scope = root || document;
|
|
319
369
|
if (scope.closest && scope.closest('[data-bb-disable]')) return;
|
|
@@ -399,28 +449,38 @@
|
|
|
399
449
|
// Marquer l'élément comme traité par le module marquee
|
|
400
450
|
element.setAttribute('data-bb-marquee-processed', 'true');
|
|
401
451
|
|
|
402
|
-
// Fonction pour initialiser l'animation
|
|
403
|
-
const initAnimation = () => {
|
|
452
|
+
// Fonction pour initialiser l'animation avec retry amélioré
|
|
453
|
+
const initAnimation = (retryCount = 0) => {
|
|
404
454
|
// Attendre que le contenu soit dans le DOM
|
|
405
455
|
requestAnimationFrame(() => {
|
|
406
456
|
const contentWidth = mainBlock.offsetWidth;
|
|
407
457
|
const contentHeight = mainBlock.offsetHeight;
|
|
408
458
|
|
|
409
|
-
// Debug
|
|
410
|
-
bbContents.utils.log('Debug - Largeur du contenu:', contentWidth, 'px', 'Hauteur:', contentHeight, 'px', 'Enfants:', mainBlock.children.length, 'Vertical:', isVertical, 'Direction:', direction);
|
|
459
|
+
// Debug amélioré
|
|
460
|
+
bbContents.utils.log('Debug - Largeur du contenu:', contentWidth, 'px', 'Hauteur:', contentHeight, 'px', 'Enfants:', mainBlock.children.length, 'Vertical:', isVertical, 'Direction:', direction, 'Tentative:', retryCount + 1);
|
|
411
461
|
|
|
412
|
-
// Si pas de contenu, réessayer
|
|
462
|
+
// Si pas de contenu, réessayer avec délai progressif
|
|
413
463
|
if ((isVertical && contentHeight === 0) || (!isVertical && contentWidth === 0)) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
464
|
+
if (retryCount < 5) {
|
|
465
|
+
bbContents.utils.log('Contenu non prêt, nouvelle tentative dans', (200 + retryCount * 100), 'ms');
|
|
466
|
+
setTimeout(() => initAnimation(retryCount + 1), 200 + retryCount * 100);
|
|
467
|
+
return;
|
|
468
|
+
} else {
|
|
469
|
+
bbContents.utils.log('Échec d\'initialisation après 5 tentatives');
|
|
470
|
+
return;
|
|
471
|
+
}
|
|
417
472
|
}
|
|
418
473
|
|
|
419
474
|
// Pour le vertical, s'assurer qu'on a une hauteur minimale
|
|
420
475
|
if (isVertical && contentHeight < 50) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
476
|
+
if (retryCount < 5) {
|
|
477
|
+
bbContents.utils.log('Hauteur insuffisante pour le marquee vertical (' + contentHeight + 'px), nouvelle tentative dans', (200 + retryCount * 100), 'ms');
|
|
478
|
+
setTimeout(() => initAnimation(retryCount + 1), 200 + retryCount * 100);
|
|
479
|
+
return;
|
|
480
|
+
} else {
|
|
481
|
+
bbContents.utils.log('Échec d\'initialisation - hauteur insuffisante après 5 tentatives');
|
|
482
|
+
return;
|
|
483
|
+
}
|
|
424
484
|
}
|
|
425
485
|
|
|
426
486
|
if (isVertical) {
|
|
@@ -519,8 +579,9 @@
|
|
|
519
579
|
});
|
|
520
580
|
};
|
|
521
581
|
|
|
522
|
-
// Démarrer l'initialisation
|
|
523
|
-
|
|
582
|
+
// Démarrer l'initialisation avec délai adaptatif
|
|
583
|
+
const initDelay = isVertical ? 300 : 100;
|
|
584
|
+
setTimeout(() => initAnimation(0), initDelay);
|
|
524
585
|
});
|
|
525
586
|
|
|
526
587
|
bbContents.utils.log('Module Marquee initialisé:', elements.length, 'éléments');
|
|
@@ -923,6 +984,18 @@
|
|
|
923
984
|
bbContents.init();
|
|
924
985
|
}, 100);
|
|
925
986
|
}
|
|
987
|
+
|
|
988
|
+
// Initialisation différée supplémentaire pour les cas difficiles
|
|
989
|
+
window.addEventListener('load', function() {
|
|
990
|
+
setTimeout(function() {
|
|
991
|
+
// Vérifier s'il y a des éléments non initialisés
|
|
992
|
+
const unprocessedMarquees = document.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
|
|
993
|
+
if (unprocessedMarquees.length > 0) {
|
|
994
|
+
bbContents.utils.log('Éléments marquee non initialisés détectés après load, réinitialisation...');
|
|
995
|
+
bbContents.reinit();
|
|
996
|
+
}
|
|
997
|
+
}, 1000);
|
|
998
|
+
});
|
|
926
999
|
}
|
|
927
1000
|
|
|
928
1001
|
// Initialisation
|