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 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 = ['🥨', '🍺', '🍻', '🥨', '🥨'];
|
||||
|
||||
@@ -38,8 +41,8 @@ observer.observe(document.body, {
|
||||
attributes: true
|
||||
});
|
||||
|
||||
function createOktoberfest(container) {
|
||||
for (let i = 0; i < 20; i++) {
|
||||
function createOktoberfest(container, count) {
|
||||
for (let i = 0; i < count; i++) {
|
||||
const symbol = document.createElement('div');
|
||||
symbol.className = 'oktoberfest-symbol';
|
||||
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`;
|
||||
const duration1 = Math.random() * 5 + 8;
|
||||
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);
|
||||
}
|
||||
@@ -61,6 +66,10 @@ function initializeOktoberfest() {
|
||||
container.setAttribute("aria-hidden", "true");
|
||||
document.body.appendChild(container);
|
||||
}
|
||||
createOktoberfest(container);
|
||||
|
||||
const screenWidth = window.innerWidth;
|
||||
const count = screenWidth > 768 ? symbolCount : symbolCountMobile;
|
||||
|
||||
createOktoberfest(container, count);
|
||||
}
|
||||
initializeOktoberfest();
|
||||
|
||||
Reference in New Issue
Block a user