tangled
alpha
login
or
join now
vielle.dev
/
site-archive
0
fork
atom
[Archived] Archived WIP of vielle.dev
0
fork
atom
overview
issues
pulls
pipelines
Update functionality of colour picker
vielle.dev
9 months ago
035ea6a3
ec1e043a
verified
This commit was signed with the committer's
known signature
.
vielle.dev
SSH Key Fingerprint:
SHA256:/4bvxqoEh9iMdjAPgcgAgXKZZQTROL3ULiPt6nH9RSs=
+15
-13
1 changed file
expand all
collapse all
unified
split
src
pages
blog
[id].astro
+15
-13
src/pages/blog/[id].astro
···
40
40
41
41
<h1>{title}</h1>
42
42
43
43
-
<button id="colour-toggle" style="display: none">
43
43
+
<button
44
44
+
aria-label="toggle colour scheme"
45
45
+
id="colour-toggle"
46
46
+
style="visibility: hidden"
47
47
+
>
44
48
<Sun data-mode-light />
45
49
<Moon data-mode-dark />
46
50
</button>
47
51
</heading>
48
48
-
<main data-colour-scheme-nojs style={`--accent: ${colour};`}>
52
52
+
<main style={`--accent: ${colour};`}>
49
53
<div class="content">
50
54
<Content />
51
55
</div>
···
53
57
</Base>
54
58
55
59
<script>
56
56
-
const els = document.querySelectorAll("main[data-colour-scheme-nojs]");
57
57
-
if (els.length !== 1)
58
58
-
throw new Error(
59
59
-
"No `main[data-colour-scheme-nojs]`` found, or multiple found",
60
60
-
);
61
61
-
const el = els[0];
62
62
-
if (!(el instanceof HTMLElement)) throw new Error("Not HTML Element!");
60
60
+
const root = document.querySelector(":root");
61
61
+
if (!(root instanceof HTMLElement)) throw new Error(":root is not html");
63
62
64
63
const button = document.getElementById("colour-toggle");
65
64
if (!button) throw new Error("No #colour-toggle element");
···
69
68
dark: document.querySelectorAll("[data-mode-dark]"),
70
69
};
71
70
72
72
-
delete el.dataset["colourSchemeNojs"];
71
71
+
console.log(modeToggled);
73
72
74
73
let lightMode = matchMedia("(prefers-color-scheme: light)").matches;
74
74
+
75
75
const updateColourScheme = () => {
76
76
+
root.style.colorScheme = lightMode ? "light" : "dark";
77
77
+
76
78
modeToggled[lightMode ? "light" : "dark"].forEach((el) => {
77
79
if (!(el instanceof SVGElement || el instanceof HTMLElement)) return;
78
80
el.style.display = "block";
79
81
});
82
82
+
80
83
modeToggled[!lightMode ? "light" : "dark"].forEach((el) => {
81
84
if (!(el instanceof SVGElement || el instanceof HTMLElement)) return;
82
85
el.style.display = "none";
83
86
});
84
84
-
el.dataset["mode"] = lightMode ? "light" : "dark";
85
87
};
88
88
+
86
89
updateColourScheme();
87
87
-
88
88
-
button.style.display = "block";
89
90
button.addEventListener("click", () => {
90
91
lightMode = !lightMode;
91
92
updateColourScheme();
92
93
});
94
94
+
button.style.visibility = "visible";
93
95
</script>
94
96
95
97
<!-- post content styles -->