-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstyle_helpers.js
52 lines (45 loc) · 1.23 KB
/
style_helpers.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
window.style_helpers = (function () {
function style_generic_table(table) {
setStyles(table, {
border: "1px solid black",
borderCollapse: "collapse",
margin: "auto",
display: "block",
});
for (const th of table.querySelectorAll("th")) {
setStyles(th, {
padding: "4px",
position: "sticky",
top: "0px",
border: "1px solid black",
});
}
}
function style_generic_td(td) {
setStyles(td, {
border: "1px solid black",
padding: "4px",
});
return td;
}
function setStyles(elem, styles) {
const info = [];
const label = elem.id
? `#${elem.id}`
: elem.className
? `.${elem.className}`
: elem.tagName;
info.push(`\nSetting styles for ${label}\n`);
for (const [f, v] of Object.entries(styles)) {
info.push(` ${f}: ${v};`);
elem.style[f] = v;
}
// console.trace(info.join("\n"));
return elem;
}
return {
style_generic_table,
style_generic_td,
setStyles,
};
})();