-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathselect.js
More file actions
61 lines (52 loc) · 1.6 KB
/
Copy pathselect.js
File metadata and controls
61 lines (52 loc) · 1.6 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
const cfg = document.forms[0];
const obj = document.querySelectorAll("object");
const svg = obj[0]; // main keyboard display
obj.forEach(item => {
item.addEventListener("load", () => {
item.parentNode.classList.add("loaded");
});
});
const selected = () => document.querySelector("#menu .selected");
drawKeys();
drawLabels();
async function setLayout(name) {
const response = await fetch(`layouts/${name}.json`);
const result = await response.json();
obj.forEach(view => {
view.contentWindow.setLayout(result.keymap);
});
}
const applyFlavor = () => {
const flavor = selected().id.substr(5);
const vim = document.getElementById("option-vim").checked;
const mac = document.getElementById("option-mac").checked;
svg.contentWindow.setConfig(flavor, vim, mac);
}
const applyConfig = () => {
const data = Object.fromEntries(new FormData(cfg));
setLayout(data.layout.toLowerCase());
svg.contentWindow.setGeometry(data.geometry);
applyFlavor();
};
svg.addEventListener("load", applyConfig);
cfg.addEventListener("change", applyConfig);
// layer views
const init = (name, layer3, layer4) => {
const view = document.querySelector(`object.${name}`);
view.addEventListener("load", () => {
view.contentWindow.setLayer3(layer3);
view.contentWindow.setLayer4(layer4);
})
};
init("sym", "", "sym");
init("nav", "nav", "");
init("fun", "fun", "");
init("vim", "vim", "num");
// menu
document.querySelectorAll("#menu tr").forEach((tr) => {
tr.addEventListener("click", (event) => {
selected().classList.remove("selected");
tr.classList.add("selected");
applyFlavor();
});
});