« MediaWiki:Common.js » : différence entre les versions

De eMushpedia
Aller à la navigation Aller à la recherche
Blanked the page
Balise : Blanchiment
Aucun résumé des modifications
Ligne 1 : Ligne 1 :
( function () {
    'use strict';


    var THEMES = [ 'space', 'terminal' ];
    var LABELS = { space: 'Espace', terminal: 'Terminal' };
    var KEY = 'emush-theme';
    function current() {
        try {
            var s = localStorage.getItem( KEY );
            if ( s && THEMES.indexOf( s ) !== -1 ) { return s; }
        } catch ( e ) {}
        return THEMES[ 0 ];
    }
    function apply( theme ) {
        var root = document.documentElement;
        THEMES.forEach( function ( t ) { root.classList.remove( 'view-' + t ); } );
        root.classList.add( 'view-' + theme );
        try { localStorage.setItem( KEY, theme ); } catch ( e ) {}
    }
    // Apply memorise theme immediately
    apply( current() );
    // Add button in the right tooltip
    mw.loader.using( 'mediawiki.util' ).then( function () {
        $( function () {
            var li = mw.util.addPortletLink(
                'p-personal', '#',
                'Thème : ' + LABELS[ current() ],
                'pt-themetoggle', 'Changer de thème'
            );
            if ( !li ) { return; }
            $( li ).on( 'click', function ( e ) {
                e.preventDefault();
                var next = current() === 'space' ? 'terminal' : 'space';
                apply( next );
                var a = li.querySelector( 'a' );
                if ( a ) { a.textContent = 'Thème : ' + LABELS[ next ]; }
            } );
        } );
    } );
}() );

Version du 30 juillet 2026 à 00:20

( function () {
    'use strict';

    var THEMES = [ 'space', 'terminal' ];
    var LABELS = { space: 'Espace', terminal: 'Terminal' };
    var KEY = 'emush-theme';

    function current() {
        try {
            var s = localStorage.getItem( KEY );
            if ( s && THEMES.indexOf( s ) !== -1 ) { return s; }
        } catch ( e ) {}
        return THEMES[ 0 ];
    }

    function apply( theme ) {
        var root = document.documentElement;
        THEMES.forEach( function ( t ) { root.classList.remove( 'view-' + t ); } );
        root.classList.add( 'view-' + theme );
        try { localStorage.setItem( KEY, theme ); } catch ( e ) {}
    }

    // Apply memorise theme immediately
    apply( current() );

    // Add button in the right tooltip
    mw.loader.using( 'mediawiki.util' ).then( function () {
        $( function () {
            var li = mw.util.addPortletLink(
                'p-personal', '#',
                'Thème : ' + LABELS[ current() ],
                'pt-themetoggle', 'Changer de thème'
            );
            if ( !li ) { return; }
            $( li ).on( 'click', function ( e ) {
                e.preventDefault();
                var next = current() === 'space' ? 'terminal' : 'space';
                apply( next );
                var a = li.querySelector( 'a' );
                if ( a ) { a.textContent = 'Thème : ' + LABELS[ next ]; }
            } );
        } );
    } );
}() );