-
Notifications
You must be signed in to change notification settings - Fork 1
/
keyboard.js
73 lines (66 loc) · 2.68 KB
/
keyboard.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
keyboard = {
layouts: {
qwerty: ["qwertyuiop[]\\", "asdfghjkl;'", "zxcvbnm,./",
"QWERTYUIOP{}|", "ASDFGHJKL:\"", "ZXCVBNM<>?"],
workman: ["qdrwbjfup;[]\\", "ashtgyneoi'", "zxmcvkl,./",
"QDRWBJFUP:{}|", "ASHTGYNEOI\"", "ZXMCVKL<>?"]
},
buildTable: function(physical, logical) {
var phys = keyboard.layouts[physical];
var log = keyboard.layouts[logical];
if(!phys || !log)
return null
var table = {}
for(var i = 0; i < phys.length; i++)
for(j = 0; j < phys[i].length; j++)
table[phys[i][j]] = log[i][j];
return table;
},
updateTable: function() {
var phys = document.getElementById("layout-physical").value;
var log = document.getElementById("layout-logical").value;
var table = keyboard.buildTable(phys, log);
if(table)
keyTranslationTable = table;
},
toggleDummyInput: function() {
var dummyInput = document.getElementById("dummy-input");
var val = document.getElementById("show-dummy-input").checked;
if(val)
dummyInput.classList.remove("hidden");
else
dummyInput.classList.add("hidden");
},
toggleTwiddlerClass: function(checkbox, clas, inverted) {
var twiddlerDisplay = document.getElementById("twiddler-display");
var val = document.getElementById(checkbox).checked;
if(inverted)
val = !val;
if(val)
twiddlerDisplay.classList.add(clas);
else
twiddlerDisplay.classList.remove(clas);
},
rotateTwiddler: function() {
keyboard.toggleTwiddlerClass("show-twiddler", "hidden", true);
keyboard.toggleTwiddlerClass("rotate-twiddler", "rotated");
keyboard.toggleTwiddlerClass("mirror-twiddler", "mirrored");
keyboard.toggleTwiddlerClass("flip-twiddler", "flipped");
},
init: function() {
document.getElementById("layout-physical").addEventListener("change", keyboard.updateTable);
document.getElementById("layout-logical").addEventListener("change", keyboard.updateTable);
document.getElementById("rotate-twiddler").addEventListener("change", keyboard.rotateTwiddler);
document.getElementById("mirror-twiddler").addEventListener("change", keyboard.rotateTwiddler);
document.getElementById("flip-twiddler").addEventListener("change", keyboard.rotateTwiddler);
document.getElementById("show-twiddler").addEventListener("change", keyboard.rotateTwiddler);
document.getElementById("show-dummy-input").addEventListener("change", keyboard.toggleDummyInput);
keyTranslationTable = {};
keyboard.updateTable();
keyboard.rotateTwiddler();
keyboard.toggleDummyInput();
if(state.twiddlerBinConfig)
state.twiddlerLayout = new TwiddlerConfigV5(state.twiddlerBinConfig);
drawTwiddler();
}
}