|
|
Zeile 1: |
Zeile 1: |
| // see [[:en:MediaWiki:Navigation.js]] and/or [[w:en:MediaWiki:Common.js]] | | /* Any JavaScript here will be loaded for all users on every page load. */ |
|
| |
|
| // BEGIN Collapsible tables | | /** |
| // Description: Allows tables to be collapsed, showing only the header.
| | * Collapsible tables |
| // See Wikipedia:NavFrame.
| | * |
| // Maintainers: User:R. Koot
| | * Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]]. |
| | * @maintainer [[User:R. Koot]] (on Wikipedia) |
| | */ |
|
| |
|
| var autoCollapse = 2; | | var autoCollapse = 1; |
| // set up the words in your language
| | var collapseCaption = 'Einklappen'; |
| var collapseCaption = 'hide'; | | var expandCaption = 'Ausklappen'; |
| var expandCaption = 'show'; | |
|
| |
|
| if( mw.config.get( 'wgUserLanguage') == 'de' ) {
| | function hasClass( element, className ) { |
| collapseCaption = 'Einklappen'; | | var Classes = element.className.split( " " ); |
| expandCaption = 'Aufklappen'; | | for ( var i = 0; i < Classes.length; i++ ) { |
| | if ( Classes[i] == className ) { |
| | return true; |
| | } |
| | } |
| | return false; |
| } | | } |
|
| |
|
| function collapseTable( tableIndex ) { | | function collapseTable( tableIndex ) { |
| | var i; |
| var Button = document.getElementById( 'collapseButton' + tableIndex ); | | var Button = document.getElementById( 'collapseButton' + tableIndex ); |
| var Table = document.getElementById( 'collapsibleTable' + tableIndex ); | | var Table = document.getElementById( 'collapsibleTable' + tableIndex ); |
Zeile 27: |
Zeile 34: |
|
| |
|
| if ( Button.firstChild.data == collapseCaption ) { | | if ( Button.firstChild.data == collapseCaption ) { |
| for ( var i = 1; i < Rows.length; i++ ) { | | for ( i = 1; i < Rows.length; i++ ) { |
| Rows[i].style.display = 'none'; | | Rows[i].style.display = 'none'; |
| } | | } |
| Button.firstChild.data = expandCaption; | | Button.firstChild.data = expandCaption; |
| } else { | | } else { |
| for ( var i = 1; i < Rows.length; i++ ) { | | for ( i = 1; i < Rows.length; i++ ) { |
| Rows[i].style.display = Rows[0].style.display; | | Rows[i].style.display = Rows[0].style.display; |
| } | | } |
Zeile 38: |
Zeile 45: |
| } | | } |
| } | | } |
|
| |
| function createCollapseButtons() {
| |
| var tableIndex = 0;
| |
| var NavigationBoxes = new Object();
| |
| var Tables = document.getElementsByTagName( 'table' );
| |
|
| |
| for ( var i = 0; i < Tables.length; i++ ) {
| |
| if ( $(Tables[i]).hasClass('collapsible' ) ) {
| |
| NavigationBoxes[tableIndex] = Tables[i];
| |
| Tables[i].setAttribute( 'id', 'collapsibleTable' + 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.setAttribute( 'id', 'collapseButton' + tableIndex );
| |
| ButtonLink.setAttribute( 'href', 'javascript:collapseTable(' + tableIndex + ');' );
| |
| ButtonLink.appendChild( ButtonText );
| |
|
| |
| Button.appendChild( document.createTextNode( '[' ) );
| |
| Button.appendChild( ButtonLink );
| |
| Button.appendChild( document.createTextNode( ']' ) );
| |
|
| |
| var Header = Tables[i].getElementsByTagName( 'tr' )[0].getElementsByTagName( 'th' )[0];
| |
| /* only add button and increment count if there is a header row to work with */
| |
| if ( Header ) {
| |
| Header.insertBefore( Button, Header.childNodes[0] );
| |
| tableIndex++;
| |
| }
| |
| }
| |
| }
| |
|
| |
| for ( var i = 0; i < tableIndex; i++ ) {
| |
| if (
| |
| $(NavigationBoxes[i]).hasClass('collapsed' ) ||
| |
| ( tableIndex >= autoCollapse && $(NavigationBoxes[i]).hasClass('autocollapse' ) )
| |
| )
| |
| {
| |
| collapseTable( i );
| |
| }
| |
| }
| |
| }
| |
|
| |
| $(document).ready( createCollapseButtons );
| |
|
| |
| // Dynamic Navigation Bars
| |
|
| |
| // set up the words in your language
| |
| var NavigationBarHide = 'Collapse';
| |
| var NavigationBarShow = 'Expand';
| |
|
| |
| if( mw.config.get( 'wgUserLanguage') == 'de' ) {
| |
| NavigationBarHide = 'Einklappen';
| |
| NavigationBarShow = 'Aufklappen';
| |
| }
| |
|
| |
| // shows and hides content and picture (if available) of navigation bars
| |
| function toggleNavigationBar( e ) {
| |
| e = e || window.event;
| |
| var NavToggle = e.target || e.srcElement;
| |
| var NavFrame = NavToggle.parentNode.parentNode;
| |
|
| |
| if ( NavToggle.firstChild.data == NavigationBarHide ) {
| |
| for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| |
| if ( $(NavChild).hasClass('NavContent' ) || $(NavChild).hasClass('NavPic' ) ) {
| |
| NavChild.style.display = 'none';
| |
| }
| |
| }
| |
| NavToggle.firstChild.data = NavigationBarShow;
| |
| } else if ( NavToggle.firstChild.data == NavigationBarShow ) {
| |
| for ( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
| |
| if ( $(NavChild).hasClass('NavContent' ) || $(NavChild).hasClass('NavPic' ) ) {
| |
| NavChild.style.display = 'block';
| |
| }
| |
| }
| |
| NavToggle.firstChild.data = NavigationBarHide;
| |
| }
| |
| }
| |
|
| |
| // adds show/hide-button to navigation bars
| |
| function createNavigationBarToggleButton() {
| |
| // iterate over all <div> elements
| |
| var NavFrame = document.getElementsByTagName( 'div' );
| |
|
| |
| for ( var i = 0; i < NavFrame.length; i++ ) {
| |
| if ( $(NavFrame[i]).hasClass('NavFrame' ) ) {
| |
| var NavToggle = document.createElement( 'a' );
| |
| var NavToggleText = document.createTextNode(
| |
| $(NavFrame[i]).hasClass('selected' ) ? NavigationBarShow : NavigationBarHide
| |
| );
| |
|
| |
| NavToggle.className = 'NavToggle';
| |
| NavToggle.onclick = toggleNavigationBar;
| |
| NavToggle.appendChild( NavToggleText );
| |
|
| |
| // add NavToggle-Button as element in <div class="NavFrame">
| |
| for ( var j = 0; j < NavFrame[i].childNodes.length; j++ ) {
| |
| if ( $(NavFrame[i].childNodes[j]).hasClass('NavHead' ) ) {
| |
| NavFrame[i].childNodes[j].appendChild( NavToggle );
| |
| }
| |
| }
| |
|
| |
| if ( document.createEvent ) { // DOM 2 and DOM 3 compliant browsers
| |
| var e = document.createEvent( 'MouseEvents' );
| |
| e.initMouseEvent(
| |
| 'click', true, true, window, 0, 0, 0, 0, 0, false, false,
| |
| false, false, 0, null
| |
| );
| |
| NavToggle.dispatchEvent( e );
| |
| } else if ( NavToggle.fireEvent ) { // IE
| |
| NavToggle.fireEvent( 'onclick' );
| |
| }
| |
| }
| |
| }
| |
| }
| |
|
| |
| $(document).ready( createNavigationBarToggleButton );
| |
/* Any JavaScript here will be loaded for all users on every page load. */
/**
* Collapsible tables
*
* Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]].
* @maintainer [[User:R. Koot]] (on Wikipedia)
*/
var autoCollapse = 1;
var collapseCaption = 'Einklappen';
var expandCaption = 'Ausklappen';
function hasClass( element, className ) {
var Classes = element.className.split( " " );
for ( var i = 0; i < Classes.length; i++ ) {
if ( Classes[i] == className ) {
return true;
}
}
return false;
}
function collapseTable( tableIndex ) {
var i;
var Button = document.getElementById( 'collapseButton' + tableIndex );
var Table = document.getElementById( 'collapsibleTable' + tableIndex );
if ( !Table || !Button ) {
return false;
}
var Rows = Table.getElementsByTagName( 'tr' );
if ( Button.firstChild.data == collapseCaption ) {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = 'none';
}
Button.firstChild.data = expandCaption;
} else {
for ( i = 1; i < Rows.length; i++ ) {
Rows[i].style.display = Rows[0].style.display;
}
Button.firstChild.data = collapseCaption;
}
}