MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

// imports importArticles({type:'script', articles: [   'w:c:dev:BackToTopButton/code.js',    'w:c:dev:DisplayClock/code.js',    'w:c:dev:ListAdmins/code.js',    'w:c:dev:ReferencePopups/code.js',    'w:c:dev:RevealAnonIP/code.js' ]);

window.DisplayClockJS = { format: '%H:%2M:%2S %B %d, %Y (UTC)', location: 'global', hoverText: 'Click to purge the page', interval: 500, monofonts: 'Roboto, sans-serif' };

/** * Location of baseURL and wikiURL * * baseURL is where the wiki is actually installed * It can be seen in URLs such as index.php and api.php * It's usually /w/ * * wikiURL is the alias for baseURL + index.php?title= * It can be seen when viewing any normal wiki page * It's usually /wiki/ */ window.baseURL = '/'; window.wikiURL = '/wiki/';

/** * Collapsible tables ********************************************************* * * Description: Allows tables to be collapsed, showing only the header. See *             NavFrame. * Maintainers: en:User:R. Koot */ var autoCollapse = 2; var collapseCaption = 'hide'; var expandCaption = 'show'; window.collapseTable = function ( tableIndex ) { 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].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 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]; while ((element = element.parentNode)) { if ( $( element ).hasClass( 'outercollapse' ) ) { window.collapseTable ( i ); break; }           }        }    } } $( createCollapseButtons );

/** * Page loader * * Allows a page to be downloaded and shown within another page. * Use with Template:LoadPage */ var loadText = 'load', showText = 'show', hideText = 'hide';

$( '.load-page' ).find( '.mw-headline:first' ).append( ' [ ' + loadText + ' ] ' );

$( '.load-page-button > .jslink' ).live( 'click', function {	var $this = $( this ), $body = $this.closest( '.load-page' ), $content = $body.find( '.load-page-content' );	if ( $body.hasClass( 'loading' ) ) {		return;	}	if ( $this.text === loadText ) {		$body.addClass( 'loading' );		$( 'body' ).css( 'cursor', 'progress' );		$.ajax( { url: window.baseURL + 'api.php', data: { format: 'json', action: 'parse', prop: 'text', title: mw.config.get( 'wgPageName' ), text: '' },			dataType: 'json', timeout: 20000 } ).done( function( data ) { if ( data.error ) { if ( $( '#error-dialog' ).length ) { return; }				mw.loader.using( 'jquery.ui.dialog', function {					$body.removeClass( 'loading' );					$( 'body' ).css( 'cursor', 'auto' );					$( '#netbar' ).after( ' ' );					$( '#error-dialog' ).html( ' Error: ' + data.error.info + ' ' ).dialog( { title: 'Hey! Listen!', resizable: false, width: 400, modal: true, buttons: { 'Retry': function { $this.click; $( this ).dialog( 'destroy' ); $( '#error-dialog' ).remove; },							Cancel: function { $( this ).dialog( 'destroy' ); $( '#error-dialog' ).remove; return; }						}					} );				} );				return; }			$content.html( data.parse.text['*'] ); $this.text( hideText ); $body.removeClass( 'loading' ); $( 'body' ).css( 'cursor', 'auto' ); // Add Ajax compatible functions here window.animation; window.makeCollapsible; } ).fail( function( error ) { if ( $( '#error-dialog' ).length ) { return; }			mw.loader.using( 'jquery.ui.dialog', function {				$body.removeClass( 'loading' );				$( 'body' ).css( 'cursor', 'auto' );				$( '#netbar' ).after( ' ' );				if ( !error.responseText ){					$( '#error-dialog' ).html( ' Error: No response from the server ' );				} else {					$( '#error-dialog' ).html( ' Error: ' + error.responseText + ' ' );				}				$( '#error-dialog' ).dialog( { title: 'Hey! Listen!', resizable: false, width: 400, modal: true, buttons: { 'Retry': function { $this.click; $( this ).dialog( 'destroy' ); $( '#error-dialog' ).remove; },						Cancel: function { $( this ).dialog( 'destroy' ); $( '#error-dialog' ).remove; return; }					}				} );			} );		} );	} else if ( $this.text === showText ) {		$content.show;		$this.text( hideText );	} else {		$content.hide;		$this.text( showText );	} } );

/* Replaces with the name of the user browsing the page. Requires copying Template:USERNAME. */ function UserNameReplace { if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace || wgUserName == null) return; $("span.insertusername").html(wgUserName); }

$( UserNameReplace );