forked from w3c/uievents
-
Notifications
You must be signed in to change notification settings - Fork 0
/
key-table-builder.js
69 lines (60 loc) · 1.88 KB
/
key-table-builder.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
/* Convert <key> tags into a proper <table> of key info.
* The document must be structured as follows:
* <div class="key-table">
* <key name="name">Key description.</key>
* ...
* </div>
* where:
* name: The name of the 'key' attribute.
* noid: (optional) Don't generate an id for this key.
*
* Multiple key-tables can be present in a single document.
*/
function create_key_tables() {
keytables = document.getElementsByClassName("key-table");
for (var i = 0; i < keytables.length; i++) {
create_key_table(keytables[i]);
}
}
function create_key_table(tablediv) {
var table = document.createElement('table');
table.setAttribute('class', 'data-table key-value-table');
var row = table.insertRow(-1);
var cell;
// Build the header row.
cell = document.createElement('th');
cell.setAttribute('width', '20%');
cell.appendChild(document.createTextNode('Key'));
row.appendChild(cell);
cell = document.createElement('th');
cell.setAttribute('width', '80%');
cell.appendChild(document.createTextNode('Typical Usage (Informative)'));
row.appendChild(cell);
while (tablediv.hasChildNodes()) {
var key = tablediv.removeChild(tablediv.firstChild);
if (key.nodeType != 1) {
continue;
}
var keyname = key.getAttribute('name');
var noid = key.getAttribute('noid');
row = table.insertRow(-1);
var code;
cell = row.insertCell(-1);
cell.setAttribute('class', 'key-table-key');
code = document.createElement('code');
if (noid == null)
code.id = 'key-' + keyname;
code.setAttribute('class', 'key');
code.appendChild(document.createTextNode("'" + keyname + "'"));
cell.appendChild(code);
cell = row.insertCell(-1);
while (key.hasChildNodes()) {
var child = key.removeChild(key.firstChild);
cell.appendChild(child);
}
}
tablediv.appendChild(table);
}
if (window.addEventListener) {
window.addEventListener('load', create_key_tables, false);
}