@bebranded/bb-contents 1.0.32-beta → 1.0.34-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 +107 -19
- 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.34-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,9 @@
|
|
|
31
31
|
modules: {},
|
|
32
32
|
_observer: null,
|
|
33
33
|
_reinitScheduled: false,
|
|
34
|
+
_initRetryCount: 0,
|
|
35
|
+
_maxInitRetries: 3,
|
|
36
|
+
_performanceBoostDetected: false,
|
|
34
37
|
|
|
35
38
|
// Utilitaires
|
|
36
39
|
utils: {
|
|
@@ -81,6 +84,12 @@
|
|
|
81
84
|
|
|
82
85
|
this.utils.log('Initialisation v' + this.config.version);
|
|
83
86
|
|
|
87
|
+
// Détection du bb-performance-boost
|
|
88
|
+
this._performanceBoostDetected = document.body.hasAttribute('bb-performance-boost');
|
|
89
|
+
if (this._performanceBoostDetected) {
|
|
90
|
+
this.utils.log('bb-performance-boost détecté - mode de compatibilité activé');
|
|
91
|
+
}
|
|
92
|
+
|
|
84
93
|
// Déterminer la portée
|
|
85
94
|
const scope = document.querySelector('[data-bb-scope]') || document;
|
|
86
95
|
|
|
@@ -100,6 +109,48 @@
|
|
|
100
109
|
|
|
101
110
|
// Activer l'observer DOM pour contenu dynamique
|
|
102
111
|
this.setupObserver();
|
|
112
|
+
|
|
113
|
+
// Vérifier et réinitialiser les éléments non initialisés
|
|
114
|
+
this.checkAndReinitFailedElements();
|
|
115
|
+
},
|
|
116
|
+
|
|
117
|
+
// Nouvelle méthode pour vérifier et réinitialiser les éléments échoués
|
|
118
|
+
checkAndReinitFailedElements: function() {
|
|
119
|
+
const scope = document.querySelector('[data-bb-scope]') || document;
|
|
120
|
+
let needsReinit = false;
|
|
121
|
+
|
|
122
|
+
// Vérifier les marquees non initialisés
|
|
123
|
+
const marqueeElements = scope.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
|
|
124
|
+
if (marqueeElements.length > 0) {
|
|
125
|
+
bbContents.utils.log('Marquees non initialisés détectés:', marqueeElements.length);
|
|
126
|
+
needsReinit = true;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
// Vérifier les autres modules si nécessaire
|
|
130
|
+
Object.keys(this.modules).forEach(function(moduleName) {
|
|
131
|
+
const module = bbContents.modules[moduleName];
|
|
132
|
+
if (module.checkFailed && module.checkFailed(scope)) {
|
|
133
|
+
bbContents.utils.log('Module', moduleName, 'a des éléments échoués');
|
|
134
|
+
needsReinit = true;
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
// Réinitialiser si nécessaire et si on n'a pas dépassé le nombre max de tentatives
|
|
139
|
+
if (needsReinit && this._initRetryCount < this._maxInitRetries) {
|
|
140
|
+
this._initRetryCount++;
|
|
141
|
+
bbContents.utils.log('Tentative de réinitialisation', this._initRetryCount, '/', this._maxInitRetries);
|
|
142
|
+
|
|
143
|
+
const delay = this._performanceBoostDetected ? 1000 * this._initRetryCount : 500 * this._initRetryCount;
|
|
144
|
+
setTimeout(() => {
|
|
145
|
+
this.init();
|
|
146
|
+
}, delay); // Délai progressif adaptatif
|
|
147
|
+
}
|
|
148
|
+
},
|
|
149
|
+
|
|
150
|
+
// Méthode publique pour forcer la réinitialisation
|
|
151
|
+
reinit: function() {
|
|
152
|
+
this._initRetryCount = 0;
|
|
153
|
+
this.init();
|
|
103
154
|
},
|
|
104
155
|
|
|
105
156
|
// Observer DOM pour contenu dynamique
|
|
@@ -130,10 +181,11 @@
|
|
|
130
181
|
|
|
131
182
|
if (shouldReinit && !this._reinitScheduled) {
|
|
132
183
|
this._reinitScheduled = true;
|
|
184
|
+
const delay = this._performanceBoostDetected ? 200 : 100;
|
|
133
185
|
setTimeout(() => {
|
|
134
186
|
this.init();
|
|
135
187
|
this._reinitScheduled = false;
|
|
136
|
-
},
|
|
188
|
+
}, delay);
|
|
137
189
|
}
|
|
138
190
|
});
|
|
139
191
|
|
|
@@ -307,13 +359,20 @@
|
|
|
307
359
|
}
|
|
308
360
|
},
|
|
309
361
|
|
|
310
|
-
// Module Marquee - Version live 1.0.
|
|
362
|
+
// Module Marquee - Version live 1.0.33-beta avec améliorations d'initialisation
|
|
311
363
|
marquee: {
|
|
312
364
|
detect: function(scope) {
|
|
313
365
|
const s = scope || document;
|
|
314
366
|
return s.querySelector(bbContents._attrSelector('marquee')) !== null;
|
|
315
367
|
},
|
|
316
368
|
|
|
369
|
+
// Nouvelle méthode pour vérifier les éléments échoués
|
|
370
|
+
checkFailed: function(scope) {
|
|
371
|
+
const s = scope || document;
|
|
372
|
+
const failedElements = s.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
|
|
373
|
+
return failedElements.length > 0;
|
|
374
|
+
},
|
|
375
|
+
|
|
317
376
|
init: function(root) {
|
|
318
377
|
const scope = root || document;
|
|
319
378
|
if (scope.closest && scope.closest('[data-bb-disable]')) return;
|
|
@@ -399,28 +458,38 @@
|
|
|
399
458
|
// Marquer l'élément comme traité par le module marquee
|
|
400
459
|
element.setAttribute('data-bb-marquee-processed', 'true');
|
|
401
460
|
|
|
402
|
-
// Fonction pour initialiser l'animation
|
|
403
|
-
const initAnimation = () => {
|
|
461
|
+
// Fonction pour initialiser l'animation avec retry amélioré
|
|
462
|
+
const initAnimation = (retryCount = 0) => {
|
|
404
463
|
// Attendre que le contenu soit dans le DOM
|
|
405
464
|
requestAnimationFrame(() => {
|
|
406
465
|
const contentWidth = mainBlock.offsetWidth;
|
|
407
466
|
const contentHeight = mainBlock.offsetHeight;
|
|
408
467
|
|
|
409
|
-
// Debug
|
|
410
|
-
bbContents.utils.log('Debug - Largeur du contenu:', contentWidth, 'px', 'Hauteur:', contentHeight, 'px', 'Enfants:', mainBlock.children.length, 'Vertical:', isVertical, 'Direction:', direction);
|
|
468
|
+
// Debug amélioré
|
|
469
|
+
bbContents.utils.log('Debug - Largeur du contenu:', contentWidth, 'px', 'Hauteur:', contentHeight, 'px', 'Enfants:', mainBlock.children.length, 'Vertical:', isVertical, 'Direction:', direction, 'Tentative:', retryCount + 1);
|
|
411
470
|
|
|
412
|
-
// Si pas de contenu, réessayer
|
|
471
|
+
// Si pas de contenu, réessayer avec délai progressif
|
|
413
472
|
if ((isVertical && contentHeight === 0) || (!isVertical && contentWidth === 0)) {
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
473
|
+
if (retryCount < 5) {
|
|
474
|
+
bbContents.utils.log('Contenu non prêt, nouvelle tentative dans', (200 + retryCount * 100), 'ms');
|
|
475
|
+
setTimeout(() => initAnimation(retryCount + 1), 200 + retryCount * 100);
|
|
476
|
+
return;
|
|
477
|
+
} else {
|
|
478
|
+
bbContents.utils.log('Échec d\'initialisation après 5 tentatives');
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
417
481
|
}
|
|
418
482
|
|
|
419
483
|
// Pour le vertical, s'assurer qu'on a une hauteur minimale
|
|
420
484
|
if (isVertical && contentHeight < 50) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
485
|
+
if (retryCount < 5) {
|
|
486
|
+
bbContents.utils.log('Hauteur insuffisante pour le marquee vertical (' + contentHeight + 'px), nouvelle tentative dans', (200 + retryCount * 100), 'ms');
|
|
487
|
+
setTimeout(() => initAnimation(retryCount + 1), 200 + retryCount * 100);
|
|
488
|
+
return;
|
|
489
|
+
} else {
|
|
490
|
+
bbContents.utils.log('Échec d\'initialisation - hauteur insuffisante après 5 tentatives');
|
|
491
|
+
return;
|
|
492
|
+
}
|
|
424
493
|
}
|
|
425
494
|
|
|
426
495
|
if (isVertical) {
|
|
@@ -519,8 +588,12 @@
|
|
|
519
588
|
});
|
|
520
589
|
};
|
|
521
590
|
|
|
522
|
-
// Démarrer l'initialisation
|
|
523
|
-
|
|
591
|
+
// Démarrer l'initialisation avec délai adaptatif
|
|
592
|
+
let initDelay = isVertical ? 300 : 100;
|
|
593
|
+
if (bbContents._performanceBoostDetected) {
|
|
594
|
+
initDelay = isVertical ? 600 : 300; // Délais plus longs avec bb-performance-boost
|
|
595
|
+
}
|
|
596
|
+
setTimeout(() => initAnimation(0), initDelay);
|
|
524
597
|
});
|
|
525
598
|
|
|
526
599
|
bbContents.utils.log('Module Marquee initialisé:', elements.length, 'éléments');
|
|
@@ -913,16 +986,31 @@
|
|
|
913
986
|
if (document.readyState === 'loading') {
|
|
914
987
|
document.addEventListener('DOMContentLoaded', function() {
|
|
915
988
|
// Délai pour éviter le blocage du rendu
|
|
989
|
+
const delay = document.body.hasAttribute('bb-performance-boost') ? 300 : 100;
|
|
916
990
|
setTimeout(function() {
|
|
917
991
|
bbContents.init();
|
|
918
|
-
},
|
|
992
|
+
}, delay);
|
|
919
993
|
});
|
|
920
994
|
} else {
|
|
921
995
|
// Délai pour éviter le blocage du rendu
|
|
996
|
+
const delay = document.body.hasAttribute('bb-performance-boost') ? 300 : 100;
|
|
922
997
|
setTimeout(function() {
|
|
923
998
|
bbContents.init();
|
|
924
|
-
},
|
|
999
|
+
}, delay);
|
|
925
1000
|
}
|
|
1001
|
+
|
|
1002
|
+
// Initialisation différée supplémentaire pour les cas difficiles
|
|
1003
|
+
window.addEventListener('load', function() {
|
|
1004
|
+
const loadDelay = document.body.hasAttribute('bb-performance-boost') ? 2000 : 1000;
|
|
1005
|
+
setTimeout(function() {
|
|
1006
|
+
// Vérifier s'il y a des éléments non initialisés
|
|
1007
|
+
const unprocessedMarquees = document.querySelectorAll('[bb-marquee]:not([data-bb-marquee-processed])');
|
|
1008
|
+
if (unprocessedMarquees.length > 0) {
|
|
1009
|
+
bbContents.utils.log('Éléments marquee non initialisés détectés après load, réinitialisation...');
|
|
1010
|
+
bbContents.reinit();
|
|
1011
|
+
}
|
|
1012
|
+
}, loadDelay);
|
|
1013
|
+
});
|
|
926
1014
|
}
|
|
927
1015
|
|
|
928
1016
|
// Initialisation
|