Refactor oktoberfest.js to enhance configuration handling for symbol counts and durations
This commit is contained in:
@@ -1,5 +1,8 @@
|
|||||||
const config = window.SeasonalsPluginConfig?.Oktoberfest || {};
|
const config = window.SeasonalsPluginConfig?.Oktoberfest || {};
|
||||||
const oktoberfest = config.EnableOktoberfest !== undefined ? config.EnableOktoberfest : true; // enable/disable oktoberfest
|
const oktoberfest = config.EnableOktoberfest !== undefined ? config.EnableOktoberfest : true; // enable/disable oktoberfest
|
||||||
|
const symbolCount = config.SymbolCount !== undefined ? config.SymbolCount : 25; // count of symbols
|
||||||
|
const symbolCountMobile = config.SymbolCountMobile !== undefined ? config.SymbolCountMobile : 10; // count of symbols on mobile
|
||||||
|
const enableDifferentDuration = config.EnableDifferentDuration !== undefined ? config.EnableDifferentDuration : true; // enable different durations
|
||||||
|
|
||||||
const oktoberfestSymbols = ['🥨', '🍺', '🍻', '🥨', '🥨'];
|
const oktoberfestSymbols = ['🥨', '🍺', '🍻', '🥨', '🥨'];
|
||||||
|
|
||||||
@@ -38,8 +41,8 @@ observer.observe(document.body, {
|
|||||||
attributes: true
|
attributes: true
|
||||||
});
|
});
|
||||||
|
|
||||||
function createOktoberfest(container) {
|
function createOktoberfest(container, count) {
|
||||||
for (let i = 0; i < 20; i++) {
|
for (let i = 0; i < count; i++) {
|
||||||
const symbol = document.createElement('div');
|
const symbol = document.createElement('div');
|
||||||
symbol.className = 'oktoberfest-symbol';
|
symbol.className = 'oktoberfest-symbol';
|
||||||
symbol.textContent = oktoberfestSymbols[Math.floor(Math.random() * oktoberfestSymbols.length)];
|
symbol.textContent = oktoberfestSymbols[Math.floor(Math.random() * oktoberfestSymbols.length)];
|
||||||
@@ -47,7 +50,9 @@ function createOktoberfest(container) {
|
|||||||
symbol.style.animationDelay = `${Math.random() * 10}s, ${Math.random() * 5}s`;
|
symbol.style.animationDelay = `${Math.random() * 10}s, ${Math.random() * 5}s`;
|
||||||
const duration1 = Math.random() * 5 + 8;
|
const duration1 = Math.random() * 5 + 8;
|
||||||
const duration2 = Math.random() * 3 + 3;
|
const duration2 = Math.random() * 3 + 3;
|
||||||
symbol.style.animationDuration = `${duration1}s, ${duration2}s`;
|
if (enableDifferentDuration) {
|
||||||
|
symbol.style.animationDuration = `${duration1}s, ${duration2}s`;
|
||||||
|
}
|
||||||
|
|
||||||
container.appendChild(symbol);
|
container.appendChild(symbol);
|
||||||
}
|
}
|
||||||
@@ -61,6 +66,10 @@ function initializeOktoberfest() {
|
|||||||
container.setAttribute("aria-hidden", "true");
|
container.setAttribute("aria-hidden", "true");
|
||||||
document.body.appendChild(container);
|
document.body.appendChild(container);
|
||||||
}
|
}
|
||||||
createOktoberfest(container);
|
|
||||||
|
const screenWidth = window.innerWidth;
|
||||||
|
const count = screenWidth > 768 ? symbolCount : symbolCountMobile;
|
||||||
|
|
||||||
|
createOktoberfest(container, count);
|
||||||
}
|
}
|
||||||
initializeOktoberfest();
|
initializeOktoberfest();
|
||||||
|
|||||||
Reference in New Issue
Block a user