MediaWiki:Common.js

From Illogicopedia
(Redirected from IllogiCountry:Commojis)
Jump to navigation Jump to search

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/* 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);
	};
})();

// **************************************************
// Experimental javascript countdown timer (Splarka)
// Version 0.0.2
// **************************************************
// Embed with a span class="countdowntimer", eg:
// <span class="countdowntimer" style="display:none;">April 12 2008 00:00:01 AM EST</span>
// default replacement text can accompany, eg: <span class="notimer">*javascript required*</span>

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

	// catch negative dates
	if(diff<0) {
		diff = -diff;
		var left = ' ago since';
	} else {
		var left = ' until';
	}

	// calculate the diff
	left = (diff%60) + ' seconds ' + left;
	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 = left;

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

function checktimers() {
	var untimers = document.getElementsByClassName('notimer');
	for(var i=0;i < untimers.length; i++) {
		untimers[i].style.display = 'none';	
	}
	timers = document.getElementsByClassName('countdowntimer');  //global
	tim = new Array(); // generic holder for the timeouts, global
	if(timers.length == 0) return;
	for(var i=0;i < timers.length; i++) {
		timers[i].eventdate = new Date(timers[i].firstChild.nodeValue);
		timers[i].firstChild.nodeValue = '0 days 0 hours 0 minutes 0 seconds';
		timers[i].style.display = 'inline';
		updatetimer(i);  //start it up
	}
}
$(checktimers);

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


/** Username replace function ([[template:USERNAME]]) *******************************
 * Inserts user name into <span id="insertusername"></span>
 * By Splarka at Wikia common
 */

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")) {
			UserName.innerHTML = wgUserName;
		}
	}
}
$(UserNameReplace);

//Function to remove logo for {{nologo}}
function noLogo() {
	if (document.getElementById('nologo')) document.getElementById('p-logo').style.display = 'none';
}
$(noLogo);