@bebranded/bb-contents 1.0.45-beta → 1.0.47-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 +51 -9
- 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.47-beta
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -9,6 +9,11 @@
|
|
|
9
9
|
(function() {
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
|
+
// Créer l'objet temporaire pour la configuration si il n'existe pas
|
|
13
|
+
if (!window._bbContentsConfig) {
|
|
14
|
+
window._bbContentsConfig = {};
|
|
15
|
+
}
|
|
16
|
+
|
|
12
17
|
// Protection contre le double chargement
|
|
13
18
|
if (window.bbContents) {
|
|
14
19
|
console.warn('BeBranded Contents est déjà chargé');
|
|
@@ -17,7 +22,7 @@
|
|
|
17
22
|
|
|
18
23
|
// Configuration
|
|
19
24
|
const config = {
|
|
20
|
-
version: '1.0.
|
|
25
|
+
version: '1.0.47-beta',
|
|
21
26
|
debug: true, // Activé temporairement pour debug
|
|
22
27
|
prefix: 'bb-', // utilisé pour générer les sélecteurs (data-bb-*)
|
|
23
28
|
youtubeEndpoint: null, // URL du worker YouTube (à définir par l'utilisateur)
|
|
@@ -30,6 +35,11 @@
|
|
|
30
35
|
if (window.bbContents && window.bbContents.config && window.bbContents.config.youtubeEndpoint) {
|
|
31
36
|
config.youtubeEndpoint = window.bbContents.config.youtubeEndpoint;
|
|
32
37
|
}
|
|
38
|
+
|
|
39
|
+
// Détecter la configuration dans l'objet temporaire
|
|
40
|
+
if (window._bbContentsConfig && window._bbContentsConfig.youtubeEndpoint) {
|
|
41
|
+
config.youtubeEndpoint = window._bbContentsConfig.youtubeEndpoint;
|
|
42
|
+
}
|
|
33
43
|
|
|
34
44
|
// Objet principal
|
|
35
45
|
const bbContents = {
|
|
@@ -169,10 +179,10 @@
|
|
|
169
179
|
return true;
|
|
170
180
|
}
|
|
171
181
|
|
|
172
|
-
// Vérifier dans
|
|
173
|
-
if (window.
|
|
174
|
-
this.config.youtubeEndpoint = window.
|
|
175
|
-
console.log('[DEBUG] YouTube endpoint found in
|
|
182
|
+
// Vérifier dans l'objet temporaire
|
|
183
|
+
if (window._bbContentsConfig && window._bbContentsConfig.youtubeEndpoint) {
|
|
184
|
+
this.config.youtubeEndpoint = window._bbContentsConfig.youtubeEndpoint;
|
|
185
|
+
console.log('[DEBUG] YouTube endpoint found in temp config:', this.config.youtubeEndpoint);
|
|
176
186
|
return true;
|
|
177
187
|
}
|
|
178
188
|
|
|
@@ -713,12 +723,38 @@
|
|
|
713
723
|
const cacheKey = `youtube_${channelId}_${videoCount}_${allowShorts}_${language}`;
|
|
714
724
|
const cachedData = this.cache.get(cacheKey);
|
|
715
725
|
|
|
716
|
-
if (cachedData) {
|
|
726
|
+
if (cachedData && cachedData.value) {
|
|
717
727
|
// Données YouTube récupérées du cache (économie API)
|
|
728
|
+
console.log('[DEBUG] Using cached YouTube data for element');
|
|
718
729
|
this.generateYouTubeFeed(container, template, cachedData.value, allowShorts, language);
|
|
719
730
|
return;
|
|
720
731
|
}
|
|
721
732
|
|
|
733
|
+
// Vérifier si un appel API est déjà en cours pour cette clé
|
|
734
|
+
const loadingKey = `loading_${cacheKey}`;
|
|
735
|
+
if (window[loadingKey]) {
|
|
736
|
+
console.log('[DEBUG] API call already in progress, waiting...');
|
|
737
|
+
// Attendre que l'autre appel se termine
|
|
738
|
+
const checkLoading = () => {
|
|
739
|
+
if (!window[loadingKey]) {
|
|
740
|
+
// L'autre appel est terminé, vérifier le cache
|
|
741
|
+
const newCachedData = this.cache.get(cacheKey);
|
|
742
|
+
if (newCachedData && newCachedData.value) {
|
|
743
|
+
this.generateYouTubeFeed(container, template, newCachedData.value, allowShorts, language);
|
|
744
|
+
} else {
|
|
745
|
+
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Erreur de chargement</div>';
|
|
746
|
+
}
|
|
747
|
+
} else {
|
|
748
|
+
setTimeout(checkLoading, 100);
|
|
749
|
+
}
|
|
750
|
+
};
|
|
751
|
+
checkLoading();
|
|
752
|
+
return;
|
|
753
|
+
}
|
|
754
|
+
|
|
755
|
+
// Marquer qu'un appel API est en cours
|
|
756
|
+
window[loadingKey] = true;
|
|
757
|
+
|
|
722
758
|
// Afficher un loader
|
|
723
759
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Chargement des vidéos YouTube...</div>';
|
|
724
760
|
|
|
@@ -743,11 +779,17 @@
|
|
|
743
779
|
// Données YouTube mises en cache pour 24h (économie API)
|
|
744
780
|
|
|
745
781
|
this.generateYouTubeFeed(container, template, data, allowShorts, language);
|
|
782
|
+
|
|
783
|
+
// Libérer le verrou
|
|
784
|
+
window[loadingKey] = false;
|
|
746
785
|
})
|
|
747
786
|
.catch(error => {
|
|
748
787
|
console.error('[DEBUG] YouTube API error:', error);
|
|
749
788
|
// Erreur dans le module youtube
|
|
750
789
|
|
|
790
|
+
// Libérer le verrou en cas d'erreur
|
|
791
|
+
window[loadingKey] = false;
|
|
792
|
+
|
|
751
793
|
// En cas d'erreur, essayer de récupérer du cache même expiré
|
|
752
794
|
const expiredCache = localStorage.getItem(cacheKey);
|
|
753
795
|
if (expiredCache) {
|
|
@@ -769,8 +811,8 @@
|
|
|
769
811
|
|
|
770
812
|
generateYouTubeFeed: function(container, template, data, allowShorts, language = 'fr') {
|
|
771
813
|
console.log('[DEBUG] generateYouTubeFeed called with data:', data);
|
|
772
|
-
if (!data.items || data.items.length === 0) {
|
|
773
|
-
console.log('[DEBUG] No videos found in data');
|
|
814
|
+
if (!data || !data.items || data.items.length === 0) {
|
|
815
|
+
console.log('[DEBUG] No videos found in data or data is undefined');
|
|
774
816
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Aucune vidéo trouvée</div>';
|
|
775
817
|
return;
|
|
776
818
|
}
|