summaryrefslogtreecommitdiffstats
path: root/static/functions/countdown.class.js
blob: bd6bd21a2c3b7e484bc2aec0c518f6ad781726f0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
/*
	TODO: Move to more efficient structure used in ajax.class.

	Example Usage:
	<script type="text/javascript">
		window.onload = freeleech;
		function freeleech() {
			count.end = 'The freeleech has ended!';
			count.event = 'The freeleech will end in';
			count.element = 'freeleech';
			count.update(<?=(time(3,0,0,9,22)-time());?>);
		}
	</script>
*/
"use strict";
var count = {
	update: function (Offset) {
		if (Offset < 0) {
			document.getElementById(this.element).innerHTML = this.end;
		} else {
			var Seconds = Offset % 60;
			if (Seconds < 10) {
				Seconds = '0' + Seconds;
			}
			var Remainder = (Offset - Seconds) / 60;
			var Minutes = Remainder % 60;
			if (Minutes < 10) {
				Minutes = '0' + Minutes;
			}
			Remainder = (Remainder - Minutes) / 60;
			var Hours = Remainder % 24;
			var Days = (Remainder - Hours) / 24;
			$(this.element).raw().innerHTML = this.event + ' ' + (Days > 0 ? Days + 'd, ' : '') + (Hours > 0 ? Hours + 'h, ' : '') + Minutes + 'm, ' + Seconds + 's.';
			setTimeout(function (object) {
				object.update(Offset - 1);
			}, 999, this);
		}
	}
};