MediaWiki:Common.js

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

/* 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; }

/*	Source: http://www.dustindiaz.com/getelementsbyclass/ getElementsByClass, which complements getElementById and getElementsByTagName, returns an array of all subelements of node that are tagged with a specific CSS class (searchClass) and are of the tag name tag. If tag is null, it searches for any suitable elements regardless of the tag name. Example: getElementsByClass( 'infobox', document.getElementById( 'content' ), 'div' ) selects the same elements as the CSS declaration #content div.infobox 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 */

// BEGIN JavaScript title rewrite 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