-
Notifications
You must be signed in to change notification settings - Fork 6
/
timer.js
70 lines (61 loc) · 1.67 KB
/
timer.js
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
var timerSetUp = false;
var timerRunning = false;
var intervalRunning = false;
var seconds = 0;
var totalMinutes = 35;
function setUpTimer()
{
if (timerSetUp) { return; }
timerSetUp = true;
$("#slideInfo").after(' <span id="timerInfo"></span> <img id="progressIcon"/>');
$(document).keydown(function(event) {
var key = event.keyCode;
if (event.ctrlKey || event.altKey || event.metaKey) { return; }
if (key == 89) // y for timer
{
toggleTimer();
}
});
}
function toggleTimer()
{
if (!timerRunning) {
timerRunning = true
$("#timerInfo").text(timerStatus(0));
seconds = 0
if (!intervalRunning) {
intervalRunning = true
setInterval(function() {
if (!timerRunning) { return; }
seconds++;
$("#timerInfo").text(timerStatus(seconds));
}, 1000); // fire every minute
}
} else {
seconds = 0
timerRunning = false
$("#timerInfo").text('')
}
}
function timerStatus(seconds) {
var minutes = Math.round(seconds / 60);
var left = (totalMinutes - minutes);
var percent = Math.round((minutes / totalMinutes) * 100);
var progress = getSlidePercent() - percent;
setProgressIcon(progress);
return ' - (' + minutes + '/' + left + ':' + percent + '%)';
}
function setProgressIcon(progress) {
if(progress > 10) {
$('#progressIcon').attr('src', '/image/timer/flag_blue.png')
} else if (progress > 0) {
$('#progressIcon').attr('src', '/image/timer/flag_green.png')
} else if (progress > -10) {
$('#progressIcon').attr('src', '/image/timer/flag_yellow.png')
} else {
$('#progressIcon').attr('src', '/image/timer/flag_red.png')
}
}
$(function(){
setUpTimer();
});