MediaWiki:Common.js
/**
* 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, $ ) {
'use strict';
// ============================
// Caricamento script
// ============================
/**
* 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 ) );
Content Disclaimer
Informasi ini disarikan dari Wikipedia dan disajikan kembali untuk tujuan edukasi. Konten tersedia di bawah lisensi CC BY-SA 3.0. Kami tidak bertanggung jawab atas ketidakakuratan data yang bersumber dari kontribusi publik tersebut.
- The information displayed on this website is sourced in part or in whole from Wikipedia and has been adapted for the purpose of restating it. We strive to provide accurate and relevant information, however:
- There is no guarantee of absolute accuracy. Wikipedia is an open, collaborative project that can be edited by anyone, so information is subject to change.
- It is not intended to constitute professional advice. The content displayed is for informational and educational purposes only. For important decisions (e.g., medical, legal, or financial), please consult a professional.
- Content copyright. Wikipedia is licensed under the Creative Commons Attribution-ShareAlike License (CC BY-SA). This means that content may be reused with appropriate attribution and shared under a similar license.
- Responsible use. Any risk arising from the use of information from this website is entirely the responsibility of the user.