Repository navigation
Expand file tree
/
Copy pathscript.js
More file actions
61 lines (52 loc) · 2.1 KB
/
Copy pathscript.js
File metadata and controls
61 lines (52 loc) · 2.1 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
// hide/show mobile menu
function toggleMenu() {
document.getElementById("site-nav").classList.toggle("open");
}
document.getElementById("menu-toggle").addEventListener("click", toggleMenu);
// hide newsletter component
// function hideNewsletter() {
// document.getElementById("newsletter").classList.add('closed');
// }
// document.getElementById("close-newsletter").addEventListener("click", hideNewsletter);
// switch between light/dark theme
var lightTheme;
if (typeof localStorage.lightTheme !== "undefined") {
lightTheme = JSON.parse(localStorage.lightTheme);
} else if (window.matchMedia("(prefers-color-scheme: light)").matches) {
lightTheme = true;
} else {
lightTheme = false;
}
function displayTheme() {
if (lightTheme) {
document.body.classList.add("light-theme");
} else {
document.body.classList.remove("light-theme");
}
}
function changeTheme() {
lightTheme = !lightTheme;
localStorage.lightTheme = lightTheme;
displayTheme();
}
document.getElementById("moon").addEventListener("click", changeTheme);
displayTheme();
// newsletter signup status (double opt-in flow, see netlify/functions)
var signupStatus = new URLSearchParams(window.location.search).get("signup");
var signupMessages = {
pending: "Check your inbox! We just sent you an email. Click the link and you're on the list.",
confirmed: "That's it, you're on the list. See you in your inbox!",
invalid: "That link didn't work (they expire after 48 hours). Sign up below and we'll send you a fresh one.",
error: "Something broke on our end. Give it another try in a few minutes.",
};
if (signupMessages[signupStatus]) {
var newsletter = document.getElementById("newsletter");
// named statusEl: a global named "status" collides with window.status, which stringifies the value
var statusEl = document.createElement("p");
statusEl.className = "signup-status";
statusEl.textContent = signupMessages[signupStatus];
newsletter.insertBefore(statusEl, newsletter.querySelector("form"));
if (signupStatus === "pending" || signupStatus === "confirmed") {
newsletter.querySelector("form").style.display = "none";
}
}