MediaWiki:Common.js

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

/* Main Page maintain link on shorter side */ if (mw.config.get('wgTitle') === 'Main Page') { function mainPageMaintain { var leftHeight = $('#featured').height + 10 + $('#poll').height + 10 + $('#shroom').height; var rightHeight = $('#news').height + 10 + $('#dyk').height; if ( rightHeight > leftHeight ) { $("#maintain-right").hide; $("#maintain-left").show; }	}	$(mainPageMaintain); }

/* Automatically add Aboutfile template to file upload description. Source: nl.wikipedia.org/wiki/MediaWiki:Common.js */ if (mw.config.get('wgCanonicalSpecialPageName') === 'Upload' && !document.getElementById('wpForReUpload') && !document.getElementsByClassName('mw-destfile-warning')[0] && !document.getElementsByClassName('error')[0]) { function loadAutoAboutfileTemplate { uploadDescription = document.getElementById('wpUploadDescription'); var doubleBracket = '{' + '{'; uploadDescription.value = doubleBracket + 'aboutfile\n|1=Subject of the image\n|2=Where you found the image\n|3=Artist\n|4=Describe edits, if any\n|5=Other versions (use file link)\n}}'; }	$(loadAutoAboutfileTemplate); }

/* Add a drop-down menu for CheckUser reasons */ if (mw.config.get('wgCanonicalSpecialPageName') === 'CheckUser') { function checkUserReasonMenu { var field = document.getElementById('checkreason'); var menu = 'Please select a reason... Routine new user check Suspected sockpuppet account Matching a vandal account Other '; field.outerHTML = menu; }	$(checkUserReasonMenu);

function checkUserOther(name) { if (name == 'Other') { var menu = document.getElementById('checkreason'); var field = ''; menu.outerHTML = field; }	} }

/* Auto-refresh button on Special:RecentChanges */ function setCookie(c_name, value, expiredays) { var exdate = new Date; exdate.setDate(exdate.getDate + expiredays); document.cookie = c_name + "=" + escape(value) + ((expiredays == null) ? "" : ";expires=" + exdate.toGMTString); } function getCookie(c_name) { if (document.cookie.length > 0) { c_start = document.cookie.indexOf(c_name + "="); if (c_start != -1) { c_start = c_start + c_name.length + 1; c_end = document.cookie.indexOf(";", c_start); if (c_end == -1) c_end = document.cookie.length; return unescape(document.cookie.substring(c_start, c_end)); }	}	return ""; } var ajaxPages = new Array("Special:RecentChanges"); var ajaxRCOverride = false; var rcRefresh = 30000; function ajaxRC { appTo = $(".firstHeading"); appTo.append('   AUTO-REFRESH:   '); $("#autoRefreshToggle").click(function {		setCookie("ajaxRC", $("#autoRefreshToggle").is(":checked") ? "on" : "off")		loadRCData	}); $("#autoRefreshProgress").hide; if (getCookie("ajaxRC") == "on" || ajaxRCOverride) { $("#autoRefreshToggle").attr("checked", "checked"); setTimeout("loadRCData;", rcRefresh); } } function loadRCData { if (!$("#autoRefreshToggle").is(":checked")) return; $('#autoRefreshProgress').show $(article).load(location.href + " " + article + " > *", function (data) {		$(article + " .mw-collapsible").makeCollapsible;		$('#autoRefreshProgress').hide		if ($("#autoRefreshToggle").is(":checked")) setTimeout("loadRCData;", rcRefresh);	}); } $(function {	article = "#bodyContent";	for (x in ajaxPages) {		if (mw.config.get('wgPageName') == ajaxPages[x] && $("#autoRefreshToggle").length == 0) ajaxRC;	} });

function setUpSynchTable { var tables = document.getElementsByClassName("awardsSynchronisedTable"); for (var k = 0; k < tables.length; k++) { var rows = tables[k].rows; for (var i = 0; i < rows.length; i++) { var cells = rows[i].cells; for (var j = 0; j < cells.length; j++) { cells[j].style.verticalAlign = "top"; var synchDiv = document.createElement("DIV"); synchDiv.style.position = "relative"; synchDiv.className = "synchDiv"; var childs = cells[j].childNodes; while (childs.length > 0) { synchDiv.appendChild(childs[0]); }       cells[j].appendChild(synchDiv); }   }  }  if (tables.length > 0) { document.onscroll = synchTableOnScroll; } }

function synchTableOnScroll { var divs = document.getElementsByClassName("synchDiv"); for (var i = 0; i < divs.length; i++) { var parent = divs[i].parentNode; var parentRect = parent.getBoundingClientRect; var offset; if (window.innerHeight > divs[i].offsetHeight) { offset = Math.min(Math.max(-1 * parentRect.top, 0), parent.clientHeight - divs[i].offsetHeight); } else { offset = Math.min(Math.max(-1 * parentRect.top / (parent.clientHeight - window.innerHeight) * (parent.clientHeight - divs[i].offsetHeight), 0), parent.clientHeight - divs[i].offsetHeight); }   divs[i].style.top = offset + "px"; } }

