Add indication of selected theme

This commit is contained in:
Gabriel Arazas 2022-06-13 17:06:29 +08:00
parent 97e08d0557
commit 85f99f2cd4
3 changed files with 39 additions and 14 deletions

View File

@ -20,6 +20,11 @@ and this project adheres to https://semver.org/spec/v2.0.0.html[Semantic Version
== Unreleased
=== Added
* Indicator for the selected theme in the dropdown menu.
=== Updated
* Minimum Go runtime version in `go.mod`.

View File

@ -103,6 +103,11 @@ footer[aria-label="Site footer"] {
color: var(--background);
cursor: pointer;
}
&--selected {
background: var(--base05);
color: var(--background);
};
}
.pagination {

View File

@ -65,20 +65,35 @@
</div>
</div>
</div>
<script defer>
const themeDropdown = document.querySelector('.site__theme-btn');
themeDropdown.addEventListener('click', (event) => {
const { target } = event;
if (target.classList.contains("site__theme-item")) {
if (target.dataset.theme) {
theme = target.dataset.theme;
window.localStorage.setItem("theme", theme);
document.documentElement.dataset.theme = theme;
} else {
window.localStorage.removeItem("theme");
delete document.documentElement.dataset.theme;
}
<script>
function styleTheme() {
const selectedTheme = window.localStorage.getItem("theme");
for (const el of document.querySelectorAll(".site__theme-item")) {
if (el.dataset.theme == selectedTheme) {
el.classList.add("site__theme-item--selected");
} else {
el.classList.remove("site__theme-item--selected");
}
});
}
}
const themeDropdown = document.querySelector('.site__theme-btn');
themeDropdown.addEventListener('click', (event) => {
const { target } = event;
if (target.classList.contains("site__theme-item")) {
if (target.dataset.theme) {
theme = target.dataset.theme;
window.localStorage.setItem("theme", theme);
document.documentElement.dataset.theme = theme;
} else {
window.localStorage.removeItem("theme");
delete document.documentElement.dataset.theme;
}
}
styleTheme();
});
styleTheme();
</script>
{{- end }}