Line 107: |
Line 107: |
| * http://www.mediawiki.org/wiki/Manual:Collapsible_tables. | | * http://www.mediawiki.org/wiki/Manual:Collapsible_tables. |
| * Maintainers: [[**MAINTAINERS**]] | | * Maintainers: [[**MAINTAINERS**]] |
| + | * added 07 Nov 2009 by [[User:FGrose]] from above source, replacing old code |
| */ | | */ |
| var autoCollapse = 2; | | var autoCollapse = 2; |
Line 193: |
Line 194: |
| })(); | | })(); |
| | | |
− | /** Dynamic Navigation Bars (experimental) *************************************
| + | /** Dynamic Navigation Bars (experimental) ************************************* |
− | *
| + | * |
− | * Description: See [[Wikipedia:NavFrame]].
| + | * Description: See [[Wikipedia:NavFrame]]. |
− | * Maintainers: UNMAINTAINED
| + | * Maintainers: UNMAINTAINED |
− | */
| + | * |
| + | * Added by [[User:FGrose]] on 07 Nov 2009 from Wikipedia:MediaWiki:Common.js |
| + | */ |
| | | |
− | // set up the words in your language
| + | // set up the words in your language |
− | var NavigationBarHide = '[' + collapseCaption + ']';
| + | var NavigationBarHide = '[' + collapseCaption + ']'; |
− | var NavigationBarShow = '[' + expandCaption + ']';
| + | var NavigationBarShow = '[' + expandCaption + ']'; |
| | | |
− | // shows and hides content and picture (if available) of navigation bars
| + | // shows and hides content and picture (if available) of navigation bars |
− | // Parameters:
| + | // Parameters: |
− | // indexNavigationBar: the index of navigation bar to be toggled
| + | // indexNavigationBar: the index of navigation bar to be toggled |
− | function toggleNavigationBar(indexNavigationBar)
| + | function toggleNavigationBar(indexNavigationBar) |
− | {
| + | { |
− | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
| + | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); |
− | var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
| + | var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); |
| | | |
− | if (!NavFrame || !NavToggle) {
| + | if (!NavFrame || !NavToggle) { |
− | return false;
| + | return false; |
− | }
| + | } |
| | | |
− | // if shown now
| + | // if shown now |
− | if (NavToggle.firstChild.data == NavigationBarHide) {
| + | if (NavToggle.firstChild.data == NavigationBarHide) { |
− | for (
| + | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { |
− | var NavChild = NavFrame.firstChild;
| + | if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) { |
− | NavChild != null;
| + | NavChild.style.display = 'none'; |
− | NavChild = NavChild.nextSibling
| + | } |
− | ) {
| + | } |
− | if ( hasClass( NavChild, 'NavPic' ) ) {
| + | NavToggle.firstChild.data = NavigationBarShow; |
− | NavChild.style.display = 'none';
| |
− | }
| |
− | if ( hasClass( NavChild, 'NavContent') ) {
| |
− | NavChild.style.display = 'none';
| |
− | }
| |
− | }
| |
− | NavToggle.firstChild.data = NavigationBarShow;
| |
| | | |
− | // if hidden now
| + | // if hidden now |
− | } else if (NavToggle.firstChild.data == NavigationBarShow) {
| + | } else if (NavToggle.firstChild.data == NavigationBarShow) { |
− | for (
| + | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { |
− | var NavChild = NavFrame.firstChild;
| + | if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) { |
− | NavChild != null;
| + | NavChild.style.display = 'block'; |
− | NavChild = NavChild.nextSibling
| + | } |
− | ) {
| + | } |
− | if (hasClass(NavChild, 'NavPic')) {
| + | NavToggle.firstChild.data = NavigationBarHide; |
− | NavChild.style.display = 'block';
| + | } |
− | }
| + | } |
− | if (hasClass(NavChild, 'NavContent')) {
| |
− | NavChild.style.display = 'block';
| |
− | }
| |
− | }
| |
− | NavToggle.firstChild.data = NavigationBarHide;
| |
− | }
| |
− | }
| |
| | | |
− | // adds show/hide-button to navigation bars
| + | // adds show/hide-button to navigation bars |
− | function createNavigationBarToggleButton()
| + | function createNavigationBarToggleButton() |
− | {
| + | { |
− | var indexNavigationBar = 0;
| + | var indexNavigationBar = 0; |
− | // iterate over all < div >-elements
| + | // iterate over all < div >-elements |
− | var divs = document.getElementsByTagName("div");
| + | var divs = document.getElementsByTagName("div"); |
− | for(
| + | for (var i = 0; NavFrame = divs[i]; i++) { |
− | var i=0;
| + | // if found a navigation bar |
− | NavFrame = divs[i];
| + | if (hasClass(NavFrame, "NavFrame")) { |
− | i++
| |
− | ) {
| |
− | // if found a navigation bar
| |
− | if (hasClass(NavFrame, "NavFrame")) {
| |
| | | |
− | indexNavigationBar++;
| + | indexNavigationBar++; |
− | var NavToggle = document.createElement("a");
| + | var NavToggle = document.createElement("a"); |
− | NavToggle.className = 'NavToggle';
| + | NavToggle.className = 'NavToggle'; |
− | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
| + | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); |
− | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
| + | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); |
| | | |
− | var NavToggleText = document.createTextNode(NavigationBarHide);
| + | var isCollapsed = hasClass( NavFrame, "collapsed" ); |
− | for ( | + | /* |
− | var NavChild = NavFrame.firstChild;
| + | * Check if any children are already hidden. This loop is here for backwards compatibility: |
− | NavChild != null;
| + | * the old way of making NavFrames start out collapsed was to manually add style="display:none" |
− | NavChild = NavChild.nextSibling
| + | * to all the NavPic/NavContent elements. Since this was bad for accessibility (no way to make |
− | ) {
| + | * the content visible without JavaScript support), the new recommended way is to add the class |
− | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
| + | * "collapsed" to the NavFrame itself, just like with collapsible tables. |
− | if (NavChild.style.display == 'none') {
| + | */ |
− | NavToggleText = document.createTextNode(NavigationBarShow);
| + | for (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) { |
− | break;
| + | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { |
− | }
| + | if ( NavChild.style.display == 'none' ) { |
− | }
| + | isCollapsed = true; |
− | }
| + | } |
| + | } |
| + | } |
| + | if (isCollapsed) { |
| + | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { |
| + | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { |
| + | NavChild.style.display = 'none'; |
| + | } |
| + | } |
| + | } |
| + | var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide); |
| + | NavToggle.appendChild(NavToggleText); |
| | | |
− | NavToggle.appendChild(NavToggleText);
| + | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked) |
− | // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
| + | for(var j=0; j < NavFrame.childNodes.length; j++) { |
− | for(
| + | if (hasClass(NavFrame.childNodes[j], "NavHead")) { |
− | var j=0;
| + | NavFrame.childNodes[j].appendChild(NavToggle); |
− | j < NavFrame.childNodes.length;
| + | } |
− | j++
| + | } |
− | ) {
| + | NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); |
− | if (hasClass(NavFrame.childNodes[j], "NavHead")) {
| + | } |
− | NavFrame.childNodes[j].appendChild(NavToggle);
| + | } |
− | }
| + | } |
− | }
| |
− | NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
| |
− | }
| |
− | }
| |
− | }
| |
| | | |
− | addOnloadHook( createNavigationBarToggleButton );
| + | addOnloadHook( createNavigationBarToggleButton ); |
| + | |
| | | |
| /** Main Page layout fixes ********************************************************* | | /** Main Page layout fixes ********************************************************* |