-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
90 lines (74 loc) · 1.56 KB
/
script.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
const blocks = [
"0011",
"0101",
"0110",
"1001",
"1010",
"1100"
];
const grid = [
"012345",
"6789AB",
"CDEFGH",
"IJKLMN",
"OPQRST",
"UVWXYZ"
];
var short = document.createElement('img');
short.classList.add("stripe");
var long = short.cloneNode(true);
short.src = "assets/short.png";
long.src = "assets/long.png";
var topbar = document.getElementById("topbtns");
var botbar = document.getElementById("botbtns");
var toppart = 0;
var botpart = 0;
function btnclick(btn)
{
var block = parseInt(btn.getAttribute("block"));
var id = btn.parentElement.id;
if (id == "topbtns")
toppart = block;
else if (id == "botbtns")
botpart = block;
update();
}
function update()
{
document.getElementById("dp-result").innerText = grid[toppart][botpart];
document.getElementById("dp-kix").innerText = grid[toppart][botpart];
}
function reset()
{
toppart = botpart = 0;
update();
}
function clearbuffer()
{
document.getElementById("buffer").value = "";
}
function addchar()
{
document.getElementById("buffer").value += grid[toppart][botpart];
reset();
}
(function() {
for (var i = 0; i < blocks.length; i++)
{
var btn = document.createElement('button');
btn.classList.add("kixbtn");
btn.setAttribute("block", i);
btn.setAttribute("onclick", "btnclick(this)");
for (var c = 0; c < blocks[i].length; c++)
{
var char = blocks[i][c];
if (char == "0")
btn.appendChild(short.cloneNode(true));
else if (char == "1")
btn.appendChild(long.cloneNode(true));
}
topbar.appendChild(btn);
botbar.appendChild(btn.cloneNode(true));
}
update();
})();