-
Notifications
You must be signed in to change notification settings - Fork 10
/
options.js
189 lines (163 loc) · 4.93 KB
/
options.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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
// Event test options block
// Gary Kacmarcik - garykac@{gmail|google}.com
_column_info = [
["preventDefault", "pd_"],
["stopPropagation", "sp_"],
["ShowEvents", "show_"],
["Highlight", "hl_"],
];
function createOptions(options_div, event_info, table_info, extra) {
var table = document.createElement('table');
var row, cell;
table.classList.add("opttable");
row = document.createElement('tr');
for (var col of _column_info) {
var name = col[0];
var prefix = col[1];
cell = document.createElement('td');
cell.classList.add("optcell");
addOptionTitle(cell, name);
for (var event of event_info) {
var e = event[0];
var options = event[1][name];
if (name == "Highlight" && (options.enabled == undefined || options.enabled)) {
var classes = "event_hilight " + e.toLowerCase() + "_hilight";
if (options.class != undefined)
classes += " " + options.class;
options.class = classes;
}
options.onclick = 'onOptionClick(this)';
addOptionCheckbox(cell, prefix + e, e, options);
}
row.appendChild(cell);
}
cell = document.createElement('td');
cell.classList.add("optcell");
addOptionTitle(cell, "Show Fields");
for (var group of table_info) {
var name = group[0];
var type = group[1];
var options = group[3];
options.enabled = true;
options.class = type + "_header showfieldoption";
options.onclick = 'showFieldClick(this)';
if (name != "") {
addOptionCheckbox(cell, "show_" + type, name, options);
}
}
row.appendChild(cell);
table.appendChild(row);
if (extra != undefined && extra.length != 0) {
var addTitle = true;
for (var opt of extra) {
row = document.createElement('tr');
cell = document.createElement('td');
cell.classList.add("optcell");
cell.setAttribute("colspan", "5");
if (addTitle) {
addOptionTitle(cell, "General Options");
addTitle = false;
}
var type = opt[0];
if (type == "checkbox") {
var name = opt[1];
var label = opt[2];
var options = opt[3];
if (options.onclick === undefined) {
options.onclick = 'onOptionClick(this)';
}
addOptionCheckbox(cell, name, label, options);
} else if (type == "text") {
var text = opt[1];
cell.appendChild(document.createTextNode(text));
}
row.appendChild(cell);
table.appendChild(row);
}
}
options_div.appendChild(table);
}
function addOptionTitle(cell, title) {
var span = document.createElement('span');
span.classList.add("opttitle");
span.textContent = title;
cell.appendChild(span);
cell.appendChild(document.createElement("br"));
}
function addOptionCheckbox(cell, id, text, options) {
if (options.enabled === undefined)
options.enabled = true;
if (options.checked === undefined)
options.checked = true;
// Apply previously saved value (if any).
var savedValue = window.localStorage.getItem(id);
if (savedValue != null) {
options.checked = (savedValue == "true");
}
var input = document.createElement("input");
input.type = "checkbox";
input.id = id;
input.checked = options.checked;
input.disabled = !options.enabled;
if (options.onclick != undefined && options.onclick != "") {
input.setAttribute("onclick", options.onclick);
}
cell.appendChild(input);
var label = document.createElement("label");
label.setAttribute("for", id);
var span = document.createElement('span');
if (options.class !== undefined) {
for (var c of options.class.split(' ')) {
span.classList.add(c);
}
}
span.appendChild(document.createTextNode(text));
label.appendChild(span);
cell.appendChild(label);
cell.appendChild(document.createElement("br"));
}
function addOptionText(cell, prefix, id, text) {
var span1 = document.createElement('span');
span1.classList.add("opttext");
span1.appendChild(document.createTextNode(prefix));
var span2 = document.createElement('span');
span2.id = id;
span2.textContent = 0;
span1.appendChild(span2);
span1.appendChild(document.createTextNode(text));
cell.appendChild(span1);
cell.appendChild(document.createElement("br"));
}
function toggleOptions() {
var link = document.getElementById("optionsToggle");
var options = document.getElementById("options");
clearChildren(link);
if (options.style.display == "block") {
options.style.display = "none";
link.appendChild(document.createTextNode("Show Options"));
}
else {
options.style.display = "block";
link.appendChild(document.createTextNode("Hide Options"));
}
}
function onOptionClick(cb) {
window.localStorage.setItem(cb.id, cb.checked);
}
function showFieldClick(cb) {
onOptionClick(cb);
var celltype = cb.id.split('_')[1];
var show = cb.checked;
var table = document.getElementById("output");
for (var ir = 0, row; row = table.rows[ir]; ir++) {
for (var ic = 0, cell; cell = row.cells[ic]; ic++) {
if (cell.classList.contains(celltype)) {
if (show) {
cell.style.display = "";
} else {
cell.style.display = "none";
}
}
}
}
}