Repository navigation
Expand file tree
/
Copy pathresume.js
More file actions
76 lines (72 loc) · 2.18 KB
/
Copy pathresume.js
File metadata and controls
76 lines (72 loc) · 2.18 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Keys: every action has one. Theme choice is shared with STYLESHEET.html (same storage key).
// "auto" = no data-theme attribute: CSS follows the system dark/light setting live.
(function () {
var themes = ["auto", "dark", "light", "eink"];
var root = document.documentElement;
var jobs = function () {
return document.querySelectorAll("details.job, details.abs");
};
var current = function () {
return root.dataset.theme || "auto";
};
function setTheme(t) {
if (t === "auto") root.removeAttribute("data-theme");
else root.dataset.theme = t;
try {
if (t === "auto") localStorage.removeItem("tc-style-theme");
else localStorage.setItem("tc-style-theme", t);
} catch (e) {}
document.querySelectorAll("[data-theme-set]").forEach(function (b) {
b.setAttribute("aria-pressed", b.dataset.themeSet === t);
});
}
function setAll(open) {
jobs().forEach(function (d) {
d.open = open;
});
}
var act = {
t: function () {
setTheme(themes[(themes.indexOf(current()) + 1) % themes.length]);
},
e: function () {
setAll(true);
},
c: function () {
setAll(false);
},
p: function () {
window.print();
},
};
document.addEventListener("keydown", function (ev) {
if (ev.ctrlKey || ev.metaKey || ev.altKey) return;
var tag = (ev.target.tagName || "").toLowerCase();
if (tag === "input" || tag === "textarea") return;
if (act[ev.key]) act[ev.key]();
});
document.querySelectorAll("[data-act]").forEach(function (b) {
b.addEventListener("click", function () {
act[b.dataset.act]();
});
});
document.querySelectorAll("[data-theme-set]").forEach(function (b) {
b.addEventListener("click", function () {
setTheme(b.dataset.themeSet);
});
});
setTheme(current());
// print and PDF always show every entry, then restore the fold state
var state = [];
window.addEventListener("beforeprint", function () {
state = Array.prototype.map.call(jobs(), function (d) {
return d.open;
});
setAll(true);
});
window.addEventListener("afterprint", function () {
jobs().forEach(function (d, i) {
d.open = state[i];
});
});
})();