Line 173: |
Line 173: |
| }; | | }; |
| } | | } |
| + | function createCollapseButtons() |
| + | { |
| + | var tableIndex = 0; |
| + | var NavigationBoxes = new Object(); |
| + | var Tables = getElementsByClassName(document, "table", "collapsible"); |
| | | |
− | function createCollapseButtons() {
| + | for ( var i = 0; i < Tables.length; i++ ) { |
− | var tableIndex = 0;
| + | /* only add button and increment count if there is a header row to work with */ |
− | var NavigationBoxes = {};
| + | var HeaderRow = Tables[i].getElementsByTagName( "tr" )[0]; |
− | var Tables = document.getElementsByTagName( 'table' );
| + | if (!HeaderRow) continue; |
− | var i;
| + | var Header = HeaderRow.getElementsByTagName( "th" )[0]; |
| + | if (!Header) continue; |
| | | |
− | for ( i = 0; i < Tables.length; i++ ) {
| + | NavigationBoxes[ tableIndex ] = Tables[i]; |
− | if ( $( Tables[i] ).hasClass( 'collapsible' ) ) {
| + | Tables[i].setAttribute( "id", "collapsibleTable" + tableIndex ); |
− | /* 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];
| + | var Button = document.createElement( "span" ); |
− | Tables[i].setAttribute( 'id', 'collapsibleTable' + tableIndex );
| + | var ButtonLink = document.createElement( "a" ); |
| + | var ButtonText = document.createTextNode( collapseCaption ); |
| | | |
− | var Button = document.createElement( 'span' );
| + | Button.className = "collapseButton"; //Styles are declared in Common.css |
− | var ButtonLink = document.createElement( 'a' );
| |
− | var ButtonText = document.createTextNode( collapseCaption );
| |
− | // TODO: Declare styles in [[MediaWiki:Gadget-collapsibleTables.css]]
| |
− | // Button.className = 'collapseButton';
| |
− | 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.style.color = Header.style.color; |
− | ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex );
| + | ButtonLink.setAttribute( "id", "collapseButton" + tableIndex ); |
− | ButtonLink.setAttribute( 'href', '#' );
| + | ButtonLink.setAttribute( "href", "javascript:collapseTable(" + tableIndex + ");" ); |
− | $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) );
| + | ButtonLink.appendChild( ButtonText ); |
− | ButtonLink.appendChild( ButtonText );
| |
| | | |
− | Button.appendChild( document.createTextNode( '[' ) );
| + | Button.appendChild( document.createTextNode( "[" ) ); |
− | Button.appendChild( ButtonLink );
| + | Button.appendChild( ButtonLink ); |
− | Button.appendChild( document.createTextNode( ']' ) );
| + | Button.appendChild( document.createTextNode( "]" ) ); |
| | | |
− | Header.insertBefore( Button, Header.firstChild );
| + | Header.insertBefore( Button, Header.childNodes[0] ); |
− | tableIndex++;
| + | tableIndex++; |
− | }
| + | } |
− | }
| |
| | | |
− | for ( i = 0; i < tableIndex; i++ ) {
| + | var Tables = getElementsByClassName(document, "table", "collapsed"); |
− | if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) ||
| + | for ( var i = 0; i < Tables.length; i++ ) { |
− | ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) )
| + | collapseTable( i ); |
− | ) {
| + | } |
− | collapseTable( i );
| + | |
− | }
| + | var Tables = getElementsByClassName(document, "table", "autocollapse"); |
− | }
| + | for ( var i = 0; i < Tables.length; i++ ) { |
| + | if ( i >= autoCollapse ) { |
| + | collapseTable( i ); |
| + | } |
| + | } |
| } | | } |
| | | |