Changes

Jump to: navigation, search

MediaWiki:Common.js

1,872 bytes added, 22:12, 20 June 2016
Navbar/navbox code
/* Any JavaScript here will be loaded for all users on every page load. */
 
/**
* Collapsible tablesKeep code in MediaWiki:Common.js to a minimum as it is unconditionally * loaded for all users on every wiki page. If possible create a gadget that is * enabled by default instead of adding it here (since gadgets are fully * optimized ResourceLoader modules with possibility to add dependencies etc.)
*
* Allows tables Since Common.js isn't a gadget, there is no place to declare its * dependencies, so we have to lazy load them with mw.loader.using on demand and * then execute the rest in the callback. In most cases these dependencies will * be loaded (or loading) already and the callback will not be collapseddelayed. In case a * dependency hasn't arrived yet it'll make sure those are loaded before this. */ /* global mw, $ *//* jshint strict:false, showing only the headerbrowser:true */ mw.loader. See using( [[Wikipedia:NavFrame]'mediawiki.util', 'mediawiki.notify', 'jquery.client']).done( function () { /* Begin of mw.loader.using callback */ /** * Dynamic Navigation Bars (experimental)
*
* @version 2.0.3 (2014-03-14) * @source https://www.mediawiki.org/wiki/MediaWikiDescription:Gadget-collapsibleTables.js * @author See [[UserWikipedia:R. KootNavFrame]]. * @author [[UserMaintainers:Krinkle]] * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which * is supported in MediaWiki core.UNMAINTAINED
*/
/* set up the words in your language */var autoCollapse NavigationBarHide = 2'[' + collapseCaption + ']';var collapseCaption NavigationBarShow = 'hide[';var + expandCaption = + 'show]';var tableIndex indexNavigationBar = 0;
/** * Shows and hides content and picture (if available) of navigation bars * Parameters: * indexNavigationBar: the index of navigation bar to be toggled **/window.toggleNavigationBar = function collapseTable( tableIndex indexNavigationBar, event ) { var Button NavToggle = document.getElementById( 'collapseButtonNavToggle' + tableIndex indexNavigationBar ); var Table NavFrame = document.getElementById( 'collapsibleTableNavFrame' + tableIndex indexNavigationBar ); var NavChild;
if ( !Table NavFrame || !Button NavToggle ) {
return false;
}
var Rows /* if shown now */ if ( NavToggle.firstChild.data = Table== NavigationBarHide ) { for ( NavChild = NavFrame.rowsfirstChild; NavChild != null;NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) { NavChild.style.display = 'none'; } } var iNavToggle.firstChild.data = NavigationBarShow;
/* if hidden now */ } else if ( ButtonNavToggle.firstChild.data === collapseCaption NavigationBarShow ) { for ( i NavChild = 1NavFrame.firstChild; i < RowsNavChild != null; NavChild = NavChild.length; i++ nextSibling ) { Rows[i]if ( $( NavChild ).style.display = hasClass( 'noneNavContent'; } Button) || $( NavChild ).firstChild.data = expandCaption; } else { for hasClass( i = 1; i < Rows.length; i++ 'NavPic' ) ) { Rows[i] NavChild.style.display = Rows[0].style.display'block'; }
}
ButtonNavToggle.firstChild.data = collapseCaptionNavigationBarHide;
}
}
function createClickHandler( tableIndex ) { return function ( e ) { eevent.preventDefault(); collapseTable( tableIndex ); };}
/* adds show/hide-button to navigation bars */function createCollapseButtonscreateNavigationBarToggleButton( $content ) { var NavigationBoxes = {}NavChild; /* iterate over all < div >-elements */ var $Tables divs = $content.find( 'tablediv' ); var $divs.each( function ( i;, NavFrame ) { /* if found a navigation bar */ if ( $( NavFrame ).hasClass( 'NavFrame' ) ) {
$Tables indexNavigationBar++; var NavToggle = document.eachcreateElement( function'a' ); NavToggle.className = 'NavToggle'; NavToggle.setAttribute( i'id', table 'NavToggle' + indexNavigationBar ) {; if NavToggle.setAttribute( 'href', '#' ); $(tableNavToggle ).hasClasson( 'collapsibleclick' , $.proxy( window.toggleNavigationBar, window, indexNavigationBar ) ) {;
var isCollapsed = $( NavFrame ).hasClass( 'collapsed' ); /* only * * Check if any children are already hidden. This loop is here for backwards compatibility: * the old way of making NavFrames start out collapsed was to manually add button and increment count if there style="display:none" * 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 a header row to work add the class * "collapsed" to the NavFrame itself, just like with collapsible tables. */ var HeaderRow for ( NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = tableNavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).getElementsByTagNamehasClass( 'trNavContent' )[0];) { if ( !HeaderRow NavChild.style.display === 'none' ) { isCollapsed = true; } return;}
}
var Header if ( isCollapsed ) { for ( NavChild = NavFrame.firstChild; NavChild != tablenull; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).getElementsByTagNamehasClass( 'thNavPic' )[0]; if || $( NavChild ).hasClass( !Header 'NavContent' ) ) { NavChild.style.display = 'none'; } return;}
}
var NavToggleText = document.createTextNode( isCollapsed ? NavigationBarShow : NavigationBarHide );
NavToggle.appendChild( NavToggleText );
NavigationBoxes[ tableIndex ] = table; table.setAttribute( 'id', 'collapsibleTable' + tableIndex );  var Button = document.createElement( 'span' ); var ButtonLink = document.createElement( 'a' ); var ButtonText = document.createTextNode( collapseCaption ); // Styles are declared in [[MediaWiki:Common.css]] Button.className = 'collapseButton';  ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); ButtonLink.setAttribute( 'href', '#' ); $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) ); ButtonLink.appendChild( ButtonText );  Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); Button.appendChild* Find the NavHead and attach the toggle link ( document.createTextNode( ']Must be this complicated because Moz' ) );  Header.insertBefore( Button, Header.s firstChild handling is borked);*/ tableIndex++; } } );  for ( i var j = 0; i j < tableIndexNavFrame.childNodes.length; ij++ ) { if ( $( NavigationBoxes[i] )NavFrame.hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxeschildNodes[ij] ).hasClass( 'autocollapseNavHead' ) ) ) { collapseTable( i ); } else if ( $( NavigationBoxes[i] ) NavToggle.style.hasClass ( 'innercollapse' ) ) { var element color = NavigationBoxesNavFrame.childNodes[ij].style.color; while ((element = element NavFrame.parentNode)) { if ( $( element )childNodes[j].hasClassappendChild( 'outercollapse' ) NavToggle ) { collapseTable ( i ); break;
}
}
NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
});
}
mw.hook( 'wikipage.content' ).add( createCollapseButtons createNavigationBarToggleButton ); /* End of mw.loader.using callback */} );/* DO NOT ADD CODE BELOW THIS LINE */
1,980
edits

Navigation menu