Changes

Jump to navigation Jump to search

MediaWiki:Common.js

4,257 bytes added, 11:35, 17 October 2015
Different version of the collapsible table and NavFrame javascript.
importScript('/www/wiki.nmr-relax.com/extensions/HarvardReferences/HarvardReferences.js');
importScript('http:/wiki.nmr-relax.com/extensions/HarvardReferences/HarvardReferences.js');
 
/**
* Dynamic Navigation Bars. See [[Wikipedia:NavFrame]] Collapsible tables ******************************************************** * Based on script from en.wikipedia.org, 2008-09-15.
*
* @source www.mediawiki.org/wiki/MediaWikiDescription:Gadget-NavFrame.js * @maintainer HelderAllows tables to be collapsed, showing only the header.wiki, 2012–2013 * @maintainer Krinkle, 2013
*/
( function () {  // Set up the words in your languagevar autoCollapse = 2;
var collapseCaption = 'hide';
var expandCaption = 'show';
window.collapseTable = function ( tableIndex ) { var navigationBarHide Button = document.getElementById( 'collapseButton'+ tableIndex ); var Table = document.getElementById( 'collapsibleTable' + tableIndex ); if ( !Table || !Button ) { return false; } var Rows = Table.rows; var i; if ( Button.firstChild.data === collapseCaption ) { for ( i = 1; i < Rows.length; i++ ) { Rows[i].style.display = 'none' ; } Button.firstChild.data = expandCaption; } else { for ( i = 1; i < Rows.length; i++ ) { Rows[i].style.display = Rows[0].style.display; } Button.firstChild.data = collapseCaption ; }}; function createCollapseButtons() { var tableIndex = 0; var NavigationBoxes = {}; var Tables = document.getElementsByTagName( 'table' ); var i; function handleButtonLink( index, e ) { window.collapseTable( index ); e.preventDefault(); } for ( i = 0; i < Tables.length; i++ ) { if ( $( Tables[i] ).hasClass( 'collapsible') ) { /* only add button and increment count if there is a header row to work with */ var HeaderRow = Tables[i].getElementsByTagName( 'tr' )[0]; if ( !HeaderRow ) continue; var navigationBarShow Header = HeaderRow.getElementsByTagName( 'th')[0]; if ( !Header ) continue; NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttribute( 'id', 'collapsibleTable' + expandCaption + tableIndex ); var Button = document.createElement( ']span'); var ButtonLink = document.createElement( 'a' ); var ButtonText = document.createTextNode( collapseCaption ); Button.className = 'collapseButton'; /*Styles are declared in Common.css */ ButtonLink.style.color = Header.style.color; ButtonLink.setAttribute( 'id', 'collapseButton' + tableIndex ); ButtonLink.setAttribute( 'href', '#' ); $( ButtonLink ).on( 'click', $.proxy( handleButtonLink, ButtonLink, tableIndex ) ); ButtonLink.appendChild( ButtonText ); Button.appendChild( document.createTextNode( '[' ) ); Button.appendChild( ButtonLink ); Button.appendChild( document.createTextNode( ']' ) ); Header.insertBefore( Button, Header.firstChild ); tableIndex++; } } for ( i = 0; * Shows and hides content and picture i < tableIndex; i++ ) { if ( $( NavigationBoxes[i] ).hasClass( 'collapsed' ) || ( tableIndex >= autoCollapse && $( NavigationBoxes[i] ).hasClass( 'autocollapse' ) ) ) { window.collapseTable( i ); } else if ( $( NavigationBoxes[i] ).hasClass ( 'innercollapse' ) ) { var element = NavigationBoxes[i]; while ((element = element.parentNode)) { if available( $( element ) of navigation bars.hasClass( 'outercollapse' ) ) { window.collapseTable ( i ); break; } } } }} mw.hook( 'wikipage.content' ).add( createCollapseButtons ); /** Dynamic Navigation Bars (experimental) *************************************
*
* @param {number} indexNavigationBar The index of navigation bar to be toggled Description: See [[Wikipedia:NavFrame]]. * @param {jQuery.Event} e Event object Maintainers: UNMAINTAINED
*/
// 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 = function toggleNavigationBar( indexNavigationBar, e ) { var navChild, navToggle NavToggle = document.getElementById( '"NavToggle' " + indexNavigationBar ),; navFrame var NavFrame = document.getElementById( '"NavFrame' " + indexNavigationBar ); // Prevent browser from jumping to href "#" e.preventDefault();  if ( !navFrame NavFrame || !navToggle NavToggle) { return false; } // If if shown now if ( navToggleNavToggle.firstChild.data == navigationBarHide NavigationBarHide) { for ( navChild var NavChild = navFrameNavFrame.firstChild; navChild NavChild != null; navChild NavChild = navChildNavChild.nextSibling ) { if ( hasClass( navChildNavChild, 'NavPicNavContent' ) ) { navChild.style.display = 'none'; } if ( || hasClass( navChildNavChild, 'NavContentNavPic' ) ) { navChild NavChild.style.display = 'none'; } } navToggle NavToggle.firstChild.data = navigationBarShowNavigationBarShow; // If if hidden now } else if ( navToggleNavToggle.firstChild.data == navigationBarShow NavigationBarShow) { for ( navChild var NavChild = navFrameNavFrame.firstChild; navChild NavChild != null; navChild NavChild = navChildNavChild.nextSibling ) { if ( $( navChild ).hasClass( NavChild, 'NavPicNavContent' ) || $( navChild ).hasClass( NavChild, 'NavContentNavPic' ) ) { navChild NavChild.style.display = 'block'; } } navToggle NavToggle.firstChild.data = navigationBarHideNavigationBarHide; }
}
/** * Adds / adds show/hide-button to navigation bars. * * @param {jQuery} $content */function createNavigationBarToggleButton( $content ) { var i, j, navFrame, navToggle, navToggleText, navChild, indexNavigationBar = 0, navFrames = $content.find( 'div.NavFrame' ).toArray() // Iterate iterate over all < div >-elements var divs = document.getElementsByTagName(new"div") 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++; navToggle var NavToggle = document.createElement( '"a' "); navToggle NavToggle.className = 'NavToggle'; navToggle NavToggle.setAttribute( 'id', 'NavToggle' + indexNavigationBar ); navToggle NavToggle.setAttribute( 'href', '#javascript:toggleNavigationBar(' + indexNavigationBar + ');' ); $ var isCollapsed = hasClass( navToggle ).on( 'click', $.proxy( toggleNavigationBarNavFrame, null, indexNavigationBar ) "collapsed" ); /* navToggleText * 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= document"display:none" * to all the NavPic/NavContent elements.createTextNode Since this was bad for accessibility ( navigationBarHide 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 var 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' ) { navToggleText isCollapsed = documenttrue; } } } if (isCollapsed) { for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.createTextNodenextSibling) { if ( hasClass( NavChild, 'NavPic' ) || hasClass( navigationBarShow NavChild, 'NavContent' ) );{ break NavChild.style.display = 'none'; } } } var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide); navToggle NavToggle.appendChild( navToggleText 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 ( $hasClass( navFrameNavFrame.childNodes[j] ).hasClass( ', "NavHead' ") ) { navFrame NavToggle.style.color = NavFrame.childNodes[j].style.color; NavFrame.childNodes[j].appendChild( navToggle NavToggle); } } navFrame NavFrame.setAttribute( 'id', 'NavFrame' + indexNavigationBar ); } }
}
mw.hook( 'wikipage.content' ).add$( createNavigationBarToggleButton ); }());

Navigation menu