MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary Tag: Manual revert |
No edit summary |
||
| Line 3: | Line 3: | ||
const chars = el.textContent.split(''); | const chars = el.textContent.split(''); | ||
const total = chars.length; | const total = chars.length; | ||
const isRainbow = el.classList.contains('rainbow'); | |||
const isWavy = el.classList.contains('wavy'); | |||
el.innerHTML = chars.map((c, i) => { | el.innerHTML = chars.map((c, i) => { | ||
const hue = Math.round((i / total) * 360); | let styles = []; | ||
const waveDelay | if (isRainbow) { | ||
const hue = Math.round((i / total) * 360); | |||
const rainbowDelay = -((i / total) * 3).toFixed(2); | |||
styles.push(`color: hsl(${hue}, 100%, 60%)`, `animation-delay: ${rainbowDelay}s`); | |||
} | |||
if (isWavy) { | |||
const waveDelay = ((i / total) * 1).toFixed(2); | |||
// If rainbow is also present, we append the wave delay to the animation-delay list | |||
if (isRainbow) { | |||
styles[1] += `, ${waveDelay}s`; | |||
} else { | |||
styles.push(`animation-delay: ${waveDelay}s`); | |||
} | |||
} | |||
return `<span style="${styles.join('; ')}">${c === ' ' ? ' ' : c}</span>`; | |||
}).join(''); | }).join(''); | ||
} | } | ||
$(document).ready(function() { | $(document).ready(function() { | ||
$('.rainbow, .wavy').each(function() { applyEffects(this); }); | |||
}); | }); | ||
Revision as of 07:02, 14 March 2026
/* Any JavaScript here will be loaded for all users on every page load. */
function applyEffects(el) {
const chars = el.textContent.split('');
const total = chars.length;
const isRainbow = el.classList.contains('rainbow');
const isWavy = el.classList.contains('wavy');
el.innerHTML = chars.map((c, i) => {
let styles = [];
if (isRainbow) {
const hue = Math.round((i / total) * 360);
const rainbowDelay = -((i / total) * 3).toFixed(2);
styles.push(`color: hsl(${hue}, 100%, 60%)`, `animation-delay: ${rainbowDelay}s`);
}
if (isWavy) {
const waveDelay = ((i / total) * 1).toFixed(2);
// If rainbow is also present, we append the wave delay to the animation-delay list
if (isRainbow) {
styles[1] += `, ${waveDelay}s`;
} else {
styles.push(`animation-delay: ${waveDelay}s`);
}
}
return `<span style="${styles.join('; ')}">${c === ' ' ? ' ' : c}</span>`;
}).join('');
}
$(document).ready(function() {
$('.rainbow, .wavy').each(function() { applyEffects(this); });
});