setUpSynchTable;

/****************************************************************************** * Shroom Youtube Popups                                                     * ******************************************************************************/

function shroomYoutubeController { var spans = document.getElementsByClassName("shroomYoutube");

if (spans.length == 0) { return; }

this.APIReady = false; this.APIContinue = function {}; onYouTubeIframeAPIReady = function { this.APIReady = true; this.APIContinue; }.bind(this); this.players = [];

var tag = document.createElement('script'); tag.src = "https://www.youtube.com/iframe_api"; var firstScriptTag = document.getElementsByTagName('script')[0]; firstScriptTag.parentNode.insertBefore(tag, firstScriptTag);

this.containerDiv = document.createElement("div"); this.containerDiv.className = "shroomYoutubeContainer"; var shadeDiv = document.createElement("div"); shadeDiv.className = "shroomYoutubeShade"; shadeDiv.onclick = this.hideContainer.bind(this); this.bgDiv = document.createElement("div"); this.bgDiv.className = "shroomYoutubeBg"; var throbber = document.createElement("div"); throbber.className = "shroomThrobber"; this.bgDiv.appendChild(throbber); var closeButton = document.createElement("div"); closeButton.className = "shroomYoutubeClose"; closeButton.onclick = this.hideContainer.bind(this); this.bgDiv.appendChild(closeButton); this.containerDiv.appendChild(shadeDiv); this.containerDiv.appendChild(this.bgDiv); document.body.appendChild(this.containerDiv);

for (var i = 0; i < spans.length; i++) { new shroomYoutubeInstance (this, spans[i]) } }

function shroomYoutubeInstance (parent, span) { this.parent = parent; this.span = span; this.link = this.span.getElementsByTagName("a")[0]; this.videoWrapper = document.createElement("div"); this.videoWrapper.class = "shroomYoutubeVideoWrapper"; parent.bgDiv.appendChild(this.videoWrapper); this.link.onclick = this.showWrapper.bind(this); }

