« MediaWiki:Common.js » : différence entre les versions
Aller à la navigation
Aller à la recherche
Aucun résumé des modifications |
Aucun résumé des modifications |
||
| Ligne 1 : | Ligne 1 : | ||
javascript | |||
( function () { | ( function () { | ||
'use strict'; | 'use strict'; | ||
var THEMES = [ 'space', 'terminal' ]; | var THEMES = [ 'space', 'terminal' ]; | ||
var KEY = 'emush-theme'; | var KEY = 'emush-theme'; | ||
// Read the stored theme, falling back to the first one | |||
function current() { | function current() { | ||
try { | try { | ||
| Ligne 14 : | Ligne 15 : | ||
} | } | ||
// Swap the view-* class on <html> and persist the choice | |||
function apply( theme ) { | function apply( theme ) { | ||
var root = document.documentElement; | var root = document.documentElement; | ||
| Ligne 21 : | Ligne 23 : | ||
} | } | ||
// | // The link already exists in the HTML — only bind the click | ||
$( function () { | |||
var li = document.getElementById( 'pt-themetoggle' ); | |||
if ( !li ) { return; } | |||
li.addEventListener( 'click', function ( e ) { | |||
e.preventDefault(); | |||
apply( current() === 'space' ? 'terminal' : 'space' ); | |||
} ); | } ); | ||
} ); | } ); | ||
}() ); | }() ); | ||
Version du 30 juillet 2026 à 00:25
javascript
( function () {
'use strict';
var THEMES = [ 'space', 'terminal' ];
var KEY = 'emush-theme';
// Read the stored theme, falling back to the first one
function current() {
try {
var s = localStorage.getItem( KEY );
if ( s && THEMES.indexOf( s ) !== -1 ) { return s; }
} catch ( e ) {}
return THEMES[ 0 ];
}
// Swap the view-* class on <html> and persist the choice
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 ) {}
}
// The link already exists in the HTML — only bind the click
$( function () {
var li = document.getElementById( 'pt-themetoggle' );
if ( !li ) { return; }
li.addEventListener( 'click', function ( e ) {
e.preventDefault();
apply( current() === 'space' ? 'terminal' : 'space' );
} );
} );
}() );