Jump to content

MediaWiki:Common.js: Difference between revisions

From FC1
No edit summary
No edit summary
 
(7 intermediate revisions by the same user not shown)
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() {
     function applyTextEffects($content) {
     function applyEffects(el) {
         $content.find('.text-animation-container').each(function () {
         const hasEffect = ['wavy', 'rainbow', 'jolt', 'pulse', 'force-glow', 'force-shadow'].some(cls => el.classList.contains(cls));
            const $el = $(this);
        if (!hasEffect || el.getAttribute('data-animated') === 'true') return;
            if ($el.data('animated')) return;  


            const text = $el.text();
        const text = el.textContent;
            const chars = text.split('');
        const isJolt = el.classList.contains('jolt');
            const isWavy = $el.hasClass('wavy');
        const isWavy = el.classList.contains('wavy');
            const isRainbow = $el.hasClass('rainbow');
        const isRainbow = el.classList.contains('rainbow');
            const isJolt = $el.hasClass('jolt'); // Added Jolt check


            const nodes = chars.map((char, i) => {
        // Note: Pulse is handled by the container CSS now
                const $span = $('<span>').text(char === ' ' ? '\u00A0' : char);
        el.style.setProperty('animation-delay', '0s', 'important');  
                let delays = [];
       
        let lastVariant = -1;


                if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
        const newHTML = text.split('').map((c, i) => {
                if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
            let delays = [];
                  
            let classes = [];
                 // Randomized delay for Jolt to make it look "glitchy"
           
                 if (isJolt) {
            if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
                    delays.push((Math.random() * -0.5).toFixed(2) + 's');
            if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
                }
           
            if (isJolt) {
                 let variant;
                 do { variant = Math.floor(Math.random() * 3) + 1; } while (variant === lastVariant);
                lastVariant = variant;
                 classes.push(`jolt-v${variant}`);
                delays.push((Math.random() * -0.35).toFixed(2) + 's');
            }


                if (delays.length) {
            const content = (c === ' ') ? '&nbsp;' : c;
                    $span.css('animation-delay', delays.join(', '));
            const delayStyle = delays.length > 0 ? `style="animation-delay: ${delays.join(', ')} !important;"` : '';
                }
            const classAttr = classes.length > 0 ? `class="${classes.join(' ')}"` : '';
                return $span;
           
            });
            return `<span ${classAttr} ${delayStyle}>${content}</span>`;
        }).join('');


            $el.empty().append(nodes).data('animated', true);
        el.innerHTML = newHTML;
        });
        el.setAttribute('data-animated', 'true');
     }
     }


     mw.hook('wikipage.content').add(applyTextEffects);
     mw.hook('wikipage.content').add(function($content) {
}());
        $content.find('.text-animation-container').each(function() {
            applyEffects(this);
        });
    });
})();

Latest revision as of 22:29, 17 March 2026

/* Any JavaScript here will be loaded for all users on every page load. */
(function() {
    function applyEffects(el) {
        const hasEffect = ['wavy', 'rainbow', 'jolt', 'pulse', 'force-glow', 'force-shadow'].some(cls => el.classList.contains(cls));
        if (!hasEffect || el.getAttribute('data-animated') === 'true') return;

        const text = el.textContent;
        const isJolt = el.classList.contains('jolt');
        const isWavy = el.classList.contains('wavy');
        const isRainbow = el.classList.contains('rainbow');

        // Note: Pulse is handled by the container CSS now
        el.style.setProperty('animation-delay', '0s', 'important'); 
        
        let lastVariant = -1;

        const newHTML = text.split('').map((c, i) => {
            let delays = [];
            let classes = [];
            
            if (isWavy) delays.push((i * -0.15).toFixed(2) + 's');
            if (isRainbow) delays.push((i * -0.15).toFixed(2) + 's');
            
            if (isJolt) {
                let variant;
                do { variant = Math.floor(Math.random() * 3) + 1; } while (variant === lastVariant);
                lastVariant = variant;
                classes.push(`jolt-v${variant}`);
                delays.push((Math.random() * -0.35).toFixed(2) + 's');
            }

            const content = (c === ' ') ? '&nbsp;' : c;
            const delayStyle = delays.length > 0 ? `style="animation-delay: ${delays.join(', ')} !important;"` : '';
            const classAttr = classes.length > 0 ? `class="${classes.join(' ')}"` : '';
            
            return `<span ${classAttr} ${delayStyle}>${content}</span>`;
        }).join('');

        el.innerHTML = newHTML;
        el.setAttribute('data-animated', 'true');
    }

    mw.hook('wikipage.content').add(function($content) {
        $content.find('.text-animation-container').each(function() {
            applyEffects(this);
        });
    });
})();