MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
(function () { | |||
function applyTextEffects($content) { | |||
$content.find('.text-animation-container').each(function () { | |||
const $el = $(this); | |||
if ($el.data('animated')) return; | |||
const text = $el.text(); | |||
const chars = text.split(''); | |||
const isWavy = $el.hasClass('wavy'); | |||
const isRainbow = $el.hasClass('rainbow'); | |||
const isJolt = $el.hasClass('jolt'); // Added Jolt check | |||
const nodes = chars.map((char, i) => { | |||
const $span = $('<span>').text(char === ' ' ? '\u00A0' : char); | |||
let delays = []; | |||
if (isWavy) delays.push((i * -0.15).toFixed(2) + 's'); | |||
if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's'); | |||
// Randomized delay for Jolt to make it look "glitchy" | |||
if (isJolt) { | |||
delays.push((Math.random() * -0.5).toFixed(2) + 's'); | |||
} | |||
if (delays.length) { | |||
$span.css('animation-delay', delays.join(', ')); | |||
} | |||
return $span; | |||
}); | |||
$el.empty().append(nodes).data('animated', true); | |||
}); | }); | ||
} | |||
mw.hook('wikipage.content').add(applyTextEffects); | |||
}()); | |||
} | |||
Revision as of 19:08, 17 March 2026
/* Any JavaScript here will be loaded for all users on every page load. */
(function () {
function applyTextEffects($content) {
$content.find('.text-animation-container').each(function () {
const $el = $(this);
if ($el.data('animated')) return;
const text = $el.text();
const chars = text.split('');
const isWavy = $el.hasClass('wavy');
const isRainbow = $el.hasClass('rainbow');
const isJolt = $el.hasClass('jolt'); // Added Jolt check
const nodes = chars.map((char, i) => {
const $span = $('<span>').text(char === ' ' ? '\u00A0' : char);
let delays = [];
if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
// Randomized delay for Jolt to make it look "glitchy"
if (isJolt) {
delays.push((Math.random() * -0.5).toFixed(2) + 's');
}
if (delays.length) {
$span.css('animation-delay', delays.join(', '));
}
return $span;
});
$el.empty().append(nodes).data('animated', true);
});
}
mw.hook('wikipage.content').add(applyTextEffects);
}());