Changes

Jump to navigation Jump to search

MediaWiki:Common.js

4,539 bytes removed, 12:17, 17 October 2015
Updated to https://en.wikipedia.org/wiki/MediaWiki:Common.css .
/** * Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. Default style for navigation boxes */ var autoCollapse = 2;var collapseCaption = 'hide';var expandCaption = 'show'; window.collapseTable = function ( tableIndex ) navbox { var 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]. /* Navbox container 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 = collapseCaptionborder: 1px solid #aaa; }}width: 100%; function createCollapseButtons() { var tableIndex = 0margin: auto; var NavigationBoxes = {}clear: both; var Tables = document.getElementsByTagName( 'table' )font-size: 88%; var itext-align: center; 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 Header = HeaderRow.getElementsByTagName( 'th' )[0]; if ( !Header ) continue; NavigationBoxes[ tableIndex ] = Tables[i]; Tables[i].setAttribute( 'id', 'collapsibleTable' + 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; 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]padding: 1px; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapse' ) ) { window.collapseTable ( i ); break; } } } }
}
mw.hook( 'wikipage.content' ).add( createCollapseButtons );navbox-inner, /** Dynamic Navigation Bars (experimental) ************************************* * * Description: See [[Wikipedia:NavFrame]].navbox-subgroup { * 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:// indexNavigationBarwidth: the index of navigation bar to be toggledwindow.toggleNavigationBar = function(indexNavigationBar){ var NavToggle = document.getElementById("NavToggle" + indexNavigationBar)100%; var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); if (!NavFrame || !NavToggle) { return false; } // if shown now if (NavToggle.firstChild.data == NavigationBarHide) { for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) { if (hasClass(NavChild, 'NavContent') || hasClass(NavChild, 'NavPic')) { NavChild.style.display = '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') || hasClass(NavChild, 'NavPic')) { NavChild.style.display = 'block'; } } NavToggle.firstChild.data = NavigationBarHide; }
}
.navbox-group,.navbox-title,.navbox-abovebelow { padding: 0.25em 1em; /* Title, group and above/ adds showbelow styles */hide line-height: 1.5em; text-button to navigation barsalign: center;}function createNavigationBarToggleButton()th.navbox-group { /* Group style */ var indexNavigationBar = 0white-space: nowrap; /* @noflip */ iterate over all < div > text-elements align: right;}.navbox, var divs = document.getElementsByTagName("div");navbox-subgroup { for (var i = 0background: #fdfdfd; NavFrame = divs[i]; i++) { /* Background color */ if found a navigation bar if (hasClass(NavFrame, "NavFrame") && !hasClass(NavFrame, "mw}.navbox-collapsible")) list { line-height: 1.5em; indexNavigationBar++ border-color: #fdfdfd; /* Must match background color */} var NavToggle = document.createElement("a");navbox th, NavToggle.className = 'NavToggle'navbox-title { background: #ccccff; /* Level 1 color */} NavToggle.setAttribute('id'navbox-abovebelow, 'NavToggle' + indexNavigationBar); NavToggleth.setAttribute('href'navbox-group, 'javascript.navbox-subgroup .navbox-title { background:toggleNavigationBar(' + indexNavigationBar + ');')#ddddff; /* Level 2 color */ } var isCollapsed = hasClass( NavFrame.navbox-subgroup .navbox-group, "collapsed" ).navbox-subgroup .navbox-abovebelow { background: #e6e6ff; /* Level 3 color */} .navbox-even { background: #f7f7f7; /*Even row striping */} * Check if any children are already hidden. navbox-odd { background: transparent; This loop is here for backwards compatibility: /* the old way of making NavFrames start out collapsed was to manually add style="display:none" Odd row striping * to all the NavPic/NavContent elements}table. Since this was bad for accessibility (no way to makenavbox { margin-top: 1em; /* the Prevent preceding content visible without JavaScript support), the new recommended way is from clinging to add the classnavboxes */}table.navbox table.navbox { margin-top: 0; /* No top margin for nested navboxes * "collapsed" to the NavFrame itself, just like with collapsible tables/}table.navbox + table.navbox { margin-top: -1px; /* Single pixel border between adjacent navboxes */ for (var NavChild = NavFrame}.navbox .hlist td dl,.navbox .hlist td ol,.firstChild; NavChild != null && !isCollapsed; NavChild = NavChildnavbox .nextSibling) {hlist td ul, if ( hasClass( NavChild.navbox td.hlist dl, 'NavPic' ) || hasClass( NavChild.navbox td.hlist ol, 'NavContent' ) ) { if ( NavChild.stylenavbox td.display == 'none' ) hlist ul { isCollapsed = true padding: 0.125em 0; /* Adjust hlist padding in navboxes */ } } }/* Default styling for Navbar template */ if (isCollapsed) .navbar { for (var NavChild = NavFrame.firstChild display: inline; font-size: 88%; NavChild != null font-weight: normal; NavChild = NavChild}.nextSibling) navbar ul { if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) { display: inline; NavChild.style.display = 'none' white-space: nowrap; } }.mw-body-content .navbar ul { line-height: inherit; } var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow navbar li { word-spacing: NavigationBarHide)-0.125em; NavToggle}.navbar.appendChild(NavToggleText)mini li span { font-variant: small-caps; } /* Navbar styling when nested in infobox and navbox */ 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.childNodesinfobox .lengthnavbar { font-size: 100%; j++) { if (hasClass(NavFrame}.navbox .childNodes[j], "NavHead")) navbar { NavToggle display: block; font-size: 100%;}.stylenavbox-title .color = NavFramenavbar { /* @noflip */ float: left; /* @noflip */ text-align: left; /* @noflip */ margin-right: 0.childNodes5em; width: 6em;} /* 'show'/'hide' buttons created dynamically by the CollapsibleTables javascript in [j[MediaWiki:Common.js]] are styled here so they can be customised.style*/.colorcollapseButton { /* @noflip */ float: right; font-weight: normal; NavFrame /* @noflip */ margin-left: 0.childNodes5em; /* @noflip */ text-align: right; width: auto;}/* In navboxes, the show/hide button balances the v·d·e links from [j[Template:Navbar]], so they need to be the same width. */.appendChild(NavToggle)navbox .collapseButton { width: 6em; } } NavFrame/* Styling for JQuery makeCollapsible, matching that of collapseButton */.setAttribute('id', 'NavFrame' + indexNavigationBar)mw-collapsible-toggle { font-weight: normal; /* @noflip */ text-align: right; }.navbox .mw-collapsible-toggle { }width: 6em;
}
$( createNavigationBarToggleButton );

Navigation menu