MediaWiki:Common.js

importArticles({	type: "script",	articles: [		"w:dev:DisableArchiveEdit/code.js", /* Discourage/disable the editing of talk page archives */		"w:runescape:MediaWiki:Common.js/standardeditsummaries.js", /* Standard edit summaries */		"MediaWiki:Common.js/wallgreetingbutton.js", /* Add a button to edit Message Wall Greeting */

/* ############################################# */ /* ##         CUSTOM EDIT BUTTONS            ## */ /* ############################################# */ if(mwCustomEditButtons) mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images2.wikia.nocookie.net/central/images/c/c8/Button_redirect.png", "speedTip": "Redirect", "tagOpen": "#REDIRECT ",		 "tagClose": "", "sampleText": "Insert text" }; if(mwCustomEditButtons) mwCustomEditButtons[mwCustomEditButtons.length] = { "imageFile": "http://images.wikia.com/godzilla/images/5/54/Wikia_Button_-_Category.png", "speedTip": "Category", "tagOpen": "Category:",		 "tagClose": "", "sampleText": "Insert text" };

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

// inserts user name into addOnloadHook(UserNameReplace);

function UserNameReplace { if(typeof(disableUsernameReplace) != 'undefined' && disableUsernameReplace) { return; } for(var i=0; UserName = document.getElementsByTagName("span")[i]; i++) { if ((document.getElementById('pt-userpage'))&&(UserName.getAttribute('id') == "insertusername")) { var ViewerName = document.getElementById('pt-userpage').firstChild.innerHTML; UserName.innerHTML = ViewerName; }   } }

function rewriteHover {	var gbl = document.getElementById("hover-global");

if(gbl == null) return;

var nodes = getElementsByClassName(gbl,'*','hoverable')

for (var i = 0; i < nodes.length; i++) {		nodes[i].onmouseover = function {			this.className += " over"; }

nodes[i].onmouseout = function {			this.className = this.className.replace(new RegExp(" over\\b"), ""); }	} }

function ContentLoader {		this.cache = true; }

ContentLoader.prototype.enableCache = function(caching) {		this.cache = (caching == null) ? true : this.cache; }

ContentLoader.prototype.createRequest = function {	if(typeof(XMLHttpRequest) != 'undefined') {		return new XMLHttpRequest; }	else if(typeof(ActiveXObject) != 'undefined') {		return new ActiveXObject("Msxml2.XMLHTTP"); }	return null; }

ContentLoader.prototype.send = function(url, postdata, contentType) {	var method = (postdata == null) ? 'GET' : 'POST'; this.request = this.createRequest; this.request.open(method, url);

if(!this.cache) this.request.setRequestHeader( "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT" );

var request = this.request; var loader = this; if(postdata == null) {			if(contentType == null) contentType = 'application/x-www-form-urlencoded'; request.setRequestHeader('Content-type', contentType); }	var f = function {			if(request.readyState == 4) {				loader.text = request.responseText; loader.document = request.responseXML; request = null; loader.request = null; loader.callback; }		}	this.request.onreadystatechange = f;	this.request.send(postdata); } /*	end ContentLoader

function replaceSearchIcon {	var innerDiv;

var searchbox = document.getElementById('searchBody');

if(searchbox) {		innerDiv = searchbox.getElementsByTagName('div')[0]; var link = innerDiv.getElementsByTagName('a')[0];

if(link) innerDiv.removeChild(link); }	else {		searchbox = getElementsByClassName(document.getElementById('searchBox'), 'div', 'r_boxContent')[0]; innerDiv = searchbox.getElementsByTagName('div')[1]; }	var loader = new ContentLoader; loader.div = innerDiv; loader.callback = onSearchIconsArrival; loader.send('/index.php?title=Template:Searchicons&action=raw'); }

function rand(n) {	return Math.round(Math.random * n); }

function onSearchIconsArrival {	var lines = this.text.split('\n'); var line = lines[rand(lines.length - 1)]; var pos = line.indexOf(' '); var link = document.createElement('div'); //	link.href = '/index.php?title=Special:Search&adv=1'; link.id = 'search-icon-wrapper'; var img = document.createElement('img'); img.alt = 'Search'; img.src = (pos == -1) ? line : line.substring(0, pos); link.appendChild(img); this.div.insertBefore(link, this.div.firstChild);

var div = document.createElement('div'); div.id = 'search-popup'; div.style.display = 'none'; var ul = document.createElement('ul'); var li; var a;

li = document.createElement('li'); a = document.createElement('a'); a.href = '/index.php?title=Special:Search&adv=1'; a.appendChild(document.createTextNode('Advanced search')); li.appendChild(a); ul.appendChild(li); li = document.createElement('li'); a = document.createElement('a'); a.href = (pos == -1) ? 'javascript:emptySearchDesc' : '/wiki/' + line.substring(pos + 1); a.appendChild(document.createTextNode("What's this? (" + ((pos == -1) ? 'NO DESCRIPTION' : line.substring(pos + 1)) + ')')); li.appendChild(a); ul.appendChild(li);

li = document.createElement('li'); a = document.createElement('a'); a.href = 'javascript:closeSearchPopup'; a.appendChild(document.createTextNode("Close")); li.appendChild(a); ul.appendChild(li);

div.appendChild(ul); document.getElementById('globalWrapper').appendChild(div);

link.onclick = openSearchPopup; }

function openSearchPopup(event) {	var div = document.getElementById('search-popup'); var e = event || window.event; div.style.display = (div.style.display == 'none') ? 'block' : 'none'; div.style.left = e.clientX + 'px'; div.style.top = (e.clientY + document.documentElement.scrollTop) + 'px'; }

function closeSearchPopup {	document.getElementById('search-popup').style.display = 'none'; }

function emptySearchDesc {	alert('No description exists for this search icon. Please contact the administrators to resolve this problem.'); }

function ContentLoader {		this.cache = true; }

// ************************************************** // End (Sikon's?) searchicon code // **************************************************

// ************************************************** // Experimental javascript countdown timer (Splarka) // Version 0.0.3 // ************************************************** // // Usage example: // //  Only January 01 2007 00:00:00 PST until New years. // //  Javascript disabled.

function updatetimer(i) { var now = new Date; var then = timers[i].eventdate; var diff = count=Math.floor((then.getTime-now.getTime)/1000);

// catch bad date strings if(isNaN(diff)) { timers[i].firstChild.nodeValue = '** ' + timers[i].eventdate + ' **' ; return; }

// determine plus/minus if(diff<0) { diff = -diff; var tpm = ' '; } else { var tpm = ' '; }

// calcuate the diff var left = (diff%60) + ' seconds'; diff=Math.floor(diff/60); if(diff > 0) left = (diff%60) + ' minutes ' + left; diff=Math.floor(diff/60); if(diff > 0) left = (diff%24) + ' hours ' + left; diff=Math.floor(diff/24); if(diff > 0) left = diff + ' days ' + left timers[i].firstChild.nodeValue = tpm + left;

// a setInterval is more efficient, but calling setTimeout // makes errors break the script rather than infinitely recurse timeouts[i] = setTimeout('updatetimer(' + i + ')',1000); }

function checktimers { //hide 'nocountdown' and show 'countdown' var nocountdowns = getElementsByClassName(document, 'span', 'nocountdown'); for(var i in nocountdowns) nocountdowns[i].style.display = 'none' var countdowns = getElementsByClassName(document, 'span', 'countdown'); for(var i in countdowns) countdowns[i].style.display = 'inline'

//set up global objects timers and timeouts. timers = getElementsByClassName(document, 'span', 'countdowndate'); //global timeouts = new Array; // generic holder for the timeouts, global if(timers.length == 0) return; for(var i in timers) { timers[i].eventdate = new Date(timers[i].firstChild.nodeValue); updatetimer(i); //start it up  } } addOnloadHook(checktimers);

// ************************************************** // - end -  Experimental javascript countdown timer // **************************************************