2014-01-14 23:22:29 +01:00
|
|
|
/*
|
|
|
|
* JavaScript functions for countdown.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
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-11-06 00:11:13 +01:00
|
|
|
var totalseconds;
|
|
|
|
var min;
|
|
|
|
var sec;
|
|
|
|
var negative;
|
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':
|
2013-11-06 00:11:13 +01:00
|
|
|
totalseconds = start + duration - time;
|
2013-08-04 12:59:11 +02:00
|
|
|
break;
|
|
|
|
case 'paused':
|
2013-11-06 00:11:13 +01:00
|
|
|
totalseconds = start + duration - pause;
|
2013-08-04 12:59:11 +02:00
|
|
|
break;
|
|
|
|
case 'inactive':
|
2013-11-06 00:11:13 +01:00
|
|
|
totalseconds = duration;
|
2013-08-04 12:59:11 +02:00
|
|
|
break;
|
|
|
|
}
|
2013-11-06 00:11:13 +01:00
|
|
|
totalseconds = Math.floor(totalseconds);
|
|
|
|
if (totalseconds < 0 ) {
|
|
|
|
totalseconds = -totalseconds;
|
|
|
|
negative = true;
|
2013-10-22 00:15:45 +02:00
|
|
|
}
|
2013-11-06 00:11:13 +01:00
|
|
|
min = Math.floor(totalseconds / 60);
|
|
|
|
sec = Math.floor(totalseconds - (min * 60));
|
|
|
|
if (sec < 10) {
|
|
|
|
sec = "0" + sec;
|
2013-08-04 12:59:11 +02:00
|
|
|
}
|
2013-11-06 00:11:13 +01:00
|
|
|
if (negative) {
|
|
|
|
min = "-" + min;
|
|
|
|
$('#overlay_countdown_inner').addClass('negative');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$('#overlay_countdown_inner').removeClass('negative');
|
|
|
|
}
|
|
|
|
if(totalseconds !== undefined) {
|
|
|
|
$('#overlay_countdown_inner').html(min + ":" + sec);
|
2013-10-22 00:15:45 +02:00
|
|
|
|
|
|
|
}
|
|
|
|
}
|
2013-11-06 00:11:13 +01:00
|
|
|
setInterval('update_countdown()', 200);
|