@bebranded/bb-contents 1.1.10 → 1.1.12
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 +26 -28
- 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.1.
|
|
4
|
+
* @version 1.1.12
|
|
5
5
|
* @author BeBranded
|
|
6
6
|
* @license MIT
|
|
7
7
|
* @website https://www.bebranded.xyz
|
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
'use strict';
|
|
11
11
|
|
|
12
12
|
// Version du script
|
|
13
|
-
const BB_CONTENTS_VERSION = '1.1.
|
|
13
|
+
const BB_CONTENTS_VERSION = '1.1.12';
|
|
14
14
|
|
|
15
15
|
// Créer l'objet temporaire pour la configuration si il n'existe pas
|
|
16
16
|
if (!window._bbContentsConfig) {
|
|
@@ -2281,38 +2281,27 @@
|
|
|
2281
2281
|
// Nettoyer le cache expiré au démarrage
|
|
2282
2282
|
this.cleanCache();
|
|
2283
2283
|
|
|
2284
|
-
|
|
2285
|
-
|
|
2284
|
+
// OPTIMISATION: Calculer maxVideoCount/maxSkip sur tout le document pour que le cache
|
|
2285
|
+
// contienne assez de vidéos même quand les grids sont dans des scopes différents
|
|
2286
|
+
const allElements = document.querySelectorAll('[bb-youtube-channel]');
|
|
2287
|
+
if (allElements.length === 0) return;
|
|
2286
2288
|
|
|
2287
|
-
// Module détecté: youtube
|
|
2288
|
-
|
|
2289
|
-
// OPTIMISATION: Grouper les éléments par configuration unique pour partager les requêtes API
|
|
2290
2289
|
const elementsByConfig = {};
|
|
2291
2290
|
|
|
2292
|
-
|
|
2293
|
-
|
|
2294
|
-
if (element.bbProcessed || element.hasAttribute('data-bb-marquee-processed')) {
|
|
2295
|
-
// Élément youtube déjà traité par un autre module, ignoré
|
|
2296
|
-
return;
|
|
2297
|
-
}
|
|
2298
|
-
element.bbProcessed = true;
|
|
2291
|
+
allElements.forEach(element => {
|
|
2292
|
+
if (element.bbProcessed || element.hasAttribute('data-bb-marquee-processed')) return;
|
|
2299
2293
|
|
|
2300
2294
|
const channelIdsRaw = bbContents._getAttr(element, 'bb-youtube-channel');
|
|
2301
2295
|
if (!channelIdsRaw) return;
|
|
2302
2296
|
|
|
2303
|
-
// Parser les channelIds (peuvent être séparés par virgules)
|
|
2304
2297
|
const channelIds = channelIdsRaw.split(',').map(id => id.trim()).filter(id => id);
|
|
2305
2298
|
if (channelIds.length === 0) return;
|
|
2306
2299
|
|
|
2307
|
-
// Normaliser et trier les channelIds pour créer une clé unique
|
|
2308
2300
|
const normalizedChannelIds = channelIds.sort().join(',');
|
|
2309
|
-
|
|
2310
2301
|
const allowShorts = bbContents._getAttr(element, 'bb-youtube-allow-shorts') === 'true';
|
|
2311
2302
|
const language = bbContents._getAttr(element, 'bb-youtube-language') || 'fr';
|
|
2312
2303
|
const videoCount = parseInt(bbContents._getAttr(element, 'bb-youtube-video-count') || '10', 10);
|
|
2313
2304
|
const skip = parseInt(bbContents._getAttr(element, 'bb-youtube-skip') || '0', 10);
|
|
2314
|
-
|
|
2315
|
-
// Créer une clé unique par configuration (channelIds + allowShorts + language)
|
|
2316
2305
|
const configKey = `${normalizedChannelIds}_${allowShorts}_${language}`;
|
|
2317
2306
|
|
|
2318
2307
|
if (!elementsByConfig[configKey]) {
|
|
@@ -2326,8 +2315,7 @@
|
|
|
2326
2315
|
};
|
|
2327
2316
|
}
|
|
2328
2317
|
|
|
2329
|
-
|
|
2330
|
-
// Garder le max videoCount et maxSkip pour ce groupe
|
|
2318
|
+
// maxVideoCount/maxSkip calculés sur toute la page (document)
|
|
2331
2319
|
elementsByConfig[configKey].maxVideoCount = Math.max(
|
|
2332
2320
|
elementsByConfig[configKey].maxVideoCount,
|
|
2333
2321
|
videoCount
|
|
@@ -2336,13 +2324,16 @@
|
|
|
2336
2324
|
elementsByConfig[configKey].maxSkip,
|
|
2337
2325
|
skip
|
|
2338
2326
|
);
|
|
2327
|
+
|
|
2328
|
+
// N'ajouter et n'initialiser que les éléments du scope courant
|
|
2329
|
+
if (scope.contains(element)) {
|
|
2330
|
+
element.bbProcessed = true;
|
|
2331
|
+
elementsByConfig[configKey].elements.push(element);
|
|
2332
|
+
}
|
|
2339
2333
|
});
|
|
2340
2334
|
|
|
2341
|
-
// Initialiser chaque groupe d'éléments
|
|
2342
2335
|
Object.keys(elementsByConfig).forEach(configKey => {
|
|
2343
2336
|
const group = elementsByConfig[configKey];
|
|
2344
|
-
|
|
2345
|
-
// Initialiser tous les éléments de ce groupe
|
|
2346
2337
|
group.elements.forEach(element => {
|
|
2347
2338
|
const videoCount = parseInt(bbContents._getAttr(element, 'bb-youtube-video-count') || '10', 10);
|
|
2348
2339
|
const skip = parseInt(bbContents._getAttr(element, 'bb-youtube-skip') || '0', 10);
|
|
@@ -2436,22 +2427,29 @@
|
|
|
2436
2427
|
// OPTIMISATION: Cache partagé par configuration (sans videoCount ni skip)
|
|
2437
2428
|
const baseCacheKey = `youtube_${groupConfig.channelIds}_${groupConfig.allowShorts}_${groupConfig.language}`;
|
|
2438
2429
|
const cachedData = this.cache.get(baseCacheKey);
|
|
2430
|
+
const minItemsNeeded = skip + videoCount;
|
|
2439
2431
|
|
|
2440
|
-
if (cachedData && cachedData.items) {
|
|
2441
|
-
//
|
|
2432
|
+
if (cachedData && cachedData.items && cachedData.items.length >= minItemsNeeded) {
|
|
2433
|
+
// Cache suffisant pour cette grid
|
|
2442
2434
|
const limitedData = this.applySkipAndLimit(cachedData, skip, videoCount);
|
|
2443
2435
|
this.generateYouTubeFeed(container, template, limitedData, groupConfig.allowShorts, groupConfig.language);
|
|
2444
2436
|
return;
|
|
2445
2437
|
}
|
|
2438
|
+
if (cachedData && cachedData.items && cachedData.items.length < minItemsNeeded) {
|
|
2439
|
+
// Cache insuffisant (ex. première grid seule en DOM a rempli le cache) → invalider pour refetch
|
|
2440
|
+
try { localStorage.removeItem(baseCacheKey); } catch (e) {}
|
|
2441
|
+
}
|
|
2446
2442
|
|
|
2447
2443
|
if (this.isRequestActive(baseCacheKey)) {
|
|
2448
2444
|
const checkActive = () => {
|
|
2449
2445
|
if (!this.isRequestActive(baseCacheKey)) {
|
|
2450
|
-
// L'autre appel est terminé, vérifier le cache
|
|
2451
2446
|
const newCachedData = this.cache.get(baseCacheKey);
|
|
2452
|
-
if (newCachedData && newCachedData.items) {
|
|
2447
|
+
if (newCachedData && newCachedData.items && newCachedData.items.length >= minItemsNeeded) {
|
|
2453
2448
|
const limitedData = this.applySkipAndLimit(newCachedData, skip, videoCount);
|
|
2454
2449
|
this.generateYouTubeFeed(container, template, limitedData, groupConfig.allowShorts, groupConfig.language);
|
|
2450
|
+
} else if (newCachedData && newCachedData.items && newCachedData.items.length < minItemsNeeded) {
|
|
2451
|
+
try { localStorage.removeItem(baseCacheKey); } catch (e) {}
|
|
2452
|
+
this.initElement(element, groupConfig, videoCount, skip);
|
|
2455
2453
|
} else {
|
|
2456
2454
|
container.innerHTML = '<div style="padding: 20px; text-align: center; color: #6b7280;">Erreur de chargement</div>';
|
|
2457
2455
|
}
|