MediaWiki:Common.js
From EncyclopAtys
function hs(id,mod) {
if(document.getElementById(id).style.display == 'none') {
document.getElementById(id).style.display=mod;
}
else {
document.getElementById(id).style.display='none';
}
}
/** 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);
};
})();
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 = '/w/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', '/w/api.php?format=xml&action=query&prop=revisions&rvprop=ids&rvlimit=1&titles=' + diffTitle, true );
xmlHttp.send( null );
}
/** </nowiki> **/