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.

/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
/*global mw, $, importScript */

/**
 * Redirect bad mirrors to it.wikipedia.org
 * [[m:User:Hoo man]]
 */
( function () {
	var i, isBad,
		badMirrors = [
		'wikipedia.sapere.alice.it',
		'212.48.3.33',
		'wikipedia.virgilio.it',
		'213.92.16.218',
		];
	for ( i = 0; i < badMirrors.length; i++ ) {
		if ( document.___location.href.indexOf( badMirrors[ i ] ) !== -1 ) {
			isBad = true;
			break;
		}
	}
	if ( isBad ) {
		// redirect users to the same page on itwiki
		//document.___location.href = '//it.wikipedia.org/wiki/' + mw.config.get( 'wgPageName' );
		// redirect users to a landing page
		document.___location.href = '//it.wikipedia.org/wiki/Wikipedia:Live_mirror';
	}
} )();


/**
 * Collegamento diretto alla pagina di upload di Commons nel portlet Strumenti
 */
$( function () {
	mw.util.addPortletLink( 'p-tb', '//commons.wikimedia.org/wiki/Commons:Upload/it', 'Carica su Commons',
						    't-uploadcommons', 'Carica file multimediali su Wikimedia Commons', 'm', '#t-specialpages' );
} );

/**
 * In "Pagina principale" aggiunge il link alla lista completa di tutte le pagine
 */
if ( mw.config.get( 'wgIsMainPage' ) || mw.config.get( 'wgPageName' ) === "Discussione:Pagina_principale" ) {
	$( function () {
		mw.util.addPortletLink( 'p-lang', '//meta.wikimedia.org/wiki/Lista_di_Wikipedie',
								'Lista completa', 'interwiki-completelist', 'Lista completa delle Wikipedie' );
	} );
}

/**
 * Utilizzata con [[template:Titolo errato]] per cambiare il titolo di una pagina,
 * cerca un HTML (creato dal template) contenente:
 * <div id="RealTitleBanner"><span id="RealTitle">titolo</span></div>
 * Si può disattivare con un elemento con id="DisableRealTitle".
 * Importata inizialmente da [[en:MediaWiki:Common.js]].
 */

function checkRealTitleBanner() {
	var $realTitleBanner = $( '#RealTitleBanner' ), $realTitle, $firstH1;
	if ( $realTitleBanner.length && !$( '#DisableRealTitle' ).length ) {
		$realTitle = $realTitleBanner.find( '#RealTitle' );
		$firstH1 = $( 'h1:first' );
		if ( $realTitle.length && $firstH1.length ) {
			$realTitleBanner.hide();
			$firstH1.html( $realTitle.html() );
			document.title = $realTitle.text() + ' - Wikipedia';
		}
	}
}

$( checkRealTitleBanner );

/**
 * WikiMiniAtlas
 * WikiMiniAtlas is a popup click and drag world map.
 * This script causes all of our coordinate links to display the WikiMiniAtlas popup button.
 * The script itself is located on meta because it is used by many projects.
 * See [[Meta:WikiMiniAtlas]] for more information. 
 */
 
mw.loader.load( '//meta.wikimedia.org/w/index.php?title=MediaWiki:Wikiminiatlas.js&action=raw&ctype=text/javascript&smaxage=21600&maxage=86400' );

/**
 * Aggiunge un combobox a [[MediaWiki:Edittools]] per selezionare un gruppo di caratteri speciali.
 */

function comboboxEdittools() {
	var $specialChars = $( '#specialchars' ), $select;
	if ( $specialChars.length ) {
		$select = $( '<select>' ).change( function () {
			$specialChars.find( 'p' ).hide();
			$specialChars.find( 'option:selected' ).data().show();
		} );
		$specialChars.find( 'p' ).each( function () {
			$( '<option>' ).html( $( this ).attr( 'id' ).replace( /_/g, ' ' ) )
				.data( $( this ) ).appendTo( $select );
		} );
		$specialChars.prepend( $select );
		$select.change();
	}
}

$( comboboxEdittools );

/**
 * Layout pagina di modifica
 */
$( function () {
	if ( mw.config.get( 'wgAction' ) === 'edit' ) {
		/* Allarga l'edittools a tutta pagina */
		$( '#Standard' ).css( 'width', '100%' );
	}
} );

/**
 * @source www.mediawiki.org/wiki/Snippets/Load_JS_and_CSS_by_URL
 * @rev 5
 */
