-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathselect.js
More file actions
59 lines (50 loc) · 1.57 KB
/
select.js
File metadata and controls
59 lines (50 loc) · 1.57 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
const cfg = document.forms[0];
const obj = document.querySelectorAll("object");
const svg = obj[0]; // main keyboard display
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;
svg.contentWindow.setConfig(flavor, vim);
}
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();
});
});
// anchors
document.querySelectorAll("h2[id], h3[id]").forEach((heading) => {
heading.innerHTML = `${heading.innerHTML} <a href="#${heading.id}">#</a>`;
});