forked from paulroub/tddmash
-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
93 lines (74 loc) · 2.41 KB
/
demo.html
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
<!DOCTYPE html>
<html>
<head>
<title>Clockwork demo</title>
<style>
html, body {
background-color: #000;
margin: 0;
padding: 0;
}
.clockboard {
color: #333;
font-family: consolas, 'courier new', courier, monospace;
font-size: min(7vw, 9vh);
margin: .5em auto;
padding: 1em;
text-align: center;
width: 10em;
}
b {
color: #FFF;
font-weight: bold;
}
p {
margin:0;
}
</style>
</head>
<body>
<div class=clockboard id=theclock></div>
<script src=clockwork.js></script>
<script>
const board = document.getElementById('theclock');
let clockwork = GetClockwork('en');
let english = true;
function showWords(words) {
board.innerHTML = '';
words.forEach(showRow);
}
function showRow(row) {
const line = document.createElement('p');
row.forEach((word) => {
showWord(word, line);
});
board.appendChild(line);
}
function showWord(word, line) {
let newWord = null;
if (clockwork.isHighlighted(word)) {
newWord = document.createElement('b');
newWord.innerHTML = clockwork.getText(word) + " ";
}
else {
newWord = document.createTextNode(clockwork.getText(word) + " ");
}
line.appendChild(newWord)
}
function showTime() {
const now = new Date();
const timeStr = clockwork.formatTime(new Date());
const words = clockwork.timeWords(timeStr);
const highlighted = clockwork.highlights(words);
showWords(highlighted);
}
setInterval(showTime, 1000);
showTime();
board.addEventListener('click', () => {
english = !english;
clockwork = GetClockwork(english ? 'en' : 'es');
showTime();
});
</script>
</body>
</html>