Changes

Jump to navigation Jump to search

MediaWiki:Common.js

4,256 bytes removed, 21:09, 20 October 2015
Undo revision 5236 by Bugman admin (talk)
/**
* Collapsible tables *******************************************************Dynamic Navigation Bars. See [[Wikipedia:NavFrame]] * *Based on script from en.wikipedia.org, 2008-09-15.
*
* Description@source www.mediawiki.org/wiki/MediaWiki: Allows tables to be collapsedGadget-NavFrame.js * @maintainer Helder.wiki, showing only the header.2012–2013 * @maintainer Krinkle, 2013
*/
( function () {var autoCollapse = 2;// Set up the words in your language
var collapseCaption = 'hide';
var expandCaption = 'show';
window.collapseTable = function ( 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; }of navigation bars. var Rows = Table.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].stylejQuery.display = Rows[0].style.display; Event} Button.firstChild.data = collapseCaption; }};e Event object */function createCollapseButtonstoggleNavigationBar(indexNavigationBar, e ) { var tableIndex = 0;navChild, var NavigationBoxes navToggle = {};document.getElementById( 'NavToggle' + indexNavigationBar ), var Tables navFrame = document.getElementsByTagNamegetElementById( 'tableNavFrame' + indexNavigationBar ); var i; // Prevent browser from jumping to href "#" function handleButtonLink( index, e ) { window.collapseTablepreventDefault( index ); e.preventDefault if (!navFrame || !navToggle ){ return false; } for ( i = 0; i < Tables.length; i++ ) { // If shown now if ( $( Tables[i] )navToggle.firstChild.hasClass( 'collapsible' ) data == navigationBarHide ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow for ( navChild = Tables[i]navFrame.getElementsByTagName( 'tr' )[0]firstChild; if ( navChild !HeaderRow ) continue= null; var Header navChild = HeaderRownavChild.getElementsByTagName( 'th' nextSibling )[0];{ if ( !Header ) continue; NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttributehasClass( 'id'navChild, 'collapsibleTableNavPic' + tableIndex ); var Button = document.createElement( 'span' );{ var ButtonLink = document navChild.createElement( 'a' ); var ButtonText = documentstyle.createTextNode( collapseCaption ); Button.className display = 'collapseButtonnone'; /* Styles are declared in Common.css */ } ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute if ( hasClass( 'id'navChild, 'collapseButtonNavContent' + tableIndex );) { ButtonLink navChild.setAttribute( 'href', '#' ); $( ButtonLink )style.on( display = 'clicknone', $.proxy( handleButtonLink, ButtonLink, tableIndex ) ); ButtonLink.appendChild( ButtonText ); } } Button navToggle.appendChild( documentfirstChild.createTextNode( '[' ) )data = navigationBarShow; Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( ']' ) ); // If hidden now Header.insertBefore } 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' ) ) ) { window navChild.collapseTable( i ); } else if ( $( NavigationBoxes[i] )style.hasClass ( 'innercollapse' ) ) { var element = NavigationBoxes[i]; while ((element display = element.parentNode)) { if ( $( element ).hasClass( 'outercollapseblock' ) ) { window.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 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 toggledwindow.toggleNavigationBar = functioncreateNavigationBarToggleButton(indexNavigationBar$content ){ var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);i, j, navFrame, navToggle, navToggleText, navChild, var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); if (!NavFrame || !NavToggle) { return false; } // if shown now if (NavToggle.firstChild.data == NavigationBarHide) {0, for (var NavChild navFrames = NavFrame.firstChild; NavChild != null; NavChild = NavChild$content.nextSibling) { if (hasClassfind(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) { NavChilddiv.style.display = NavFrame'none'; } } NavToggle.firstChild.data = NavigationBarShow; // if hidden now } else if (NavToggle.firstChild.data == NavigationBarShow) { for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { if (hasClass(NavChild, 'NavContent') || hasClasstoArray(NavChild, 'NavPic')) { NavChild.style.display = 'block'; } } NavToggle.firstChild.data = NavigationBarHide; }} / / adds show/hide-button to navigation barsfunction createNavigationBarToggleButton(){ var indexNavigationBar = 0; // iterate Iterate over all < div >-elements var divs = document.getElementsByTagName("div"new);nav frames for (var i = 0; NavFrame = divs[i]< navFrames.length; i++) { navFrame = navFrames[i]; // if If found a navigation bar if (hasClass(NavFrame, "NavFrame")) { indexNavigationBar++; var NavToggle navToggle = document.createElement("'a"' ); NavToggle navToggle.className = 'NavToggle'; NavToggle navToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); NavToggle navToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + #'); $( navToggle ).on( 'click'); var isCollapsed = hasClass, $.proxy( NavFrametoggleNavigationBar, null, "collapsed" indexNavigationBar ) ); /* * 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 navToggleText ="display:none" * to all the NavPic/NavContent elementsdocument. Since this was bad for accessibility createTextNode(no way to make * the content visible without JavaScript supportnavigationBarHide ), the new recommended way is to add the class * "collapsed" to the NavFrame itself, just like with collapsible tables. */; for (var NavChild navChild = NavFramenavFrame.firstChild; NavChild navChild != null && !isCollapsed; NavChild navChild = NavChildnavChild.nextSibling) { if ( $( navChild ).hasClass( NavChild, 'NavPic' ) || $( navChild ).hasClass( NavChild, 'NavContent' ) ) { if ( NavChildnavChild.style.display == 'none' ) { isCollapsed navToggleText = true; } } } if document.createTextNode(isCollapsednavigationBarShow ) { for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { NavChild.style.display = 'none' break; } } } var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide); NavToggle navToggle.appendChild(NavToggleTextnavToggleText ); // 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 (hasClass$(NavFramenavFrame.childNodes[j], ").hasClass( 'NavHead"' )) { NavToggle.style.color = NavFrame.childNodes[j].style.color; NavFrame navFrame.childNodes[j].appendChild(NavTogglenavToggle ); } } NavFrame navFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); } }
}
$mw.hook( 'wikipage.content' ).add( createNavigationBarToggleButton ); }());

Navigation menu