Changes

Jump to navigation Jump to search

MediaWiki:Common.js

2,306 bytes removed, 17:05, 20 October 2015
Updated the NavFrame back to the current version at https://en.wikipedia.org/wiki/MediaWiki:Common.js (this syntax is now supported with MediaWiki 1.25.3).
/** Collapsible tables ****************************************************** *Dynamic Navigation Bars. See [[Wikipedia:NavFrame]] * *Based on script from en.wikipedia.org, 2008-09-15.
*
* From English Wikipedia, 2008@source www.mediawiki.org/wiki/MediaWiki:Gadget-09-15 * * Description: Allows tables to be collapsed, showing only the headerNavFrame. Seejs * [[Wikipedia:NavFrame]]@maintainer Helder.wiki, 2012–2013 * Maintainers: [[User:R. Koot]]@maintainer Krinkle, 2013
*/
var autoCollapse = 2;( function () { // Set up the words in your language
var collapseCaption = 'hide';
var expandCaption = 'show';
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 available) of navigation bars. * * @param {number} indexNavigationBar The index of navigation bar to be toggled * @param {jQuery.Event} e Event object */function toggleNavigationBar( indexNavigationBar, e ) { var navChild, navToggle = document.getElementById( 'NavToggle' + indexNavigationBar ), navFrame = document.getElementById( 'NavFrame' + indexNavigationBar );  // Prevent browser from jumping to href "#" e.preventDefault();  if ( !Table navFrame || !Button navToggle ) {
return false;
}
var Rows = Table.rows;// If shown now if ( ButtonnavToggle.firstChild.data == collapseCaption navigationBarHide ) { for ( var i navChild = navFrame.firstChild; navChild != 1null; i < RowsnavChild = navChild.length; i++ nextSibling ) { Rows[i]if ( hasClass( navChild, 'NavPic' ) ) { navChild.style.display = 'none'; } Button.firstChild.data = expandCaption; } else { for if ( hasClass( var i = 1; i < Rows.length; i++ navChild, 'NavContent' ) ) { Rows[i] navChild.style.display = Rows[0].style.display'none'; }
}
ButtonnavToggle.firstChild.data = collapseCaptionnavigationBarShow; }}
function createCollapseButtons(){ var tableIndex = 0;// If hidden now var NavigationBoxes = new Object} else if (); var Tables navToggle.firstChild.data = document.getElementsByTagName( 'table' );  for ( var i = 0; i < Tables.length; i++ navigationBarShow ) { if ( hasClassfor ( Tables[i], 'collapsible' ) ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow navChild = Tables[i]navFrame.getElementsByTagName( 'tr' )[0]firstChild; if( navChild !HeaderRow ) continue= null; var Header navChild = HeaderRownavChild.getElementsByTagName( 'th' nextSibling )[0];{ if( !Header $( navChild ) continue;  NavigationBoxes[tableIndex] = Tables[i]; Tables[i].setAttributehasClass( 'id', 'collapsibleTableNavPic' + tableIndex );  var Button = document.createElement|| $( 'span' navChild ); var ButtonLink = document.createElementhasClass( 'aNavContent' ); var ButtonText = document.createTextNode( collapseCaption );{  Button.style.styleFloat = 'right'; Button.style.cssFloat = 'right'; Button navChild.style.fontWeight display = 'normalblock'; 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 );
}
navToggle.firstChild.data = navigationBarHide;
}
}
addOnloadHook( createCollapseButtons );  /** Dynamic Navigation Bars (experimental) ************************************ *Adds show/hide-button to navigation bars.
*
* From English Wikipedia, 2008-09-15 * * Description: See [[Wikipedia:NavFrame]]. * Maintainers: UNMAINTAINED@param {jQuery} $content
*/
// 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 toggleNavigationBarcreateNavigationBarToggleButton( indexNavigationBar $content ){ var NavToggle i, j, navFrame, navToggle, navToggleText, navChild, indexNavigationBar = document0, navFrames = $content.getElementByIdfind('NavTogglediv.NavFrame' + indexNavigationBar); var NavFrame = document.getElementByIdtoArray('NavFrame' + indexNavigationBar);
if// Iterate over all ( !NavFrame || !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 ) {; return falsenavToggle.setAttribute( 'href', '#' ); } $( navToggle ).on( 'click', $.proxy( toggleNavigationBar, null, indexNavigationBar ) );
// if shown now if navToggleText = document.createTextNode( NavToggle.firstChild.data == NavigationBarHide navigationBarHide ) {; for( var NavChild navChild = NavFramenavFrame.firstChild; NavChild navChild != null; NavChild navChild = NavChildnavChild.nextSibling ) { if ( $( navChild ).hasClass( NavChild, 'NavPic' ) || $( navChild ) { NavChild.style.display = 'none'; } if ( hasClass( NavChild, 'NavContent') ) { NavChildif ( navChild.style.display == 'none') { navToggleText = document.createTextNode( navigationBarShow ); break; }
}
}
NavToggle.firstChild.data = NavigationBarShow;
navToggle.appendChild( navToggleText ); // if hidden now } else ifFind the NavHead and attach the toggle link ( NavToggle.Must be this complicated because Moz's firstChild.data == NavigationBarShowhandling is borked) { for( var NavChild j = NavFrame0; j < navFrame.childNodes.firstChild; NavChild != nulllength; NavChild = NavChild.nextSibling j++ ) { if( hasClass$( NavChild, 'NavPic' ) navFrame.childNodes[j] ) { NavChild.style.display = 'block'; } if( hasClass( NavChild, 'NavContentNavHead' ) ) { NavChildnavFrame.stylechildNodes[j].display = 'block'appendChild( navToggle );
}
}
NavTogglenavFrame.firstChild.data = NavigationBarHidesetAttribute( 'id', 'NavFrame' + indexNavigationBar );
}
}
// adds show/hide-button to navigation barsfunction createNavigationBarToggleButton(){ var indexNavigationBar = 0; // iterate over all < div >-elements var divs = document.getElementsByTagName('div'); for( var i = 0; NavFrame = divs[i]; i++ ) { // if found a navigation bar if( hasClass( NavFrame, 'NavFrame' ) ) { indexNavigationBar++; var NavToggle = documentmw.createElementhook("a"); NavToggle.className = 'NavToggle'; NavTogglewikipage.setAttribute('id', 'NavTogglecontent' + indexNavigationBar); NavToggle.setAttributeadd('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'createNavigationBarToggleButton );
var NavToggleText = document.createTextNode(NavigationBarHide); for( var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling ) { if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { if( NavChild.style.display == 'none' ) { NavToggleText = document.createTextNode(NavigationBarShow); break; } } }  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 < NavFrame.childNodes.length; j++) { if( hasClass( NavFrame.childNodes[j], 'NavHead' ) ) { NavFrame.childNodes[j].appendChild(NavToggle); } } NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); } }} addOnloadHook( createNavigationBarToggleButton );

Navigation menu