MediaWiki:Common.js: Difference between revisions
Jump to navigation
Jump to search
(remove now-unused collapsible (use MediaWiki implementation)) |
(new countdown JS that doesn't broke the whole wiki) |
||
Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
$.fx.off = true; | $.fx.off = true; | ||
/* Super simple HTML countdown timer. Seriously, it couldn't get any simpler. | |||
* Written by Maru <maru@puella-magi.net>. Released under public domain. | |||
* Requires jQuery. | |||
* | |||
* <span class="countdown" data-until="2012/12/25 00:00:00"> | |||
* {DAY} days {HOUR} hours {MINUTE} minutes {SECOND} seconds | |||
* </span> | |||
*/ | |||
(function(self){ | |||
$.each(self, function(i, elem){ | |||
var elem = $(elem); | |||
var targetDate = new Date(elem.data('until')); | |||
var template = elem.html(); | |||
var counter = function(){ | |||
var text = template; | |||
var dateDiff = Math.floor((targetDate - new Date()) / 1000); | |||
$.each({ | |||
day: (Math.floor(dateDiff/86400) % 100000), | |||
hour: (Math.floor(dateDiff/3600) % 24), | |||
minute: (Math.floor(dateDiff/60) % 60), | |||
second: (Math.floor(dateDiff) % 60) | |||
}, function(k, v){ | |||
text = text.replace("{" + k.toUpperCase() + "}", v); | |||
}); | |||
elem.html(text); | |||
setTimeout(counter, 1000); | |||
} | |||
counter(); | |||
}); | |||
})($('.countdown')); |
Revision as of 16:10, 28 March 2012
/* Any JavaScript here will be loaded for all users on every page load. */ $.fx.off = true; /* Super simple HTML countdown timer. Seriously, it couldn't get any simpler. * Written by Maru <maru@puella-magi.net>. Released under public domain. * Requires jQuery. * * <span class="countdown" data-until="2012/12/25 00:00:00"> * {DAY} days {HOUR} hours {MINUTE} minutes {SECOND} seconds * </span> */ (function(self){ $.each(self, function(i, elem){ var elem = $(elem); var targetDate = new Date(elem.data('until')); var template = elem.html(); var counter = function(){ var text = template; var dateDiff = Math.floor((targetDate - new Date()) / 1000); $.each({ day: (Math.floor(dateDiff/86400) % 100000), hour: (Math.floor(dateDiff/3600) % 24), minute: (Math.floor(dateDiff/60) % 60), second: (Math.floor(dateDiff) % 60) }, function(k, v){ text = text.replace("{" + k.toUpperCase() + "}", v); }); elem.html(text); setTimeout(counter, 1000); } counter(); }); })($('.countdown'));