Changes

Jump to navigation Jump to search

MediaWiki:Common.js

4,757 bytes removed, 11:31, 17 October 2015
Undo revision 5099 by Bugman admin (talk)
/**
* Collapsible tablesDynamic Navigation Bars. See [[Wikipedia:NavFrame]] * * Based on script from en.wikipedia.org, 2008-09-15.
*
* Allows tables to be collapsed, showing only the header. See [[Wikipedia:NavFrame]]. * * @version 2.0.3 (2014-03-14) * @source https://www.mediawiki.org/wiki/MediaWiki:Gadget-collapsibleTablesNavFrame.js * @author [[User:Rmaintainer Helder. Koot]]wiki, 2012–2013 * @author [[User:maintainer Krinkle]] * @deprecated Since MediaWiki 1.20: Use class="mw-collapsible" instead which * is supported in MediaWiki core., 2013
*/
( function () {
var autoCollapse = 2;// Set up the words in your language
var collapseCaption = 'hide';
var expandCaption = 'show';
var tableIndex = 0;
function collapseTable( tableIndex ) { var Button navigationBarHide = document.getElementById( 'collapseButton[' + tableIndex )collapseCaption + ']'; var Table navigationBarShow = document.getElementById( 'collapsibleTable[' + tableIndex )expandCaption + ']';
/** * Shows and hides content and picture (if ( !Table || !Button available) { return false; }  var Rows = Tableof navigation bars.rows; var i; *  if ( Button.firstChild.data === collapseCaption ) { for ( i = 1; i < Rows.length; i++ ) * @param { Rows[i].style.display = 'none'; number}indexNavigationBar The index of navigation bar to be toggled Button.firstChild.data = expandCaption; } else { for ( i = 1; i < Rows.length; i++ ) * @param { Rows[i]jQuery.style.display = Rows[0].style.display; } Button.firstChild.data = collapseCaption; }Event}e Event object */function createClickHandler( tableIndex ) { return function toggleNavigationBar( indexNavigationBar, e ) { e.preventDefault(); collapseTable( tableIndex ); };} function createCollapseButtons( $content ) { var NavigationBoxes = {};navChild, var $Tables navToggle = $contentdocument.findgetElementById( 'tableNavToggle' + indexNavigationBar ); var i;  $Tables.each( function( i, table ) { if ( $(table).hasClass( 'collapsible' ) ) {  /* only add button and increment count if there is a header row to work with */ var HeaderRow = table.getElementsByTagName( 'tr' )[0]; if ( !HeaderRow ) { return; } var Header = table.getElementsByTagName( 'th' )[0]; if ( !Header ) { return; }  NavigationBoxes[ tableIndex ] navFrame = table; tabledocument.setAttributegetElementById( 'id', 'collapsibleTableNavFrame' + tableIndex indexNavigationBar );
var Button = document.createElement( 'span' ); // Prevent browser from jumping to href "#" var ButtonLink = document e.createElementpreventDefault( '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 if ( 'href', '#' !navFrame || !navToggle );{ $( ButtonLink ).on( 'click', createClickHandler( tableIndex ) ) return false; ButtonLink.appendChild( ButtonText ); }
Button // If shown now if ( navToggle.firstChild.appendChilddata == navigationBarHide ) { for ( documentnavChild = navFrame.firstChild; navChild != null; navChild = navChild.createTextNodenextSibling ) { if ( hasClass( navChild, '[NavPic' ) );{ Button navChild.style.appendChild( ButtonLink )display = 'none'; Button.appendChild } if ( document.createTextNodehasClass( navChild, ']NavContent' ) ){ navChild.style.display = 'none'; } } navToggle.firstChild.data = navigationBarShow;
Header.insertBefore // If hidden now } else if ( Button, HeadernavToggle.firstChild .data == navigationBarShow );{ tableIndex++; } } );  for ( i navChild = 0navFrame.firstChild; i < tableIndexnavChild != null; i++ navChild = navChild.nextSibling ) { if ( $( NavigationBoxes[i] navChild ).hasClass( 'collapsedNavPic' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] navChild ).hasClass( 'autocollapseNavContent' ) ) ) { collapseTable( i ); } else if ( $( NavigationBoxes[i] ) navChild.style.hasClass ( 'innercollapse' ) ) { var element display = NavigationBoxes[i]; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapseblock' ) ) { collapseTable ( i ); break; } } } navToggle.firstChild.data = navigationBarHide; }
}
 
mw.hook( 'wikipage.content' ).add( createCollapseButtons );
/**
* Dynamic Navigation Bars (experimental)Adds show/hide-button to navigation bars.
*
* Description: See [[Wikipedia:NavFrame]]. * Maintainers: UNMAINTAINED@param {jQuery} $content
*/
 
/* set up the words in your language */
var NavigationBarHide = '[' + collapseCaption + ']';
var NavigationBarShow = '[' + expandCaption + ']';
var 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 ( indexNavigationBar, event ) {
var NavToggle = document.getElementById( 'NavToggle' + indexNavigationBar );
var NavFrame = document.getElementById( 'NavFrame' + indexNavigationBar );
var NavChild;
 
if ( !NavFrame || !NavToggle ) {
return false;
}
 
/* if shown now */
if ( NavToggle.firstChild.data === NavigationBarHide ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'none';
}
}
NavToggle.firstChild.data = NavigationBarShow;
 
/* if hidden now */
} else if ( NavToggle.firstChild.data === NavigationBarShow ) {
for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) {
if ( $( NavChild ).hasClass( 'NavContent' ) || $( NavChild ).hasClass( 'NavPic' ) ) {
NavChild.style.display = 'block';
}
}
NavToggle.firstChild.data = NavigationBarHide;
}
 
event.preventDefault();
};
 
/* adds show/hide-button to navigation bars */
function createNavigationBarToggleButton( $content ) {
var NavChild;i, j, navFrame, navToggle, navToggleText, navChild, /* iterate over all < div >-elements */ indexNavigationBar = 0, var $divs navFrames = $content.find( 'div' ); $divs.each( function ( i, NavFrame ) { /* if found a navigation bar */ if ( $( NavFrame ' ).hasClasstoArray( 'NavFrame' ) ) {;
// Iterate over all (new) nav frames for ( i = 0; i < navFrames.length; i++ ) { navFrame = navFrames[i]; // If found a navigation bar indexNavigationBar++; var NavToggle navToggle = document.createElement( 'a' ); NavToggle navToggle.className = 'NavToggle'; NavToggle navToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); NavToggle navToggle.setAttribute( 'href', '#' ); $( NavToggle navToggle ).on( 'click', $.proxy( window.toggleNavigationBar, windownull, indexNavigationBar ) );
var isCollapsed navToggleText = $( NavFrame )document.hasClasscreateTextNode( 'collapsed' navigationBarHide ); /** * 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 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 to add the class * "collapsed" to the NavFrame itself, just like with collapsible tables. */ for ( NavChild navChild = NavFramenavFrame.firstChild; NavChild navChild != null && !isCollapsed; NavChild navChild = NavChildnavChild.nextSibling ) { if ( $( NavChild navChild ).hasClass( 'NavPic' ) || $( NavChild navChild ).hasClass( 'NavContent' ) ) { if ( NavChildnavChild.style.display === 'none' ) { isCollapsed navToggleText = true; } } } if document.createTextNode( isCollapsed navigationBarShow ) { for ( NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( $( NavChild ).hasClass( 'NavPic' ) || $( NavChild ).hasClass( 'NavContent' ) ) { NavChild.style.display = 'none' break; } } } 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) */ for( var j = 0; j < NavFramenavFrame.childNodes.length; j++ ) { if ( $( NavFramenavFrame.childNodes[j] ).hasClass( 'NavHead' ) ) { NavToggle.style.color = NavFrame.childNodes[j].style.color; NavFrame navFrame.childNodes[j].appendChild( NavToggle navToggle ); } } NavFrame navFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); } } );
}
mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton );
 
}());

Navigation menu