MediaWiki:Gadget-switcher.js
Questa pagina definisce alcuni parametri di aspetto e comportamento generale di tutte le pagine. Per personalizzarli vedi Aiuto:Stile utente.
Nota: dopo aver salvato è necessario pulire la cache del proprio browser per vedere i cambiamenti (per le pagine globali è comunque necessario attendere qualche minuto). Per Mozilla / Firefox / Safari: fare clic su Ricarica tenendo premuto il tasto delle maiuscole, oppure premere Ctrl-F5 o Ctrl-R (Command-R su Mac); per Chrome: premere Ctrl-Shift-R (Command-Shift-R su un Mac); per Konqueror: premere il pulsante Ricarica o il tasto F5; per Opera può essere necessario svuotare completamente la cache dal menù Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
'use strict';
$( function () {
$.each( document.querySelectorAll( '.switcher-container' ), function ( i, container ) {
if ( i == 0 ) { mw.loader.using(['mediawiki.util'], function(){mw.util.addCSS('.switcher-container label input{margin-right:0.5em}')}) }
var selected, $radio;
var switchers = [];
var radioName = 'switcher-' + i;
$.each( container.children, function ( j, switcher ) {
var label = switcher.querySelector( '.switcher-label' );
if ( !label || !label.childNodes.length ) {
return;
}
switchers.push( switcher );
$radio = $( '<input>' ).prop({ type: 'radio', name: radioName }).on( 'click', function () {
$( selected ).hide();
$( switcher ).show();
selected = switcher;
} );
if ( !selected ) {
// Mark the first one as selected
selected = switcher;
$radio.prop( 'checked', true );
} else if ( label.getAttribute( 'data-switcher-default' ) !== null ) {
// Custom default
$radio.click();
} else {
// Hide non-default
$( switcher ).hide();
}
$( '<label style="display:block;width:fit-content"></label>' )
.append( $radio, label.childNodes )
.appendTo( container );
$( label ).remove();
} );
if ( switchers.length > 1 ) {
$( '<label style="display:block;width:fit-content">Vedi tutto</label>' ).prepend(
$( '<input>' ).prop({ type: 'radio', name: radioName }).on( 'click', function () {
$( switchers ).show();
selected = switchers;
} )
).appendTo( container );
}
if ( switchers.length === 1 ) {
$radio.remove();
}
} );
} );