/
oldapp.js
90 lines (66 loc) · 1.66 KB
/
oldapp.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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var workTime = 25.00;
var breakTime = 5.00;
var breaking = false;
var working = true;
$(document).ready(function(){
function getTimeRemaining(endtime){
var minutes = endtime;
var seconds = endtime * 60;
var secondsCounter = 0;
return {
'minutes': minutes,
'seconds': seconds
};
}
// Initialize the clock
function initializeClock(id, endtime){
var clock = $('#timeRemaining');
clock.text(workTime);
var minutesDiv = $('.minutes');
var secondsDiv = $('.seconds');
// Should display the updated time every second
function updateClock(){
var t = getTimeRemaining(endtime);
// These should display the time in the clock, but aren't working
clock.text = ('0' + t.minutes).slice(-2);
clock.text = ('0' + t.seconds).slice(-2);
console.log(t.seconds);
if (t.seconds <= 0) {
clearInterval(timeInterval);
}
}
updateClock();
var timeInterval = setInterval(updateClock, 1000);
}
initializeClock('#timeRemaining', workTime);
if(workTime === 0){
breaking = true;
initializeClock('#timeRemaining', breakTime);
}
// Add/subtract time to break
$('#subtractBreakMinute').click(function(){
if(breakTime > 0) {
breakTime -= 1;
$('#breakDisplay').text(breakTime);
}
})
$('#addBreakMinute').click(function(){
if(breakTime < 59) {
breakTime += 1;
$('#breakDisplay').text(breakTime);
}
})
// Add/subtract time to workTime
$('#subtractSessionMinute').click(function(){
if(workTime > 0) {
workTime -= 1;
$('#sessionDisplay').text(workTime);
}
})
$('#addSessionMinute').click(function(){
if(workTime < 59) {
workTime += 1;
$('#sessionDisplay').text(workTime);
}
})
});