MediaWiki:Apri-chiudi.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 menu Strumenti → Preferenze; per Internet Explorer: mantenere premuto il tasto Ctrl mentre si preme il pulsante Aggiorna o premere Ctrl-F5.
// <nowiki> Codice JavaScript: inizio...
/* Dynamic Navigation Bars
*
* Vedi: [[w:en:Wikipedia:NavFrame]]
*
* Codice originale: [[w:en:MediaWiki:Common.js]]
* integrato con: [[w:it:MediaWiki:Common.js]]
* da: [[q:it:User:FRacco]]
*
* Ultimo controllo al codice: 12/12/2013 */
// set up the words in your language
var NavigationBarHide = "« Nascondi";
var NavigationBarShow = "» Mostra";
// set up max count of Navigation Bars on page, if there are more (or equal), all will be hidden
// NavigationBarShowDefault = 0; all bars will be hidden
// NavigationBarShowDefault = n; on pages with more than "n" bars all bars will be hidden
var NavigationBarShowDefault = 0;
// shows and hides content and picture (if available) of navigation bars
// Parameters:
// indexNavigationBar: the index of navigation bar to be toggled
window.toggleNavigationBar = function( indexNavigationBar, event ) {
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavChild;
if ( !NavFrame || !NavToggle ) {
return false;
}
// if shown now
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
// if hidden now
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
if ( event ) event.preventDefault();
};
// adds show/hide-button to navigation bars
function createNavigationBarToggleButton() {
var indexNavigationBar = 0;
var NavFrame;
var NavChild;
// iterate over all div-elements
var divs = document.getElementsByTagName( 'div' );
for ( var i = 0; ( NavFrame = divs[i] ); i++ ) {
// if found a navigation bar
if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
indexNavigationBar++;
var NavToggle = document.createElement( 'a' );
NavToggle.className = 'NavToggle';
NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar );
NavToggle.setAttribute( 'href', '#' );
$( NavToggle ).on( 'click', $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) );
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' );
/* Check if any children are already hidden. This loop is here for backwards compatibility:
* the old way of making NavFrames start out collapsed was to manually add style="display:none"
* to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make
* the content visible without JavaScript support), the new recommended way is to add the class
* "collapsed" to the NavFrame itself, just like with collapsible tables. */
for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
if ( NavChild.style.display === 'none' ) {
NavFrame.className += ' collapsed';
isCollapsed = true;
}
}
}
if ( isCollapsed ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) {
NavChild.style.display = 'none';
}
}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
NavToggle.appendChild( NavToggleText );
// add NavToggle-Button as first div-element in < div class="NavFrame" >
/* Find the NavHead and attach the toggle link
* (Must be this complicated because Moz's firstChild handling is borked) */
for ( var j = 0; j < NavFrame.childNodes.length; j++ ) {
if ( $( NavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) {
NavToggle.style.color = NavFrame.childNodes[j].style.color;
NavFrame.childNodes[j].appendChild( NavToggle );
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
}
// if more (or equal) Navigation Bars found than Default: hide all
// (except for ones defined with "collapsed" or "expanded" class)
if ( indexNavigationBar >= NavigationBarShowDefault ) {
for ( var i = 1; i <= indexNavigationBar; i++ ) {
NavFrame = document.getElementById( 'NavFrame' + i );
if ( !$( NavFrame ).hasClass( 'collapsed' ) && !$( NavFrame ).hasClass( 'expanded' ) )
window.toggleNavigationBar( i );
}
}
};
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
/* Tabelle collassabili (CollapsibleTables)
*
* Descrizione: Permette alle tabelle di espandersi e contrarsi, mostrando solo il titolo.
*
* Vedi: [[w:en:Wikipedia:Collapsible tables]]
*
* Codice originale: [[w:en:MediaWiki:Common.js]]
* Mantenimento: [[w:en:User:R. Koot]]
*
* Ultimo controllo al codice: 12/12/2013 */
// set up the words in your language
var collapseCaption = "▲ Nascondi";
var expandCaption = "▼ Mostra";
// set up max count of collapsible tables on page,
// if there are more (or equal), all ".autocollapse"
// tables will be hidden
var autoCollapse = 2;
window.collapseTable = function( tableIndex ) {
var Button = document.getElementById( "collapseButton" + tableIndex );
var Table = document.getElementById( "collapsibleTable" + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.rows;
var i;
if ( Button.firstChild.data === collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = "none";
}
Button.firstChild.data = expandCaption;
} else {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
};
function createCollapseButtons() {
var tableIndex = 0;
var NavigationBoxes = {};
var Tables = document.getElementsByTagName( "table" );
var i;
function handleButtonLink( index, e ) {
window.collapseTable( index );
e.preventDefault();
}
for ( i = 0; i < Tables.length; i++ ) {
if ( $( Tables[i] ).hasClass( "collapsible" ) ) {
// aggiunge il pulsante e il numero di incremento soltanto se c'è una riga di intestazione per lavorarci
var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
if (!HeaderRow) continue;
var Header = HeaderRow.getElementsByTagName( "th" )[0];
if (!Header) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
var Button = document.createElement( "span" );
var ButtonLink = document.createElement( "a" );
var ButtonText = document.createTextNode( collapseCaption );
Button.className = "collapseButton";
/* gli stili sono dichiarati nel relativo Cascading Style Sheet (CSS) */
ButtonLink.style.color = Header.style.color;
ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
ButtonLink.setAttribute( "href", "#" );
$( ButtonLink ).on( "click", $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
ButtonLink.appendChild( ButtonText );
Button.appendChild( document.createTextNode( "[" ) );
Button.appendChild( ButtonLink );
Button.appendChild( document.createTextNode( "]" ) );
Header.insertBefore( Button, Header.firstChild );
tableIndex++;
}
}
for ( i = 0; i < tableIndex; i++ ) {
if ( $( NavigationBoxes[i] ).hasClass( "collapsed" ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( "autocollapse" ) ) ) {
window.collapseTable( i );
}
else if ( $( NavigationBoxes[i] ).hasClass( "innercollapse" ) ) {
var element = NavigationBoxes[i];
while ( ( element = element.parentNode ) ) {
if ( $( element ).hasClass( "outercollapse" ) ) {
window.collapseTable ( i );
break;
}
}
}
}
}
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/* jQuery makeCollapsible modificato
*
* script iniziale: [[mw:RL/DM#jquery.makeCollapsible]]
* autore iniziale: Krinkle <krinklemail@gmail.com>
*
* modifiche eseguite da: [[w:fr:User:Lgd]]
*
* Doppia licenza:
* @licenza CC-BY 3.0 <creativecommons.org/licenses/by/3.0>
* @licenza GPL2 <www.gnu.org/licenses/old-licenses/gpl-2.0.html>
*
* Ultimo controllo al codice: 12/12/2013 */
// set up the words in your language
var collapsetextDef = "Nascondi";
var collapsetextAll = "Nascondi tutto";
var expandtextDef = "Mostra";
var expandtextAll = "Mostra tutto";
var newCollapsible = function( $ ) {
return $( '.it-collapsible' ).each( function() {
var _fn = 'jquery.newCollapsible> ';
// Define reused variables and functions
var $that = $( this ).addClass( 'it-collapsible' ), // case: $( '#myAJAXelement' ).newCollapsible()
that = this,
collapsetext = $( this ).attr( 'data-collapsetext' ),
expandtext = $( this ).attr( 'data-expandtext' ),
toggleElement = function( $collapsible, action, $defaultToggle, instantHide ) {
// Validate parameters
if ( !$collapsible.jquery ) { // $collapsible must be an instance of jQuery
return;
}
if ( action != 'expand' && action != 'collapse' ) {
// action must be string with 'expand' or 'collapse'
return;
}
if ( typeof $defaultToggle == 'undefined' ) {
$defaultToggle = null;
}
if ( $defaultToggle !== null && !( $defaultToggle instanceof $ ) ) {
// is optional (may be undefined), but if defined it must be an instance of jQuery.
// If it's not, abort right away.
// After this $defaultToggle is either null or a valid jQuery instance.
return;
}
var $containers = null;
if ( action == 'collapse' ) {
// Collapse the element
if ( $collapsible.is( 'table' ) && $collapsible.find( 'caption' ).length ) {
// only table with caption
// Hide all table rows of this table
// Slide doens't work with tables, but fade does as of jQuery 1.1.3
// http://stackoverflow.com/questions/467336#920480
$containers = $collapsible.find( '>tbody>tr' );
if ( $defaultToggle ) {
$containers.stop( true, true ).fadeOut();
} else {
if ( instantHide ) {
$containers.hide();
} else {
$containers.stop( true, true ).fadeOut();
}
}
} else if ( !$collapsible.is( 'ul' ) && !$collapsible.is( 'ol' ) && !$that.is( 'table' ) ) {
// <div>, <p> etc. but not ul ol and tables without caption
var $collapsibleContent = $collapsible.find( '> .it-collapsible-content' );
// If a collapsible-content is defined, collapse it
if ( $collapsibleContent.length ) {
if ( instantHide ) {
$collapsibleContent.hide();
} else {
$collapsibleContent.slideUp();
}
// Otherwise assume this is a customcollapse with a remote toggle...
// ...and there is no collapsible-content because the entire element should be toggled
} else {
if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) {
$collapsible.fadeOut();
} else {
$collapsible.slideUp();
}
}
}
} else {
// Expand the element
if ( $collapsible.is( 'table' ) && $collapsible.find( 'caption' ).length ) {
$containers = $collapsible.find( '>tbody>tr' );
if ( $defaultToggle ) {
$containers.stop( true, true ).fadeIn();
} else {
$containers.stop( true, true ).fadeIn();
}
} else if ( !$collapsible.is( 'ul' ) && !$collapsible.is( 'ol' ) && !$that.is( 'table' ) ) {
// <div>, <p> etc.but not ul ol and not tables without caption
var $collapsibleContent = $collapsible.find( '> .it-collapsible-content' );
// If a collapsible-content is defined, collapse it
if ( $collapsibleContent.length ) {
$collapsibleContent.slideDown();
// Otherwise assume this is a customcollapse with a remote toggle...
// ...and there is no collapsible-content because the entire element should be toggled
} else {
if ( $collapsible.is( 'tr' ) || $collapsible.is( 'td' ) || $collapsible.is( 'th' ) ) {
$collapsible.fadeIn();
} else {
$collapsible.slideDown();
}
}
}
}
},
// Toggles collapsible and togglelink class and updates text label
toggleLinkDefault = function( that, e ) {
var $that = $(that),
$collapsible = $that.closest( '.it-collapsible.it-made-collapsible' ).toggleClass( 'it-collapsed' );
e.preventDefault();
e.stopPropagation();
// It's expanded right now
if ( !$that.hasClass( 'it-collapsible-toggle-collapsed' ) ) {
// Change link to "Show"
$that.removeClass( 'it-collapsible-toggle-expanded' ).addClass( 'it-collapsible-toggle-collapsed' );
if ( $that.find( '> a' ).length ) {
$that.find( '> a' ).text( expandtext );
} else {
$that.text( expandtext );
}
// Collapse element
toggleElement( $collapsible, 'collapse', $that );
// It's collapsed right now
} else {
// Change link to "Hide"
$that.removeClass( 'it-collapsible-toggle-collapsed' ).addClass( 'it-collapsible-toggle-expanded' );
if ( $that.find( '> a' ).length ) {
$that.find( '> a' ).text( collapsetext );
} else {
$that.text( collapsetext );
}
// Expand element
toggleElement( $collapsible, 'expand', $that );
}
return;
},
// Toggles collapsible and togglelink class
toggleLinkPremade = function( $that, e ) {
var $collapsible = $that.eq(0).closest( '.it-collapsible.it-made-collapsible' ).toggleClass( 'it-collapsed' );
if ( $( e.target ).is( 'a' ) ) {
return true;
}
e.preventDefault();
e.stopPropagation();
// It's expanded right now
if ( !$that.hasClass( 'it-collapsible-toggle-collapsed' ) ) {
// Change toggle to collapsed
$that.removeClass( 'it-collapsible-toggle-expanded' ).addClass( 'it-collapsible-toggle-collapsed' );
// Collapse element
toggleElement( $collapsible, 'collapse', $that );
// It's collapsed right now
} else {
// Change toggle to expanded
$that.removeClass( 'it-collapsible-toggle-collapsed' ).addClass( 'it-collapsible-toggle-expanded' );
// Expand element
toggleElement( $collapsible, 'expand', $that );
}
return;
},
// Toggles customcollapsible
toggleLinkCustom = function( $that, e, $collapsible ) {
// For the initial state call of customtogglers there is no event passed
if ( e ) {
e.preventDefault();
e.stopPropagation();
}
// Get current state and toggle to the opposite
var action = $collapsible.hasClass( 'it-collapsed' ) ? 'expand' : 'collapse';
$collapsible.toggleClass( 'it-collapsed' );
toggleElement( $collapsible, action, $that );
};
// Use custom text or default ?
if( !collapsetext ) {
//collapsetext = mw.message( 'collapsible-collapse' );
collapsetext = collapsetextDef;
}
if ( !expandtext ) {
//expandtext = mw.message( 'collapsible-expand' );
expandtext = expandtextDef;
}
// Create toggle link with a space around the brackets ( [text] )
var $toggleLink =
$( '<a href="#"></a>' )
.text( collapsetext )
.wrap( '<span class="it-collapsible-toggle"></span>' )
.parent()
.on( 'click.it-collapse', function( e ) {
toggleLinkDefault( this, e );
} );
// Return if it has been enabled already.
if ( $that.hasClass( 'it-made-collapsible' ) ) {
return;
} else {
$that.addClass( 'it-made-collapsible' );
}
// Check if this element has a custom position for the toggle link
// (ie. outside the container or deeper inside the tree)
// Then: Locate the custom toggle link(s) and bind them
if ( ( $that.attr( 'id' ) || '' ).indexOf( 'it-customcollapsible-' ) === 0 ) {
var thatId = $that.attr( 'id' ),
$customTogglers = $( '.' + thatId.replace( 'it-customcollapsible', 'it-customtoggle' ) );
mw.log( _fn + 'Found custom collapsible: #' + thatId );
// Double check that there is actually a customtoggle link
if ( $customTogglers.length ) {
$customTogglers.on( 'click.it-collapse', function( e ) {
toggleLinkCustom( $( this ), e, $that );
} );
} else {
mw.log( _fn + '#' + thatId + ': Missing toggler!' );
}
// Initial state
if ( $that.hasClass( 'it-collapsed' ) ) {
$that.removeClass( 'it-collapsed' );
toggleLinkCustom( $customTogglers, null, $that );
}
// If this is not a custom case, do the default:
// Wrap the contents add the toggle link
} else {
// Elements are treated differently
if ( $that.is( 'table' ) && $that.find( 'caption' ).length ) { // only table with caption
// The toggle-link will be in the caption
var $caption = $( 'caption', that ),
$toggle = $caption.find( '> .it-collapsible-toggle' );
// If theres no toggle link, add it to the caption
if ( !$toggle.length ) {
$caption.eq( -1 ).prepend( $toggleLink );
} else {
$toggleLink = $toggle.off( 'click.it-collapse' ).on( 'click.it-collapse', function( e ) {
toggleLinkPremade( $toggle, e );
} );
}
} else if ( !$that.is( 'ul' ) && !$that.is( 'ol' ) && !$that.is( 'table' ) ) {
// <div>, <p> etc.but not ol ul and not tables without caption
// The toggle-link will be the first child of the element
var $toggle = $that.find( '> .it-collapsible-toggle' );
// If a direct child .content-wrapper does not exists, create it
if ( !$that.find( '> .it-collapsible-content' ).length ) {
$that.wrapInner( '<div class="it-collapsible-content"></div>' );
}
// If theres no toggle link, add it
if ( !$toggle.length ) {
$that.prepend( $toggleLink );
} else {
$toggleLink = $toggle.off( 'click.it-collapse' ).on( 'click.it-collapse', function( e ) {
toggleLinkPremade( $toggle, e );
} );
}
}
}
// Initial state (only for those that are not custom)
if ( $that.hasClass( 'it-collapsed' ) && ( $that.attr( 'id' ) || '' ).indexOf( 'it-customcollapsible-' ) !== 0 ) {
$that.removeClass( 'it-collapsed' );
// The collapsible element could have multiple togglers
// To toggle the initial state only click one of them (ie. the first one, eq(0))
// Else it would go like: hide, show, hide, show for each toggle link.
toggleElement( $that, 'collapse', $toggleLink.eq( 0 ), /* instantHide = */ true );
$toggleLink.eq( 0 ).click();
}
} );
};
var newAutoCollapse = function( $ ) {
// autocollaspe for "palettes"
var $navboxnew = $( '#content .navboxnew' );
if ( $navboxnew.length === 1 ) {
$navboxnew.filter( '.it-collapsed' ).not( '.uncollapsed, .collapsed' ).each( function() {
$( this ).find( 'span.it-collapsible-toggle a' ).first().click();
} );
}
};
var newCollapsibleKeyboard = function( $ ) {
$( '.it-collapsible-toggle, .it-collapsible-toggle-keyboard' ).attr( 'tabindex', 0 ).keypress( function( event ) {
if ( event.which == 13 ) {
$( this ).click()
}
} );
};
var newCollapsibleGroup = function( $ ) {
$( '.it-collapsible-group' ).each( function() {
var $that = $( this );
var text = expandtextAll;
var $tooglelink = $( '<a class="it-collapsible-toggle it-collapsible-toggle-collapsed it-collapsible-group-toogle-all" href="#">' + collapsetextAll + '</a>' );
$that.find( '.it-collapsible-group-toogle:first' ).append( $tooglelink ).click( function( event ) {
if( text === expandtextAll ) {
text = collapsetextAll;
$that.find( '.it-collapsible-toggle-collapsed:not(".it-collapsible-group-toogle-all")' ).click();
} else {
text = expandtextAll;
$that.find( '.it-collapsible-toggle-expanded:not(".it-collapsible-group-toogle-all")' ).click();
}
$tooglelink.text( text );
// Toggles collapsible and togglelink class and updates text label and group icon
$tooglelink.toggleClass( 'it-collapsible-toggle-collapsed' );
return false;
} );
} );
};
var newBeKindToIE = function( $ ) {
var ieVersion = $.client.profile().versionBase;
// gestion des listes horizontalisées
// remove bullet from last list items in IE 8 7 6
if ( ieVersion < 9 ) {
$( '#content .navboxnew_inline' ).find( 'li:last-child' ).addClass( 'navboxnew_last' );
}
// navbox for IE < 8
if ( ieVersion < 8 ) {
$( '#content .navboxnew' ).removeClass( 'navboxnew' ).addClass( 'navboxnew_oldie' );
}
};
if ( $.client.profile().name == 'msie' ) {
$( document ).ready( newBeKindToIE );
}
$( document ).ready( newCollapsible );
$( document ).ready( newAutoCollapse );
$( document ).ready( newCollapsibleKeyboard );
$( document ).ready( newCollapsibleGroup );
// Codice JavaScript: ...fine </nowiki>