Avviso: giovedì 26 e venerdì 27 marzo, il sito sarà in manutenzione straordinaria per l'ultima fase di avanzamento della piattaforma.

MediaWiki:Common.js: differenze tra le versioni

Da GuidaSBN.
(fix)
 
(test)
 
Riga 20: Riga 20:
  
 
$( checkRealTitleBanner );
 
$( checkRealTitleBanner );
 +
 +
/**
 +
* 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 = $( '<kbd>' ).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 );

Versione attuale delle 15:27, 2 ott 2017

Home > MediaWiki:Common.js
/**
	 * 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 );
 
/**
	 * 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 = $( '<kbd>' ).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 );