MediaWiki:Common.js: differenze tra le versioni

Da ScoutWiki, il wiki sullo scautismo.
Vai alla navigazione Vai alla ricerca
(+collapsible tables)
(Changing to the en version)
Riga 47: Riga 47:
/** Collapsible tables *********************************************************
/** Collapsible tables *********************************************************
  *
  *
*  Taken from http://en.wikipedia.org/wiki/MediaWiki:Common.js
  *  Description: Allows tables to be collapsed, showing only the header. See
  *  Description: Allows tables to be collapsed, showing only the header. See
  *              Wikipedia:NavFrame.
  *              [[Wikipedia:NavFrame]].
  *  Maintainers: User:R. Koot
  *  Maintainers: [[User:R. Koot]]
  * (Added to ScoutWiki.IT by [[:fi:User:ZeiP|ZeiP]] @ 28-08-2008 from IT-WP.
  * (Added to ScoutWiki.IT by [[:fi:User:ZeiP|ZeiP]] @ 28-08-2008 from EN-WP.)
  */
  */
   
   
var autoCollapse = 2;
var autoCollapse = 2;
var collapseCaption = "nascondi";
var collapseCaption = "hide";
var expandCaption = "espandi";
var expandCaption = "show";
   
   
function collapseTable( tableIndex )
function collapseTable( tableIndex )
Riga 67: Riga 66:
     }
     }
   
   
     var Rows = Table.getElementsByTagName( "tr" );  
     var Rows = Table.rows;
   
   
     if ( Button.firstChild.data == collapseCaption ) {
     if ( Button.firstChild.data == collapseCaption ) {
Riga 90: Riga 89:
     for ( var i = 0; i < Tables.length; i++ ) {
     for ( var i = 0; i < Tables.length; i++ ) {
         if ( hasClass( Tables[i], "collapsible" ) ) {
         if ( hasClass( Tables[i], "collapsible" ) ) {
            /* only add button and increment count if there is a header row to work with */
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
            if (!HeaderRow) continue;
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
            if (!Header) continue;
             NavigationBoxes[ tableIndex ] = Tables[i];
             NavigationBoxes[ tableIndex ] = Tables[i];
             Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
             Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
Riga 103: Riga 109:
             Button.style.width = "6em";
             Button.style.width = "6em";
   
   
            ButtonLink.style.color = Header.style.color;
             ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
             ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
             ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
             ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
Riga 111: Riga 118:
             Button.appendChild( document.createTextNode( "]" ) );
             Button.appendChild( document.createTextNode( "]" ) );
   
   
             var Header = Tables[i].getElementsByTagName( "tr" )[0].getElementsByTagName( "th" )[0];
             Header.insertBefore( Button, Header.childNodes[0] );
            /* only add button and increment count if there is a header row to work with */
            tableIndex++;
            if (Header) {
                Header.insertBefore( Button, Header.childNodes[0] );
                tableIndex++;
            }
         }
         }
     }
     }
Riga 128: Riga 131:
   
   
addOnloadHook( createCollapseButtons );
addOnloadHook( createCollapseButtons );
//END Collapsible tables

Versione delle 18:29, 28 ago 2008

/* <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 *********************************************************
 *
 *  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 EN-WP.)
 */
 
var autoCollapse = 2;
var collapseCaption = "hide";
var expandCaption = "show";
 
function collapseTable( tableIndex )
{
    var Button = document.getElementById( "collapseButton" + tableIndex );
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
 
    if ( !Table || !Button ) {
        return false;
    }
 
    var Rows = Table.rows;
 
    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" ) ) {
 
            /* only add button and increment count if there is a header row to work with */
            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.style.styleFloat = "right";
            Button.style.cssFloat = "right";
            Button.style.fontWeight = "normal";
            Button.style.textAlign = "right";
            Button.style.width = "6em";
 
            ButtonLink.style.color = Header.style.color;
            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( "]" ) );
 
            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 );