|
|
(11 intermediate revisions by 3 users not shown) |
Line 1: |
Line 1: |
β | /** Collapsible tables ********************************************************* | + | /* nothing anymore */ |
β | *
| |
β | * Description: Allows tables to be collapsed, showing only the header. See
| |
β | * http://www.mediawiki.org/wiki/Manual:Collapsible_tables.
| |
β | * Maintainers: [[**MAINTAINERS**]]
| |
β | */
| |
β | var autoCollapse = 2;
| |
β | var collapseCaption = 'hide';
| |
β | var expandCaption = 'show';
| |
β |
| |
β | function collapseTable( tableIndex ) {
| |
β | var Button = document.getElementById( 'collapseButton' + tableIndex );
| |
β | var Table = document.getElementById( 'collapsibleTable' + tableIndex );
| |
β |
| |
β | if ( !Table || !Button ) {
| |
β | return false;
| |
β | }
| |
β |
| |
β | var Rows = Table.rows;
| |
β |
| |
β | if ( Button.firstChild.data == collapseCaption ) {
| |
β | for ( var i = 1; i < Rows.length; i++ ) {
| |
β | Rows[i].style.display = 'none';
| |
β | }
| |
β | Button.firstChild.data = expandCaption;
| |
β | } else {
| |
β | for ( var 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 = new Object();
| |
β | var Tables = document.getElementsByTagName( 'table' );
| |
β |
| |
β | for ( var i = 0; i < Tables.length; i++ ) {
| |
β | if ( hasClass( Tables[i], '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 MediaWiki:Common.css
| |
β |
| |
β | ButtonLink.style.color = rgb(120,120,120);
| |
β | 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 );
| |
β | }
| |
β | }
| |
β | }
| |
β |
| |
β | addOnloadHook( createCollapseButtons );
| |
β |
| |
β | /** Test if an element has a certain class **************************************
| |
β | *
| |
β | * Description: Uses regular expressions and caching for better performance.
| |
β | * Maintainers: [[User:Mike Dillon]], [[User:R. Koot]], [[User:SG]]
| |
β | */
| |
β |
| |
β | var hasClass = (function() {
| |
β | var reCache = {};
| |
β | return function( element, className ) {
| |
β | return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
| |
β | };
| |
β | })();
| |
β |
| |
β |
| |
β | /** Dynamic Navigation Bars (experimental) *************************************
| |
β | *
| |
β | * Description: See [[Wikipedia:NavFrame]].
| |
β | * Maintainers: UNMAINTAINED
| |
β | */
| |
β |
| |
β | // set up the words in your language
| |
β | var 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 toggled
| |
β | function toggleNavigationBar(indexNavigationBar)
| |
β | {
| |
β | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
| |
β | 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;
| |
β | }
| |
β | }
| |
β |
| |
β | // adds show/hide-button to navigation bars
| |
β | function 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 = document.createElement("a");
| |
β | NavToggle.className = 'NavToggle';
| |
β | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar);
| |
β | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');');
| |
β |
| |
β | var isCollapsed = hasClass( NavFrame, "collapsed" );
| |
β | /*
| |
β | * 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 (var NavChild = NavFrame.firstChild; NavChild != null && !isCollapsed; NavChild = NavChild.nextSibling) {
| |
β | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
| |
β | if ( NavChild.style.display == 'none' ) {
| |
β | isCollapsed = true;
| |
β | }
| |
β | }
| |
β | }
| |
β | if (isCollapsed) {
| |
β | for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
| |
β | if ( hasClass( NavChild, 'NavPic' ) || hasClass( NavChild, 'NavContent' ) ) {
| |
β | NavChild.style.display = 'none';
| |
β | }
| |
β | }
| |
β | }
| |
β | var NavToggleText = document.createTextNode(isCollapsed ? NavigationBarShow : NavigationBarHide);
| |
β | 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 );
| |
β | | |
β | | |
β | <!-- /*<nowiki>*/
| |
β | /** additional scripts **/
| |
β | if ( wgIsArticle || window.location.href.indexOf( 'action=submit' ) > -1 )
| |
β | {
| |
β | addScript( 'MediaWiki:CollapsibleTables.js' );
| |
β | hookEvent( 'load', function()
| |
β | {
| |
β | new CollapsibleTables();
| |
β | diffwithFix();
| |
β |
| |
β | // Extension for the deletion drop down list
| |
β | if ( wgAction == 'delete' && ( delReasonBtn = document.getElementById( 'wpConfirmB' ) ) )
| |
β | {
| |
β | var delReasonList = document.getElementById( 'wpDeleteReasonList' );
| |
β | var delLink = document.createElement( 'a' );
| |
β | delLink.href = 'javascript:void(0);'
| |
β | delLink.title = document.getElementById( 'wpReason' ).value;
| |
β | delLink.style.fontSize = '0.9em';
| |
β | delLink.style.marginLeft = '1em';
| |
β | delLink.onclick = function()
| |
β | {
| |
β | document.getElementById( 'wpReason' ).value = this.title;
| |
β | }
| |
β | delReasonList.onchange = function ()
| |
β | {
| |
β | document.getElementById( 'wpReason' ).value = '';
| |
β | this.onchange = null;
| |
β | }
| |
β | delLink.appendChild( document.createTextNode( 'restore default reason' ) );
| |
β | delReasonBtn.parentNode.appendChild( delLink );
| |
β | delete delLink, delReasonList, delReasonBtn;
| |
β | }
| |
β | } );
| |
β | }
| |
β | if ( wgPageName == 'Special:Upload' && document.getElementById( 'mw-upload-form' ) !== 'undefined' )
| |
β | {
| |
β | addScript( 'MediaWiki:UploadForm.js' );
| |
β | hookEvent( 'load', function()
| |
β | {
| |
β | new UploadForm();
| |
β | } );
| |
β | }
| |
β | | |
β | /**** function addScript.js
| |
β | * by Patrick Westerhoff [poke]
| |
β | */
| |
β | function addScript ( pagename )
| |
β | {
| |
β | var script = document.createElement( 'script' );
| |
β | pagename = encodeURI( pagename.replace( ' ', '_' ) );
| |
β | script.src = '/index.php?title=' + pagename + '&action=raw&ctype=text/javascript';
| |
β | script.type = 'text/javascript';
| |
β |
| |
β | document.getElementsByTagName( 'head' )[0].appendChild( script );
| |
β | }
| |
β | | |
β | /**** function diffwithFix.js
| |
β | * by Patrick Westerhoff [poke]
| |
β | */
| |
β | function diffwithFix ()
| |
β | {
| |
β | var diffSpan = document.getElementById( 'diffwith' );
| |
β | if ( diffSpan == undefined )
| |
β | return;
| |
β |
| |
β | var diffLink = diffSpan.getElementsByTagName( 'a' )[0];
| |
β | var diffTitle = diffSpan.title;
| |
β | var xmlHttp;
| |
β |
| |
β | try
| |
β | {
| |
β | xmlHttp = new XMLHttpRequest();
| |
β | }
| |
β | catch ( e )
| |
β | {
| |
β | try
| |
β | {
| |
β | xmlHttp = new ActiveXObject( 'Msxml2.XMLHTTP' );
| |
β | }
| |
β | catch ( e )
| |
β | {
| |
β | try
| |
β | {
| |
β | xmlHttp = new ActiveXObject( 'Microsoft.XMLHTTP' );
| |
β | }
| |
β | catch ( e )
| |
β | {
| |
β | diffSpan.style.fontSize = '90%';
| |
β | diffSpan.innerHTML = '(Automated diff <b>not available</b>.)';
| |
β | return;
| |
β | }
| |
β | }
| |
β | }
| |
β |
| |
β | xmlHttp.onreadystatechange = function ()
| |
β | {
| |
β | if ( xmlHttp.readyState != 4 )
| |
β | return;
| |
β |
| |
β | revs = xmlHttp.responseXML.getElementsByTagName( 'rev' );
| |
β |
| |
β | if ( revs.length > 0 )
| |
β | {
| |
β | diffLink.href += '&oldid=' + revs[0].getAttribute( 'revid' );
| |
β | diffSpan.title = '';
| |
β | }
| |
β | }
| |
β | xmlHttp.open( 'GET', '/api.php?format=xml&action=query&prop=revisions&rvprop=ids&rvlimit=1&titles=' + diffTitle, true );
| |
β | xmlHttp.send( null );
| |
β | }
| |
β | /*</nowiki>*/ -->
| |