MediaWiki:Common.js: differenze tra le versioni

Contenuto cancellato Contenuto aggiunto
mNessun oggetto della modifica
 
(303 versioni intermedie di 37 utenti non mostrate)
Riga 1:
/**
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */
* Mantenere il codice di MediaWiki:Common.js il più breve possibile, in quanto è caricato
* da ciascuna pagina, per tutti gli utenti che navigano sulla versione desktop.
* Creare piuttosto accessori abilitati di default (gli accessori sono infatti moduli
* ottimizzati del ResourceLoader con la possibilità di aggiungere dipendenze, ecc.).
*/
/* global mediaWiki, jQuery */
 
( function ( mw, $ ) {
<pre>
'use strict';
 
// ============================
/*
// Caricamento script
Correzione della posizione del link [modifica] delle sezioni.
// ============================
Copyright 2006, Marc Mongenet
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
See http://www.gnu.org/licenses/gpl.html
The function looks for <span class="editsection">, and move them
at the end of their parent and display them inline in small font.
var oldEditsectionLinks=true disables the function.
*/
setModifySectionStyle = function()
{
try {
if (!(typeof oldEditsectionLinks == 'undefined' || oldEditsectionLinks == false)) return;
var spans = document.getElementsByTagName("span");
for (var s = 0; s < spans.length; ++s) {
var span = spans[s];
if (span.className == "editsection") {
span.style.fontSize = "90%";
span.style.fontWeight = "normal";
span.style.cssFloat = span.style.styleFloat = "none";
span.parentNode.appendChild(document.createTextNode(" "));
span.parentNode.appendChild(span);
}
}
} catch (e) { /* something went wrong */ }
}
addOnloadHook(setModifySectionStyle);
/*
 
/**
</pre>
* 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' );
}
 
// ============================
// Modifica HTML pagine
// ============================
 
/**
* Aggiunge un combobox a [[MediaWiki:Edittools]] per selezionare un gruppo di caratteri speciali.
*/
function comboboxEdittools() {
var $specialChars = $( '#specialchars' );
if ( $specialChars.length ) {
var $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 );
 
// ============================
// Supporto ai template
// ============================
 
/**
* 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 currImg = 0;
var $images = $( imageGroupUnits ).children( '.center, .mw-halign-center' );
var $countInfo = $( '<kbd>' ).css( 'font-size', '110%' );
var $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 );
} );
var $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 );
 
/**
* Utilizzata con [[Template:Navbox]]: se presente più di un navbox con
* classe mw-collapsible, quelli con autocollapse si chiudono da soli.
*/
function checkAutocollapse( $content ) {
var $navbox = $content.filter( '.navbox' );
if ( $navbox.length > 1 ) {
$navbox.filter( '.autocollapse' ).find( '.mw-collapsible-toggle' ).click();
}
}
 
mw.hook( 'wikipage.collapsibleContent' ).add( checkAutocollapse );
}( mediaWiki, jQuery ) );