MediaWiki:Common.js

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

// ================== // Countdown 2.0, rewrite by Pecoes // Original script by Splarka + Eladkse // ==================

'use strict'; var translations = $.extend(true, {       en: {            and: 'and',            second: 'second',            seconds: 'seconds',            minute: 'minute',            minutes: 'minutes',            hour: 'hour',            hours: 'hours',            day: 'day',            days: 'days'        }    }, module.translations || {}), i18n = translations[ mw.config.get('wgContentLanguage') ] || translations.en;
 * (function (module, mw, $) {

var countdowns = []; var NO_LEADING_ZEROS = 1; function output (i, diff) { /*jshint bitwise:false*/ var delta, result, parts = []; delta = diff % 60; parts.unshift(delta + ' ' + i18n[delta === 1 ? 'second' : 'seconds']); diff = Math.floor(diff / 60); delta = diff % 60; parts.unshift(delta + ' ' + i18n[delta === 1 ? 'minute' : 'minutes']); diff = Math.floor(diff / 60); delta = diff % 24; parts.unshift(delta + ' ' + i18n[delta === 1 ? 'hour'  : 'hours'  ]); diff = Math.floor(diff / 24); parts.unshift(diff + ' ' + i18n[diff  === 1 ? 'day'    : 'days'   ]); result = parts.pop; if (countdowns[i].opts & NO_LEADING_ZEROS) { while (parts.length && parts[0][0] === '0') { parts.shift; }       }        if (parts.length) { result = parts.join(', ') + ' ' + i18n.and + ' ' + result; }       countdowns[i].node.text(result); }   function end(i) { var c = countdowns[i].node.parent; switch (c.attr('data-end')) { case 'remove': c.remove; countdowns.splice(i, 1); return; case 'stop': output(i, 0); countdowns.splice(i, 1); return; case 'toggle': var toggle = c.attr('data-toggle'); if (toggle && $(toggle).length) { $(toggle).css('display', 'inline'); c.css('display', 'none'); countdowns.splice(i, 1); return; }               break; case 'callback': var callback = c.attr('data-callback'); if (callback && $.isFunction(module[callback])) { output(i, 0); countdowns.splice(i, 1); module[callback].call(c); return; }               break; }       countdowns[i].countup = true; output(i, 0); }   function update  { var now = Date.now; $.each(countdowns.slice(0), function (i, countdown) {           var diff = Math.floor((countdown.date - now) / 1000);            if (diff <= 0 && !countdown.countup) {                end(i);            } else {                output(i, Math.abs(diff));            }        }); if (countdowns.length) { window.setTimeout(function {                update;            }, 1000); }   }    function getOptions (node) { /*jshint bitwise:false*/ var text = node.parent.attr('data-options'), opts = 0; if (text) { if (/no-leading-zeros/.test(text)) { opts |= NO_LEADING_ZEROS; }       }        return opts; }   $(function  {        var countdown = $('.countdown');        if (!countdown.length) return;        $('.nocountdown').css('display', 'none');        countdown        .css('display', 'inline')        .find('.countdowndate')        .each(function  { var $this = $(this), date = (new Date($this.text)).valueOf; if (isNaN(date)) { $this.text('BAD DATE'); return; }           countdowns.push({                node: $this,                opts: getOptions($this),                date: date,            }); });       if (countdowns.length) {            update;        }    }); }(window.countdownTimer = window.countdownTimer || {}, mediaWiki, jQuery));

// ================== // Auto-refresh recent changes // Code used from KHWiki // ================== /* 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 openPage(phase,pageName,elmnt,color) { var i, tabcontent, tablinks, tilecontent; tabcontent = document.getElementById(phase).getElementsByClassName("tabcontent"); tilecontent = document.getElementsByClassName("series-nav")[0]; for (i = 0; i < tabcontent.length; i++) { tabcontent[i].style.display = "none"; }   tablinks = document.getElementById(phase).getElementsByClassName("tablink"); for (i = 0; i < tablinks.length; i++) { tablinks[i].style.backgroundColor = ""; }   document.getElementById(pageName).style.display = "block"; elmnt.style.backgroundColor = color; tilecontent.getElementsByClassName("tabbertab")[0].style.backgroundColor = color;

}

// Get the element with id="defaultOpen" and click on it var portalStart = document.getElementById("defaultOpen"); if (portalStart){ portalStart.click; }