MediaWiki:Common.js

Da ScoutWiki, il wiki sullo scautismo.
Versione del 28 ago 2008 alle 18:24 di ZeiP (discussione | contributi) (+collapsible tables)

Nota: dopo aver pubblicato, potrebbe essere necessario pulire la cache del proprio browser per vedere i cambiamenti.

  • Firefox / Safari: tieni premuto il tasto delle maiuscole Shift e fai clic su Ricarica, oppure premi Ctrl-F5 o Ctrl-R (⌘-R su Mac)
  • Google Chrome: premi Ctrl-Shift-R (⌘-Shift-R su un Mac)
  • Internet Explorer / Edge: tieni premuto il tasto Ctrl e fai clic su Aggiorna, oppure premi Ctrl-F5
  • Opera: premi Ctrl-F5.
/* <pre> */
/* Il codice JavaScript inserito qui viene caricato da ciascuna pagina, per tutti gli utenti. */

/*
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 = "x-small";
                        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> */

/** Collapsible tables *********************************************************
 *
 *  Taken from http://en.wikipedia.org/wiki/MediaWiki:Common.js
 *  Description: Allows tables to be collapsed, showing only the header. See
 *               Wikipedia:NavFrame.
 *  Maintainers: User:R. Koot
 * (Added to ScoutWiki.IT by [[:fi:User:ZeiP|ZeiP]] @ 28-08-2008 from IT-WP.
 */
 
var autoCollapse = 2;
var collapseCaption = "nascondi";
var expandCaption = "espandi";
 
function collapseTable( tableIndex )
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.getElementsByTagName( "tr" ); 
 
    if ( Button.firstChild.data == collapseCaption ) {
        for ( var i = 1; i < Rows.length; i++ ) {
            Rows[i].style.display = "none";
        }
        Button.firstChild.data = expandCaption;
    } else {
        for ( var 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 = new Object();
    var Tables = document.getElementsByTagName( "table" );
 
    for ( var i = 0; i < Tables.length; i++ ) {
        if ( hasClass( Tables[i], "collapsible" ) ) {
            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.style.styleFloat = "right";
            Button.style.cssFloat = "right";
            Button.style.fontWeight = "normal";
            Button.style.textAlign = "right";
            Button.style.width = "6em";
 
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
            ButtonLink.appendChild( ButtonText );
 
            Button.appendChild( document.createTextNode( "[" ) );
            Button.appendChild( ButtonLink );
            Button.appendChild( document.createTextNode( "]" ) );
 
            var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
            /* only add button and increment count if there is a header row to work with */
            if (Header) {
                Header.insertBefore( Button, Header.childNodes[0] );
                tableIndex++;
            }
        }
    }
 
    for ( var i = 0;  i < tableIndex; i++ ) {
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
            collapseTable( i );
        }
    }
}
 
addOnloadHook( createCollapseButtons );
 
//END Collapsible tables