var extraJS = mw.util.getParamValue( 'withJS' );
if ( extraJS ) {
	if ( extraJS.match( /^MediaWiki:[^&<>=%#]*\.js$/ ) ) {
		importScript( extraJS );
	} else {
		mw.notify( 'Only pages from the MediaWiki namespace are allowed.', { title: 'Invalid withJS value' } );
	}
}

/**
 * Utilizzata con [[template:Galleria]] per creare una galleria di immagini,
 * cerca un HTML (creato dal template) contenente:
 * <div class="ImageGroup"><div class="ImageGroupUnits">immagini</div></div>
 * Idea originale da [[fr:MediaWiki:Common.js]] del 2007.
 * 
 * @author [[it:User:Rotpunkt]]
 */

function updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink ) {
	$images.hide().eq( currImg ).show();
	$countInfo.html( '(' + ( currImg + 1 ) + '/' + $images.length + ')' );
	$prevLink.toggle( currImg !== 0 );
	$nextLink.toggle( currImg !== $images.length - 1 );
}

function initImageGroup() {
	$( 'div.ImageGroup > div.ImageGroupUnits' ).each( function ( i, imageGroupUnits ) {
		var $images,  $prevLink, $nextLink, $countInfo, currImg = 0;
		$images = $( imageGroupUnits ).children( '.center' );
		$countInfo = $( '<tt>' ).css( 'font-size', '110%' );
		$prevLink =	$( '<a>' )
			.attr( 'href', '#' ).attr( 'title', 'Immagine precedente' )
			.text( '◀' ).css( 'text-decoration', 'none' )
			.click( function ( e ) {
				e.preventDefault();
				updateImageGroup( currImg -= 1, $images, $countInfo, $prevLink, $nextLink );
			} );
		$nextLink =	$( '<a>' )
			.attr( 'href', '#' ).attr( 'title', 'Immagine successiva' )
			.text( '▶' ).css( 'text-decoration', 'none' )
			.click( function ( e ) {
				e.preventDefault();
				updateImageGroup( currImg += 1, $images, $countInfo, $prevLink, $nextLink );
			} );
		updateImageGroup( currImg, $images, $countInfo, $prevLink, $nextLink );
		$( imageGroupUnits ).prepend( $prevLink, $countInfo, $nextLink );
	} );
}

$( initImageGroup );

/**
 * Toglie "Soggetto/Intestazione" nelle creazioni delle discussioni al Bar
 */
if ( mw.config.get( 'wgNamespaceNumber' ) === 4 &&
	 mw.config.get( 'wgPageName' ).indexOf( 'Wikipedia:Bar/' ) === 0 &&
	 mw.config.get( 'wgAction' ) === 'edit' &&
	 document.URL.indexOf( '&section=new&preload=' ) !== -1) {
	$( function () {
		document.getElementById( 'wpSummaryLabel' ).style.display = 'none';
		document.getElementById( 'wpSummary' ).style.display = 'none';
	} );
}


/**
 * Cambia posizione e link del link "modifica" delle sezioni
 * Fatto in Common.css, questo è un fix per IE7
 */
if ( $.client.profile().name === 'msie' && $.client.profile().versionNumber < 8 ) {
	$( function () {
		$( '.editsection' ).each( function( i, e ) {
			$( e ).parent().append( e );
		} );
	} );
}

/**
 * OpenStreetMap
 * Basato in parte su [[meta:MediaWiki:OSM.js]] e [[fr:MediaWiki:Gadget-osm.js]]
 * e ampiamente modificato da [[it:user:Rotpunkt]].
 */

function showOpenStreetMap( geohackParams ) {
	var url, $topDiv, $iframe, $osmDiv;

	// top div
	$topDiv = $( '<div>' ).css( { position: 'relative', top: '0', width: '100%', height: '10%' } );
	$( '<a>' )
		.attr( 'href', '#' )
		.attr( 'title', 'Nascondi la mappa' )
		.text( 'Nascondi' )
		.css( { float: 'right', margin: '10px' } )
		.click( function ( e ) {
			e.preventDefault();
			$( '#OpenStreetMap' ).hide();
		} )
		.appendTo( $topDiv );

	// iframe
	url = '//tools.wmflabs.org/wiwosm/osm-on-ol/kml-on-ol.php?' +
		  'lang=' + mw.config.get( 'wgPageContentLanguage' ) +
		  '&uselang=' + mw.util.rawurlencode( mw.config.get( 'wgUserLanguage' ) ) +
		  '&params=' + geohackParams +
		  '&title=' + mw.util.wikiUrlencode( mw.config.get( 'wgTitle' ) ) +
		  ( window.___location.protocol === 'https:' ? '&secure=1' : '' );
	$iframe = $( '<iframe>' )
		.attr( 'src', url )
		.css( { width: '100%', height: '90%', clear: 'both' } );

	// container div
	$osmDiv = $( '<div>' )
		.attr( 'id', 'OpenStreetMap' )
		.attr( 'title', 'Clicca e trascina per ridimensionare la mappa' )
		.css( {
			position : 'absolute',
			zIndex : 5000,
			top: '10%',
			left: '15%',
			width : '70%',
			height : '80%',
			border : '2px solid black',
			backgroundColor : 'white',
			overflow : 'hidden',
			cursor: 'move'
		} )
		.append( $topDiv )
		.append( $iframe );
	mw.loader.using( ['jquery.ui.draggable', 'jquery.ui.resizable'], function () {
		$osmDiv.draggable();
		$osmDiv.resizable( { minWidth: 150, minHeight: 200 } );
	} );
	$( 'body' ).append( $osmDiv );
}

// ritorna i parametri geohack, cercandoli nel tag anchor creato dal template coord
function getGeohackParams() {
	var ret;
	$( '#coordinates a' ).each( function( i, el ) {
		if ( el.href.match( /geohack/ ) && !el.href.match( /(skyhack|_globe:(?!earth))/ ) ) {
			ret = el.href.split( 'params=' )[1];
			return false;
		}
	} );
	return ret;
}

function initOpenStreetMap() {
	var $toggleAnchor, $coordinates = $( '#coordinates' ), geohackParams = getGeohackParams();
	// se è stato utilizzato il template coord e se sono presenti parametri geohack validi
	if ( $coordinates.length && geohackParams ) {
		$toggleAnchor = $( '<a>' )
			.attr( 'href', '#' )
			.attr( 'title', 'Mostrare / nascondere la mappa' )
			.text( 'Mappa' )
			.click( function ( e ) {
				e.preventDefault();
				var $osmDiv = $( '#OpenStreetMap' );
				if ( $osmDiv.length ) {
					$osmDiv.toggle();
				} else {
					showOpenStreetMap( geohackParams );
				}
			} );
		$coordinates.append( ' (', $toggleAnchor, ')' );
	}
}

$( initOpenStreetMap );

/**
 * Classe autocollapse con mw-collapsible: se presente più di una table con classe mw-collapsible,
 * quelle con anche la classe autocollapse si chiudono da sole. Deve essere presente anche la classe navbox.
 */
$( function () {
	if ( $( 'table.navbox.mw-collapsible' ).length > 1) {
		$( 'table.navbox.mw-collapsible.autocollapse' ).each( function ( i, el ) {
			if ( !$( el ).hasClass( 'mw-collapsed' ) ) {
				// makeCollapsible a volte è eseguita prima, a volte successivamente al Common.js,
				// se è già stata eseguita, non resta che simulare un click.
				if ( $( el ).data( 'mw-made-collapsible' ) ) {
					// hide() chiude la tabella più velocemente di fadeOut
					$( el ).children( 'tr:not(:first)' ).hide();
					$( el ).find( '.mw-collapsible-toggle > a' ).click();
				} else {
					$( el ).addClass( 'mw-collapsed' );
				}
			}
		} );
	}
} );

/**
 * Reference tooltips
 */
mw.loader.load( '//it.wikipedia.org/w/index.php?title=MediaWiki:ReferenceTooltip.js&action=raw&ctype=text/javascript' );

/**
 * Esempio di diff in Aiuto:Diff
 */
if ( mw.config.get( 'wgPageName' ) === 'Aiuto:Diff' ) {
	mw.loader.load( 'mediawiki.action.history.diff' );
}

/**
 * Ricerca in Wikidata
 */
if ( mw.config.get( 'wgCanonicalSpecialPageName' ) === 'Search' ||
	 ( mw.config.get( 'wgArticleId' ) === 0 && mw.config.get( 'wgCanonicalSpecialPageName' ) === false ) ) {
	mw.loader.load( '//en.wikipedia.org/w/index.php?title=MediaWiki:Wdsearch.js&action=raw&ctype=text/javascript' );
}

/**
 * Menu interprogetto nella sidebar, vedi anche [[Modulo:Interprogetto]]
 */
importScript( 'MediaWiki:InterProject.js' );