MediaWiki:Common.js
Note : après avoir publié vos modifications, il se peut que vous deviez forcer le rechargement complet du cache de votre navigateur pour voir les changements.
- Firefox / Safari : maintenez la touche Maj (Shift) en cliquant sur le bouton Actualiser ou appuyez sur Ctrl + F5 ou Ctrl + R (⌘ + R sur un Mac).
- Google Chrome : appuyez sur Ctrl + Maj + R (⌘ + Shift + R sur un Mac).
- Edge : maintenez la touche Ctrl en cliquant sur le bouton Actualiser ou pressez Ctrl + F5.
/* Handle the theme switcher */
( 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 ) {}
// Notify other scripts that the layout may have changed
mw.hook( 'emush.theme' ).fire( theme );
}
// 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' );
} );
} );
}() );
/* Ensure the left panel is always the same height as #content */
$( function () {
var panel = document.getElementById( 'mw-panel' );
var content = document.getElementById( 'content' );
if ( !panel || !content ) { return; }
// Set an exact height; min-height would only act as a floor
function sync() {
panel.style.minHeight = '0';
// Convert 1em to pixels using the panel's own font size
var em = parseFloat( getComputedStyle( panel ).fontSize );
panel.style.height = ( content.getBoundingClientRect().height - em ) + 'px';
}
sync();
// Recompute when the content box changes size
if ( window.ResizeObserver ) {
new ResizeObserver( sync ).observe( content );
} else {
window.addEventListener( 'resize', sync );
}
} );
/* Make the logo at the top center redirect to the home page */
$( function () {
var sidebarLink = document.querySelector( '#p-logo a' );
if ( !sidebarLink || document.getElementById( 'emush-logo-hotspot' ) ) { return; }
var hotspot = document.createElement( 'a' );
hotspot.id = 'emush-logo-hotspot';
hotspot.href = sidebarLink.getAttribute( 'href' );
hotspot.title = sidebarLink.getAttribute( 'title' ) || '';
hotspot.setAttribute( 'aria-label', 'Accueil' );
document.body.appendChild( hotspot );
} );