-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
65 lines (63 loc) · 2.04 KB
/
index.html
File metadata and controls
65 lines (63 loc) · 2.04 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
63
64
65
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Demo</title>
</head>
<body>
<h1>cm-web-modules</h1>
<h2>Stopwatch example</h2>
<p>
seconds: <span id="seconds-output">0</span><br/>
clock: <span id="clock-output">0</span><br/>
running: <span id="state-output">false</span>
</p>
<p>
<button id="button-start">Start</button>
<button id="button-stop">Stop</button>
<button id="button-reset">Reset</button>
</p>
<p id="debug-output">
</p>
<h2>Testing</h2>
<a href="test/index.html">Run tests</a>
<script type="module">
import {Stopwatch} from "./src/stopwatch/Stopwatch.js"
import {TextUtils} from "./src/utils/TextUtils.js"
const secondsOutput = document.getElementById("seconds-output")
const clockOutput = document.getElementById("clock-output")
const stateOutput = document.getElementById("state-output")
const debugOutput = document.getElementById("debug-output")
const stopwatch = new Stopwatch({
tickResolution: 10,
onStateChanged: (running) => {
stateOutput.innerText = running
debugInfo()
},
onTimeChanged: (seconds) => {
secondsOutput.innerText = seconds.toFixed(2)
clockOutput.innerText = TextUtils.formatTime(seconds * 1000, 1)
debugInfo()
}
})
function debugInfo() {
debugOutput.innerHTML = `
startDate: ${stopwatch.startDate}<br/>
endDate: ${stopwatch.endDate}<br/>
dateAtLatestStart: ${stopwatch.dateAtLatestStart}<br/>
secondsExpiredTillLastPause: ${stopwatch.secondsExpiredTillLastPause}<br/>
secondsExpiredSinceLastStart: ${stopwatch.secondsExpiredSinceLastStart}
`
}
document.getElementById("button-start").addEventListener("click", () => {
stopwatch.start()
})
document.getElementById("button-stop").addEventListener("click", () => {
stopwatch.stop()
})
document.getElementById("button-reset").addEventListener("click", () => {
stopwatch.reset()
})
</script>
</body>
</html>