Jump to content

MediaWiki:Common.js: Difference between revisions

Jehan (talk | contribs)
No edit summary
Jehan (talk | contribs)
No edit summary
 
(44 intermediate revisions by the same user not shown)
Line 2: Line 2:


/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Hideable tables *********************************************************
*
* Description: Allows tables to be hidden, showing nothing. See
*              [[Wikipedia:NavFrame]].
* Maintainers: [[User:Jesper Hanberg, DTU Danchip]]
*/
var autoHide = 2;
var hideCaption = 'hide';
var expandCaption = 'show';
window.hideTable = function ( tableIndex ) {
    var Button = document.getElementById( 'hideButton' + tableIndex );
    var showTable = document.getElementById( 'hideableTable' + tableIndex );
var Tables = document.getElementsByTagName( 'table' );
var i;
   
if ( !showTable || !Button ) {
        return false;
    }
/* hide shown tables */
    for ( i = 0; i < Tables.length; i++ ) {
        if ( $( Tables[i] ).hasClass( 'hideable' ) ) {
Tables[i].style.display = 'none';
Tables[i].className = "wikitable hideable hidden";
}
}
showTable.style.display = '';
showTable.className = "wikitable hideable hidden shown";
};
function createHideButtons() {
    var tableIndex = 0;
    var NavigationBoxes = {};
    var Tables = document.getElementsByTagName( 'table' );
var linkTable = document.getElementById( 'linkTable');
if ( linkTable ) var linkRows = linkTable.getElementsByTagName( 'tr' );
    var i, j;
    function handleButtonLink( index, e ) {
        window.hideTable( index );
        e.preventDefault();
    }
    if ( linkRows ) {
for ( i = 0; i < linkRows.length; i++ ) {
var linkRow = linkRows[i];
if ( !linkRow ) continue;
var linkCells = linkRow.getElementsByTagName( 'th' );
if ( !linkCells ) continue;
for ( j = 0; j < linkCells.length; j++ ) {
var linkCell = linkCells[j];
if ( !linkCell ) continue;
if ( $( linkCell ).hasClass( 'hideImage' ) )            /* add id attribute */
linkCell.setAttribute( 'id', 'hideImage' + tableIndex++ );
}
}
tableIndex = 0;
j=0;
for ( i = 0; i < Tables.length; i++ ) {
if ( $( Tables[i] ).hasClass( 'hideable' ) ) {
/* 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];
var linkImage = document.getElementById( 'hideImage' + j++ );;
if ( !Header ) continue;
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( 'id', 'hideableTable' + tableIndex );
if ( 0 ) {
                                    $( linkImage ).on( 'click', $.proxy( handlelinkImage, linkImage , tableIndex ) );
                                }
if ( 1 ) {
                                    var Button    = document.createElement( 'span' );
    var ButtonLink = document.createElement( 'a' );
    var ButtonText = document.createTextNode( expandCaption );
    Button.className = 'hideButton';  /* Styles are declared in Common.css */
    ButtonLink.style.color = Header.style.color;
    ButtonLink.setAttribute( 'id', 'hideButton' + 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 );
    if ( linkImage ) linkImage.appendChild( Button );
    if ( 0 ) linkImage.insertBefore( Button, linkImage.firstChild );
                                }
tableIndex++;
}
}
window.hideTable( 0 );
}
}
$( createHideButtons );


/**
/**
Line 72: Line 181:
             ButtonLink.setAttribute( 'href', '#' );
             ButtonLink.setAttribute( 'href', '#' );
             $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
             $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
            ButtonLink.appendChild( ButtonText );
 
    ButtonLink.appendChild( ButtonText );
   
   
             Button.appendChild( document.createTextNode( '[' ) );
             Button.appendChild( document.createTextNode( '[' ) );
Line 78: Line 188:
             Button.appendChild( document.createTextNode( ']' ) );
             Button.appendChild( document.createTextNode( ']' ) );
   
   
             Header.insertBefore( Button, Header.firstChild );
             Header.insertBefore( Button, Header.lastChild );
             tableIndex++;
             tableIndex++;
         }
         }