/** Collapsible tables ******************************************************* Dynamic Navigation Bars. See [[Wikipedia:NavFrame]] * * Based on script from en.wikipedia.org, 2008-09-15.
*
* @source www.mediawiki.org/wiki/MediaWikiFrom English Wikipedia, 2008-09-15 * * Description:Gadget-NavFrameAllows tables to be collapsed, showing only the header.jsSee * @maintainer Helder [[Wikipedia:NavFrame]].wiki, 2012–2013 * @maintainer Krinkle, 2013 Maintainers: [[User:R. Koot]]
*/
( function () { // Set up the words in your languagevar autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';
function collapseTable( tableIndex ){ var navigationBarHide 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 navigationBarShow Header = HeaderRow.getElementsByTagName( 'th' )[0]; if( !Header ) continue; NavigationBoxes[tableIndex] = Tables[i]; Tables[i].setAttribute( 'id', 'collapsibleTable' + expandCaption 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 ); /** Dynamic Navigation Bars (experimental) ************************************* * * Shows and hides content and picture (if available) of navigation bars.From English Wikipedia, 2008-09-15
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled Description: See [[Wikipedia:NavFrame]]. * @param {jQuery.Event} e Event object Maintainers: UNMAINTAINED
*/
// set up the words in your languagevar NavigationBarHide = '[' + collapseCaption + ']';var NavigationBarShow = '[' + expandCaption + ']'; // shows and hides content and picture (if available) of navigation bars// Parameters:// indexNavigationBar: the index of navigation bar to be toggledfunction toggleNavigationBar( indexNavigationBar, e ) { var navChild, navToggle NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar ),; navFrame var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar ); // Prevent browser from jumping to href "#" e.preventDefault();
if ( !navFrame NavFrame || !navToggle NavToggle ) {
return false;
}
// If if shown now if ( navToggleNavToggle.firstChild.data == navigationBarHide NavigationBarHide ) { for ( navChild var NavChild = navFrameNavFrame.firstChild; navChild NavChild != null; navChild NavChild = navChildNavChild.nextSibling ) { if ( hasClass( navChildNavChild, 'NavPic' ) ) { navChildNavChild.style.display = 'none';
}
if ( hasClass( navChildNavChild, 'NavContent' ) ) { navChildNavChild.style.display = 'none';
}
}
navToggle NavToggle.firstChild.data = navigationBarShowNavigationBarShow;
// If if hidden now } else if ( navToggleNavToggle.firstChild.data == navigationBarShow NavigationBarShow) { for ( navChild var NavChild = navFrameNavFrame.firstChild; navChild NavChild != null; navChild NavChild = navChildNavChild.nextSibling ) { if ( $( navChild ).hasClass( NavChild, 'NavPic' ) || $( navChild ){ NavChild.style.display = 'block'; } if( hasClass( NavChild, 'NavContent' ) ) { navChildNavChild.style.display = 'block';
}
}
navToggleNavToggle.firstChild.data = navigationBarHideNavigationBarHide;
}
}
/** * Adds / adds show/hide-button to navigation bars. *function createNavigationBarToggleButton(){ * @param {jQuery} $content var indexNavigationBar = 0; * //iterate over all < div >-elementsfunction createNavigationBarToggleButton var divs = document.getElementsByTagName( $content 'div') {; for( var i= 0; NavFrame = divs[i]; i++ ) { // if found a navigation bar if( hasClass( NavFrame, j, navFrame, navToggle, navToggleText, navChild,'NavFrame' ) ) { indexNavigationBar ++; var NavToggle = 0,document.createElement("a"); navFrames NavToggle.className = $content'NavToggle'; NavToggle.findsetAttribute( 'div.NavFrameid', 'NavToggle' + indexNavigationBar); NavToggle.toArraysetAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
// Iterate over all (new) nav frames for ( i = 0; i < navFrames.length; i++ ) { navFrame = navFrames[i]; // If found a navigation bar indexNavigationBar++; navToggle = document.createElement( 'a' ); navToggle.className = 'NavToggle'; navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); navToggle.setAttribute( 'href', '#' ); $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) ); navToggleText var NavToggleText = document.createTextNode( navigationBarHide NavigationBarHide); for ( navChild var NavChild = navFrameNavFrame.firstChild; navChild NavChild != null; navChild NavChild = navChildNavChild.nextSibling ) { if ( $( navChild ).hasClass( NavChild, 'NavPic' ) || $( navChild ).hasClass( NavChild, 'NavContent' ) ) { if ( navChildNavChild.style.display == 'none' ) { navToggleText NavToggleText = document.createTextNode( navigationBarShow NavigationBarShow); break; }
}
}
}
navToggle NavToggle.appendChild( navToggleText NavToggleText); // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) for ( var j = 0; j < navFrameNavFrame.childNodes.length; j++ ) { if ( $hasClass( navFrameNavFrame.childNodes[j] ).hasClass( , 'NavHead' ) ) { navFrame NavFrame.childNodes[j].appendChild( navToggle NavToggle); }
}
NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
}
navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
} mw.hook( 'wikipage.content' ).addaddOnloadHook( createNavigationBarToggleButton ); }());