This repository has been archived by the owner on Aug 4, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
meeting-timer.js
170 lines (132 loc) · 4.18 KB
/
meeting-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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
var hrs = document.getElementById('hrs'),
mins = document.getElementById('mins'),
secs = document.getElementById('secs'),
hrsExist = document.getElementById('hrs-exist'),
minsExist = document.getElementById('mins-exist'),
hrsPlural = document.getElementById('hrs-plural'),
minsPlural = document.getElementById('mins-plural'),
secsPlural = document.getElementById('secs-plural'),
attendPlural = document.getElementById('attend-plural'),
control = document.getElementById('control'),
reset = document.getElementById('reset'),
end = document.getElementById('end'),
noMore = document.getElementById('no-more'),
whyNoMore = document.getElementById('why-no-more'),
mtPast = document.getElementById('mt-past-present'),
costPast = document.getElementById('cost-past-present'),
attendInput = document.getElementById('attendees'),
cost = document.getElementById('cost'),
seconds = 0, minutes = 0, hours = 0,
attendees = 2,
firstClick = true,
t;
// FUTURE: remove global variables. use array for time store.
function getInput() {
// TODO return an error to the user
if (attendInput.value === '') {
return attendees;
// ensure the input is a number
} else if (isNaN(Number(attendInput.value))) {
return attendees;
// no negative attendees
} else if (Number(attendInput.value) <= 0) {
return attendees;
// save the new value
} else if (Number(attendInput.value) === 1) {
attendPlural.textContent = "attendee";
attendees = attendInput.value;
} else {
attendPlural.textContent = "attendees";
attendees = attendInput.value;
}
}
function add() {
// TODO what to do with > 99 hours?
var tempsec, tempmin;
tempsec = seconds + Number(attendees); // 80 = 40 + 40
seconds = tempsec % 60; // 20 = 80 % 60
tempmin = minutes + Math.floor(tempsec / 60); // 1 = 80 / 60
minutes = tempmin % 60; // 1 = 1 % 60
hours = hours + Math.floor(tempmin / 60); // 0 = 1 / 60
hrs.textContent = hours;
mins.textContent = minutes;
secs.textContent = seconds;
if (hours >= 1) {
hrsExist.style.display = "inline";
hrsPlural.textContent = "hours";
if (hours === 1) {
hrsPlural.textContent = "hour";
}
}
if (minutes >= 1) {
minsExist.style.display = "inline";
minsPlural.textContent = "minutes";
if (minutes === 1) {
minsPlural.textContent = "minute";
}
}
if (seconds >= 1) {
secsPlural.textContent = "seconds";
if (seconds === 1) {
secsPlural.textContent = "second";
}
}
timer();
}
function timer() {
t = setTimeout(add, 1000);
}
// Button functions
control.onclick = function () {
if (control.className === "start") {
control.className = "stop";
control.textContent = "Pause meeting.";
cost.style.display = "block";
end.style.display = "block";
timer();
} else if (control.className === "new") {
hrs.textContent = "0";
mins.textContent = "0";
secs.textContent = "0";
seconds = 0; minutes = 0; hours = 0;
hrsExist.style.display = "none";
minsExist.style.display = "none";
cost.style.display = "none";
noMore.style.display = "none";
whyNoMore.style.display = "none";
mtPast.textContent = "I am in a meeting with";
costPast.textContent = "So far, this meeting has cost";
attendInput.value = 2;
attendees = 2;
control.textContent = "Start meeting.";
control.className = "start";
} else {
control.className = "start";
control.textContent = "Continue meeting."
clearTimeout(t);
}
}
end.onclick = function () {
clearTimeout(t);
mtPast.textContent = "I was in a meeting with";
costPast.textContent = "This meeting cost";
end.style.display = "none";
control.className = "new";
control.textContent = "New meeting.";
noMore.style.display = "block";
}
noMore.onclick = function () {
if (whyNoMore.className === "off") {
whyNoMore.className = "on";
whyNoMore.style.display = "block";
} else {
whyNoMore.className = "off";
whyNoMore.style.display = "none";
}
}
attendInput.onkeyup = function () {
getInput();
}
attendInput.onclick = function () {
this.select();
}