2013-08-04 12:59:11 +02:00
|
|
|
function update_countdown() {
|
2013-10-26 12:59:39 +02:00
|
|
|
var time = projector.get_server_time().getTime() / 1000;
|
2013-08-04 12:59:11 +02:00
|
|
|
var seconds;
|
2013-10-22 00:15:45 +02:00
|
|
|
var minutes_digit;
|
|
|
|
var seconds_digit;
|
|
|
|
var hours_digit;
|
2013-08-04 12:59:11 +02:00
|
|
|
var start = projector.projector_countdown_start;
|
|
|
|
var duration = projector.projector_countdown_duration;
|
|
|
|
var pause = projector.projector_countdown_pause;
|
2013-10-26 12:59:39 +02:00
|
|
|
|
|
|
|
switch (projector.projector_countdown_state) {
|
2013-08-04 12:59:11 +02:00
|
|
|
case 'active':
|
|
|
|
seconds = start + duration - time;
|
|
|
|
break;
|
|
|
|
case 'paused':
|
|
|
|
seconds = start + duration - pause;
|
|
|
|
break;
|
|
|
|
case 'inactive':
|
|
|
|
seconds = duration;
|
|
|
|
break;
|
|
|
|
}
|
2013-10-26 12:59:39 +02:00
|
|
|
if (seconds > 60) {
|
2013-10-22 00:15:45 +02:00
|
|
|
hours_digit = Math.floor(seconds / 3600);
|
|
|
|
minutes_digit = Math.floor((seconds - (hours_digit * 3600)) / 60);
|
|
|
|
seconds_digit = Math.floor(seconds - (hours_digit * 3600) - (minutes_digit * 60));
|
|
|
|
minutes_digit = normalise(minutes_digit);
|
|
|
|
seconds_digit = normalise(seconds_digit);
|
2013-10-26 12:59:39 +02:00
|
|
|
if (hours_digit > 0) {
|
2013-10-22 00:15:45 +02:00
|
|
|
hours_digit = normalise(hours_digit);
|
|
|
|
seconds = hours_digit + ":" + minutes_digit + ":" + seconds_digit;
|
|
|
|
} else {
|
|
|
|
seconds = minutes_digit + ":" + seconds_digit;
|
|
|
|
}
|
|
|
|
} else {
|
2013-08-04 12:59:11 +02:00
|
|
|
seconds = Math.max(0, Math.floor(seconds));
|
2013-10-22 00:15:45 +02:00
|
|
|
}
|
2013-10-26 12:59:39 +02:00
|
|
|
|
2013-10-22 00:15:45 +02:00
|
|
|
if(seconds !== undefined) {
|
2013-08-04 12:59:11 +02:00
|
|
|
$('#overlay_countdown_inner').html(seconds);
|
|
|
|
}
|
|
|
|
setTimeout('update_countdown()', 200);
|
|
|
|
}
|
2013-10-26 12:59:39 +02:00
|
|
|
|
2013-08-04 12:59:11 +02:00
|
|
|
update_countdown();
|
2013-10-22 00:15:45 +02:00
|
|
|
|
|
|
|
function normalise(i) {
|
|
|
|
if(i < 10) {
|
|
|
|
i = "0" + i;
|
|
|
|
}
|
|
|
|
return i;
|
|
|
|
}
|
|
|
|
|