shroomYoutubeInstance.prototype.showWrapper = function (e) { if (e.button == 0 &&     !e.ctrlKey &&      !e.altKey &&      !e.shiftKey) { if (!this.parent.APIReady) { this.parent.containerDiv.className="shroomYoutubeContainer visible"; this.parent.APIContinue = this.span.onclick; //should invoke this function again... return false; } else if (this.videoWrapper.firstChild == null) { this.videoWrapper.appendChild(document.createElement("div")); var player = new YT.Player(this.videoWrapper.firstChild, {       width: '420',        height: '315',        videoId: this.span.dataset.video,        events: {          'onReady': this.onPlayerReady.bind(this),          'onStateChange': this.onPlayerStateChange.bind(this)        }      }); this.parent.addPlayer(player); }   var visibles = this.parent.containerDiv.getElementsByClassName("visible"); while (visibles.length > 0) { visibles[0].className="shroomYoutubeVideoWrapper"; }   this.parent.containerDiv.className="shroomYoutubeContainer visible"; this.videoWrapper.className="shroomYoutubeVideoWrapper visible"; return false; } else { return true; } }

shroomYoutubeInstance.prototype.onPlayerStateChange = function (e) { switch (e.data) { case -1: case 0: case 5: this.span.className = "shroomYoutube stopState"; break; case 1: this.parent.pauseOthers(e); case 3: this.span.className = "shroomYoutube playState"; break; case 2: this.span.className = "shroomYoutube pauseState"; break; } }

shroomYoutubeInstance.prototype.onPlayerReady = function (e) { e.target.playVideo; }

shroomYoutubeController.prototype.pauseOthers = function(e) { for (var i = 0; i < this.players.length; i++) { if (this.players[i] != e.target) { this.players[i].pauseVideo; } } }

shroomYoutubeController.prototype.hideContainer = function { this.containerDiv.className="shroomYoutubeContainer"; }

shroomYoutubeController.prototype.addPlayer = function (player) { this.players.push(player); }

new shroomYoutubeController ;

/** pollspinner ***************************************************************** * * description: this shows every awards poll to a user on the main page * maintainers: 2257 */

function pollspinner_boxSetup(nextPoll) {

var spinner = document.getElementsByClassName("pollspinner")[0]; spinner.className = "pollspinner animated throbbing";

var pollSubstitute = nextPoll.getElementsByClassName("pollspinner_poll")[0]; pollSubstitute.id = "PDI_container" + pollSubstitute.dataset.pollid;

while (pollSubstitute.childNodes.length > 0) { pollSubstitute.removeChild(pollSubstitute.childNodes[0]); }

this['pd_callback_' + pollSubstitute.dataset.pollid] = pollspinner_callback;

var pdscript = document.createElement("script"); pdscript.type = "text/javascript"; pdscript.language = "javascript"; pdscript.src = "http://s3.polldaddy.com/p/" + pollSubstitute.dataset.pollid + ".js"; pdscript.onload = function {

var spinner = document.getElementsByClassName("pollspinner")[0]; spinner.className = "pollspinner animated"; pollspinner_hideCurrent;

var votebuttonOuter = nextPoll.getElementsByClassName("pds-votebutton-outer")[0]; var skip = document.createElement("a"); skip.className = "pds-vote-button pollspinner_skip"; skip.appendChild(document.createTextNode("Skip")); skip.addEventListener("click", pollspinner_skip.bind(null, spinner)); votebuttonOuter.insertBefore(skip, votebuttonOuter.getElementsByClassName("pds-vote-button")[0].nextSibling);

var pdsBoxTop = nextPoll.getElementsByClassName("pds-box-top")[0]; var throbber = document.createElement("div"); throbber.className = "throbber"; throbber.appendChild(document.createTextNode("Loading next poll...")); pdsBoxTop.appendChild(throbber);

nextPoll.dataset.loaded = true; spinner.style.height = nextPoll.offsetHeight + "px"; nextPoll.className = "pollspinnerbox active"; }   pollSubstitute.appendChild(pdscript);

}

function pollspinner_hideCurrent { var spinner = document.getElementsByClassName("pollspinner")[0]; var activeBoxes = spinner.getElementsByClassName("pollspinnerbox active"); if (activeBoxes.length > 0) { activeBoxes[0].className = "pollspinnerbox answered"; } }

function pollspinner_getNext { var spinner = document.getElementsByClassName("pollspinner")[0];

var unansweredPolls = spinner.getElementsByClassName("pollspinnerbox unanswered"); var skippedPolls = spinner.getElementsByClassName("pollspinnerbox skipped"); if (unansweredPolls.length > 0) { var nextPoll = Math.floor(Math.random * unansweredPolls.length); if (unansweredPolls[nextPoll].dataset.loaded) { pollspinner_hideCurrent; spinner.style.height = unansweredPolls[nextPoll].offsetHeight + "px"; unansweredPolls[nextPoll].className = "pollspinnerbox active"; } else { pollspinner_boxSetup(unansweredPolls[nextPoll]); }   } else if (skippedPolls.length > 0) { while (skippedPolls.length > 0) { skippedPolls[0].className = "pollspinnerbox unanswered"; }

pollspinner_getNext; } else {

pollspinner_hideCurrent; var end = spinner.getElementsByClassName("pollspinnerend"); end[0].className = "pollspinnerend active"; if (mw.config.get("wgUserName") == null) { end[0].innerHTML = "The power of the Votes is restored to the poll... and it's all thanks to you! Thank you!"; } else { end[0].innerHTML = mw.config.get("wgUserName") + "! The power of the Votes is restored to the poll... and it's all thanks to you! Thank you, " + mw.config.get("wgUserName") + "!"; }       spinner.style.height = end[0].offsetHeight + "px"; } }

function pollspinner_callback( json ) { var obj = jQuery.parseJSON( json ); if ( obj.result == 'registered' || obj.result == 'already-registered' ) { var spinner = document.getElementsByClassName("pollspinner")[0];

var pdsBoxTop = document.getElementsByClassName("pollspinnerbox active")[0].getElementsByClassName("pds-box-top")[0]; var throbber = document.createElement("div"); throbber.className = "throbber"; throbber.appendChild(document.createTextNode("Loading next poll...")); pdsBoxTop.appendChild(throbber);

pollspinner_getNext; } }

function pollspinner_skip (spinner) {

var activePoll = spinner.getElementsByClassName("pollspinnerbox active"); if (activePoll.length > 0) { activePoll[0].className = "pollspinnerbox skipped"; pollspinner_getNext; } }

function pollspinner_setup { var spinner = document.getElementsByClassName("pollspinner")[0]; if (spinner != null) { var preload = new Image; preload.src = "http://wiki.userpedia.net/images/8/82/Pollthrobber.png"; spinner.className = "pollspinner animated"; var pollSpinnerBoxes = spinner.getElementsByClassName("pollspinnerbox"); for (var i = 0; i < pollSpinnerBoxes.length; i++) { pollSpinnerBoxes[i].className = "pollspinnerbox unanswered" }

var end = document.createElement("div"); end.className = "pollspinnerend"; spinner.appendChild(end); pollspinner_getNext;

} }

pollspinner_setup;