Changes

Jump to navigation Jump to search
13 bytes removed ,  00:58, 7 November 2009
replace collapsible tables section
Line 102: Line 102:  
  addOnloadHook( LinkFA );
 
  addOnloadHook( LinkFA );
   −
/** Collapsible tables *********************************************************
+
/** Collapsible tables *********************************************************
  *
+
*
  *  Description: Allows tables to be collapsed, showing only the header. See
+
*  Description: Allows tables to be collapsed, showing only the header. See
  *              [[Wikipedia:NavFrame]].
+
*              http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
  *  Maintainers: [[User:R. Koot]]
+
*  Maintainers: [[**MAINTAINERS**]]
  */
+
*/
+
var autoCollapse = 2;
var autoCollapse = 2;
+
var collapseCaption = 'hide';
var collapseCaption = "hide";
+
var expandCaption = 'show';
var expandCaption = "show";
+
 
+
function collapseTable( tableIndex ) {
function collapseTable( tableIndex )
+
var Button = document.getElementById( 'collapseButton' + tableIndex );
{
+
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
    var Button = document.getElementById( "collapseButton" + tableIndex );
+
 
    var Table = document.getElementById( "collapsibleTable" + tableIndex );
+
if ( !Table || !Button ) {
+
return false;
    if ( !Table || !Button ) {
+
}
        return false;
+
 
    }
+
var Rows = Table.rows;
+
 
    var Rows = Table.rows;
+
if ( Button.firstChild.data == collapseCaption ) {
+
for ( var i = 1; i < Rows.length; i++ ) {
    if ( Button.firstChild.data == collapseCaption ) {
+
Rows[i].style.display = 'none';
        for ( var i = 1; i < Rows.length; i++ ) {
+
}
            Rows[i].style.display = "none";
+
Button.firstChild.data = expandCaption;
        }
+
} else {
        Button.firstChild.data = expandCaption;
+
for ( var i = 1; i < Rows.length; i++ ) {
    } else {
+
Rows[i].style.display = Rows[0].style.display;
        for ( var i = 1; i < Rows.length; i++ ) {
+
}
            Rows[i].style.display = Rows[0].style.display;
+
Button.firstChild.data = collapseCaption;
        }
+
}
        Button.firstChild.data = collapseCaption;
+
}
    }
+
 
}
+
function createCollapseButtons() {
+
var tableIndex = 0;
function createCollapseButtons()
+
var NavigationBoxes = new Object();
{
+
var Tables = document.getElementsByTagName( 'table' );
    var tableIndex = 0;
+
 
    var NavigationBoxes = new Object();
+
for ( var i = 0; i < Tables.length; i++ ) {
    var Tables = document.getElementsByTagName( "table" );
+
if ( hasClass( Tables[i], 'collapsible' ) ) {
+
/* only add button and increment count if there is a header row to work with */
    for ( var i = 0; i < Tables.length; i++ ) {
+
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
        if ( hasClass( Tables[i], "collapsible" ) ) {
+
if( !HeaderRow ) continue;
+
var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            /* only add button and increment count if there is a header row to work with */
+
if( !Header ) continue;
            var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0];
+
 
            if (!HeaderRow) continue;
+
NavigationBoxes[tableIndex] = Tables[i];
            var Header = HeaderRow.getElementsByTagName( "th" )[0];
+
Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
            if (!Header) continue;
+
 
+
var Button    = document.createElement( 'span' );
            NavigationBoxes[ tableIndex ] = Tables[i];
+
var ButtonLink = document.createElement( 'a' );
            Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex );
+
var ButtonText = document.createTextNode( collapseCaption );
+
 
            var Button    = document.createElement( "span" );
+
Button.className = 'collapseButton'; // Styles are declared in MediaWiki:Common.css
            var ButtonLink = document.createElement( "a" );
+
 
            var ButtonText = document.createTextNode( collapseCaption );
+
ButtonLink.style.color = Header.style.color;
+
ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
            Button.style.styleFloat = "right";
+
ButtonLink.setAttribute( 'href', "javascript:collapseTable(" + tableIndex + ");" );
            Button.style.cssFloat = "right";
+
ButtonLink.appendChild( ButtonText );
            Button.style.fontWeight = "normal";
+
 
            Button.style.textAlign = "right";
+
Button.appendChild( document.createTextNode( '[' ) );
            Button.style.width = "6em";
+
Button.appendChild( ButtonLink );
+
Button.appendChild( document.createTextNode( ']' ) );
            ButtonLink.style.color = Header.style.color;
+
 
            ButtonLink.setAttribute( "id", "collapseButton" + tableIndex );
+
Header.insertBefore( Button, Header.childNodes[0] );
            ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" );
+
tableIndex++;
            ButtonLink.appendChild( ButtonText );
+
}
+
}
            Button.appendChild( document.createTextNode( "[" ) );
+
 
            Button.appendChild( ButtonLink );
+
for ( var i = 0;  i < tableIndex; i++ ) {
            Button.appendChild( document.createTextNode( "]" ) );
+
if ( hasClass( NavigationBoxes[i], 'collapsed' ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], 'autocollapse' ) ) ) {
+
collapseTable( i );
            Header.insertBefore( Button, Header.childNodes[0] );
+
}
            tableIndex++;
+
}
        }
+
}
    }
+
 
+
addOnloadHook( createCollapseButtons );
    for ( var i = 0;  i < tableIndex; i++ ) {
+
 
        if ( hasClass( NavigationBoxes[i], "collapsed" ) || ( tableIndex >= autoCollapse && hasClass( NavigationBoxes[i], "autocollapse" ) ) ) {
+
/** Test if an element has a certain class **************************************
            collapseTable( i );
+
  *
        }
+
  * Description: Uses regular expressions and caching for better performance.
    }
+
  * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
  }
+
*/
   
+
 
  addOnloadHook( createCollapseButtons );
+
var hasClass = (function() {
 +
var reCache = {};
 +
return function( element, className ) {
 +
return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
 +
};
 +
})();
    
  /** Dynamic Navigation Bars (experimental) *************************************
 
  /** Dynamic Navigation Bars (experimental) *************************************

Navigation menu