Toggle menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Countdown.js: Difference between revisions

MediaWiki interface page
Content deleted Content added
ChaoticShadow (talk | contribs)
mNo edit summary
ChaoticShadow (talk | contribs)
mNo edit summary
Line 36: Line 36:
});
});


});
}());

Revision as of 04:09, 10 July 2021

$(function() {
	function calcDiff(d1, d2) {
		var remDiff = d2 - d1;
		var days = Math.floor(remDiff / (1000*60*60*24));
		remDiff = remDiff % (1000*60*60*24);
		var hours = Math.floor(remDiff / (1000*60*60));
		remDiff = remDiff % (1000*60*60);
		var minutes = Math.floor(remDiff / (1000*60));
		
		return { days: days, hours: hours, minutes: minutes };
	}
	
	var intervals = [];
	
	$('.js-countdown').each(function(idx) {
		var that = $(this);
		var d1 = new Date(that.data('event-end'));
		
		function updateHTML() {
			var diff = calcDiff(new Date(), d1);
			that.html(
				diff.days + ' days, ' + 
				diff.hours + ' hours, ' +
				diff.minutes + ' minutes'
			);
			if (diff.days <= 0 && diff.hours <= 0 && diff.minutes <= 0) {
				intervals[idx] = clearInterval(intervals[idx]);
				that.html('Event ended');
			}
		}
		updateHTML();
		var interval = setInterval(function() {
			updateHTML();
		}, 30000);
		intervals.push(interval);
	});

}());
Cookies help us deliver our services. By using our services, you agree to our use of cookies.