2013-02-22 08:00:24 +00:00
|
|
|
/*
|
2013-05-28 08:01:02 +00:00
|
|
|
TODO: Move to more efficient structure used in ajax.class.
|
2011-03-28 14:21:28 +00:00
|
|
|
|
|
|
|
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) {
|
2013-02-22 08:00:24 +00:00
|
|
|
document.getElementById(this.element).innerHTML = this.end;
|
2011-03-28 14:21:28 +00:00
|
|
|
} else {
|
2013-02-22 08:00:24 +00:00
|
|
|
var Seconds = Offset % 60;
|
2011-03-28 14:21:28 +00:00
|
|
|
if (Seconds < 10) {
|
|
|
|
Seconds = '0' + Seconds;
|
|
|
|
}
|
|
|
|
var Remainder = (Offset - Seconds) / 60;
|
2013-02-22 08:00:24 +00:00
|
|
|
var Minutes = Remainder % 60;
|
2011-03-28 14:21:28 +00:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|