-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
62 lines (58 loc) · 1.61 KB
/
script.js
File metadata and controls
62 lines (58 loc) · 1.61 KB
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
function formatTimeToString(min, sec) {
if (min < 10) {
min = "0" + min;
}
if (sec < 10) {
sec = "0" + sec;
}
return min + ":" + sec
}
function PresenTimer() {
this.passed = 0; //sec
this.timeout = 300; //sec
this.tick = function() {
this.passed++;
this.update();
}
this.update = function() {
var remaining = this.timeout - this.passed;
var min = Math.floor(remaining / 60);
var sec = remaining % 60;
fieldTime.firstChild.nodeValue = formatTimeToString(min, sec);
}
this.start = function() {
this.tod = setInterval("timer.tick()", 1000);
btnStartStop.setAttribute("onclick", "timer.stop()");
btnStartStop.setAttribute("value", "Stop");
}
this.reset = function() {
this.passed = 0;
this.update();
}
this.stop = function() {
clearInterval(this.tod);
this.tod = null;
btnStartStop.setAttribute("onclick", "timer.start()");
btnStartStop.setAttribute("value", "Start");
}
this.setTimeout = function(sec) {
this.timeout = sec;
this.update();
}
this.update();
}
function set() {
timer.setTimeout(inputTimeout.valueAsNumber / 1000);
}
var btnReset = document.getElementById("btn_reset");
btnReset.setAttribute("onclick", "timer.reset()");
var btnConfig = document.getElementById("btn_config");
btnConfig.setAttribute("onclick", "config()");
var btnStartStop = document.getElementById("btn_start-stop");
btnStartStop.setAttribute("onclick", "timer.start()");
var btnSet = document.getElementById("btn_set");
btnSet.setAttribute("onclick", "set()");
var fieldTime = document.getElementById("time");
var inputTimeout = document.getElementById("in_timeout");
var timer = new PresenTimer();
set();