Jump to content

MediaWiki:Common.js: Difference between revisions

Jehan (talk | contribs)
No edit summary
Jehan (talk | contribs)
No edit summary
 
(21 intermediate revisions by the same user not shown)
Line 17: Line 17:
     var Button = document.getElementById( 'hideButton' + tableIndex );
     var Button = document.getElementById( 'hideButton' + tableIndex );
     var showTable = document.getElementById( 'hideableTable' + tableIndex );
     var showTable = document.getElementById( 'hideableTable' + tableIndex );
    var hideTables = document.getElementsByClassName( 'hideable' );
var Tables = document.getElementsByTagName( 'table' );  
var i;
     if ( !showTable || !Button ) {
      
if ( !showTable || !Button ) {
         return false;
         return false;
     }
     }
   
   
/* hide shown tables */
/* hide shown tables */
var j;
    for ( i = 0; i < Tables.length; i++ ) {
for ( j = 0; j < hideTables.length; j++ ) hideTables[j].style.display = 'none';
        if ( $( Tables[i] ).hasClass( 'hideable' ) ) {
Tables[i].style.display = 'none';
Tables[i].className = "wikitable hideable hidden";
}
}
showTable.style.display = '';
showTable.style.display = '';
showTable.className = "wikitable hideable hidden shown";
showTable.className = "wikitable hideable hidden shown";
 
};
};


Line 34: Line 40:
     var NavigationBoxes = {};
     var NavigationBoxes = {};
     var Tables = document.getElementsByTagName( 'table' );
     var Tables = document.getElementsByTagName( 'table' );
var linkTable = document.getElementById( 'linkTable');
if ( linkTable ) var linkRows = linkTable.getElementsByTagName( 'tr' );
     var i, j;
     var i, j;
    var linkImages = document.getElementsByClassName("hideImage");
     function handleButtonLink( index, e ) {
     function handleButtonLink( index, e ) {
Line 41: Line 48:
         e.preventDefault();
         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++ );
}
}
j = 0;
tableIndex = 0;
    for ( i = 0; i < Tables.length; i++ ) {
j=0;
        if ( $( Tables[i] ).hasClass( 'hideable' ) ) {
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];
/* only add button and increment count if there is a header row to work with */
            if ( !HeaderRow ) continue;
var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0];
            var Header = HeaderRow.getElementsByTagName( 'th' )[0];
if ( !HeaderRow ) continue;
var linkImage = document.getElementsByClassName("hideImage")[j++];
var Header = HeaderRow.getElementsByTagName( 'th' )[0];
            if ( !Header ) continue;
var linkImage = document.getElementById( 'hideImage' + j++ );;
if ( !Header ) continue;
            NavigationBoxes[ tableIndex ] = Tables[i];
            Tables[i].setAttribute( 'id', 'hideableTable' + tableIndex );
NavigationBoxes[ tableIndex ] = Tables[i];
Tables[i].setAttribute( 'id', 'hideableTable' + tableIndex );
            var Button    = document.createElement( 'span' );
            var ButtonLink = document.createElement( 'a' );
if ( 0 ) {
            var ButtonText = document.createTextNode( expandCaption );
                                    $( linkImage ).on( 'click', $.proxy( handlelinkImage, linkImage , tableIndex ) );
                                }
            Button.className = 'hideButton';  /* Styles are declared in Common.css */
if ( 1 ) {
                                    var Button    = document.createElement( 'span' );
            ButtonLink.style.color = Header.style.color;
    var ButtonLink = document.createElement( 'a' );
            ButtonLink.setAttribute( 'id', 'hideButton' + tableIndex );
    var ButtonText = document.createTextNode( expandCaption );
            ButtonLink.setAttribute( 'href', '#' );
            $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
    Button.className = 'hideButton';  /* Styles are declared in Common.css */
            ButtonLink.appendChild( ButtonText );
    ButtonLink.style.color = Header.style.color;
            Button.appendChild( document.createTextNode( '[' ) );
    ButtonLink.setAttribute( 'id', 'hideButton' + tableIndex );
            Button.appendChild( ButtonLink );
    ButtonLink.setAttribute( 'href', '#' );
            Button.appendChild( document.createTextNode( ']' ) );
    $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) );
    ButtonLink.appendChild( ButtonText );
            Header.insertBefore( Button, Header.firstChild );
            if ( linkImage ) linkImage.appendChild( Button );
    Button.appendChild( document.createTextNode( '[' ) );
            if ( 0 ) linkImage.insertBefore( Button, linkImage.firstChild );
    Button.appendChild( ButtonLink );
tableIndex++;
    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 );
window.hideTable( 0 );
}
}
}
   
   
Line 154: 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( '[' ) );