MediaWiki:Common.js

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

function getElementsByClass( searchClass, node, tag ) { var classElements = new Array; if( node == null ) { node = document; }	if( tag == null ) { tag = '*'; }	var els = node.getElementsByTagName( tag ); var elsLen = els.length; var tester = new ClassTester( searchClass ); for( i = 0, j = 0; i < elsLen; i++ ) { if( tester.isMatch( els[i] ) ) { classElements[j] = els[i]; j++; }	}	return classElements; } function ClassTester( className ) { this.regex = new RegExp( "(^|\\s)" + className + "(\\s|$)" ); } ClassTester.prototype.isMatch = function( element ) { return this.regex.test( element.className ); } /* end getElementsByClass */

/* Returns h1.firstHeading (the page title element). */ function getFirstHeading { var elements = getElementsByClass( 'firstHeading', document.getElementById( 'content' ), 'h1' ); return ( elements != null && elements.length > 0 ) ? elements[0] : null; }

// BEGIN JavaScript title rewrite // requires getFirstHeading and getElementsByClass and its dependencies function rewriteTitle { if( typeof( window.SKIP_TITLE_REWRITE ) != 'undefined' && window.SKIP_TITLE_REWRITE ) { return; }	var titleDiv = document.getElementById( 'title-meta' ); if( titleDiv == null ) { return; }	var cloneNode = titleDiv.cloneNode( true ); var firstHeading = getFirstHeading; var node = firstHeading.childNodes[0]; // new, then old! firstHeading.replaceChild( cloneNode, node ); cloneNode.style.display = 'inline'; var titleAlign = document.getElementById( 'title-align' ); firstHeading.style.textAlign = titleAlign.childNodes[0].nodeValue; } addOnloadHook( rewriteTitle ); // END JavaScript title rewrite