fix(landing-page): js error (#187)
This commit is contained in:
parent
f86253d66f
commit
7bf0df9ec9
4 changed files with 26 additions and 25 deletions
|
@ -40,7 +40,7 @@ import { Icon } from "astro-icon";
|
||||||
const copyCommandButton = document.getElementById("copy-command-button");
|
const copyCommandButton = document.getElementById("copy-command-button");
|
||||||
const commandText = document.getElementById("command").innerText;
|
const commandText = document.getElementById("command").innerText;
|
||||||
|
|
||||||
copyCommandButton.addEventListener("click", () => {
|
copyCommandButton?.addEventListener("click", () => {
|
||||||
navigator.clipboard.writeText(commandText);
|
navigator.clipboard.writeText(commandText);
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
|
@ -90,15 +90,15 @@ const socials = [
|
||||||
MicroModal.close(menuModalId);
|
MicroModal.close(menuModalId);
|
||||||
};
|
};
|
||||||
|
|
||||||
openNavButton.addEventListener("click", openMenu);
|
openNavButton?.addEventListener("click", openMenu);
|
||||||
closeNavButton.addEventListener("click", closeMenu);
|
closeNavButton?.addEventListener("click", closeMenu);
|
||||||
|
|
||||||
document.addEventListener("scroll", () => {
|
document?.addEventListener("scroll", () => {
|
||||||
const d = page.clientHeight - page.scrollTop - header.offsetHeight;
|
const d = page.clientHeight - page.scrollTop - header.offsetHeight;
|
||||||
header.classList.toggle("fixed-header", d < 0);
|
header.classList.toggle("fixed-header", d < 0);
|
||||||
});
|
});
|
||||||
|
|
||||||
menu.addEventListener("click", (event) => {
|
menu?.addEventListener("click", (event) => {
|
||||||
if ((event.target as HTMLElement).tagName === "A") {
|
if ((event.target as HTMLElement).tagName === "A") {
|
||||||
closeMenu();
|
closeMenu();
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ import { Icon } from "astro-icon";
|
||||||
.classList.remove("hidden");
|
.classList.remove("hidden");
|
||||||
};
|
};
|
||||||
|
|
||||||
button.addEventListener("click", () => {
|
button?.addEventListener("click", () => {
|
||||||
const themeNext = getThemeNext();
|
const themeNext = getThemeNext();
|
||||||
document.documentElement.dataset.theme = themeNext;
|
document.documentElement.dataset.theme = themeNext;
|
||||||
localStorage.setItem("theme", themeNext);
|
localStorage.setItem("theme", themeNext);
|
||||||
|
|
|
@ -52,27 +52,28 @@ const description =
|
||||||
|
|
||||||
<!-- initialize theme -->
|
<!-- initialize theme -->
|
||||||
<script is:inline>
|
<script is:inline>
|
||||||
const themeSaved = localStorage.getItem("theme");
|
document.documentElement.dataset.theme = themeSaved;
|
||||||
const forceTheme = "dark";
|
// const themeSaved = localStorage.getItem("theme");
|
||||||
|
// const forceTheme = "dark";
|
||||||
|
|
||||||
if (themeSaved) {
|
// if (themeSaved) {
|
||||||
document.documentElement.dataset.theme = themeSaved;
|
// document.documentElement.dataset.theme = themeSaved;
|
||||||
} else {
|
// } else {
|
||||||
// const prefersDark = window.matchMedia(
|
// // const prefersDark = window.matchMedia(
|
||||||
// "(prefers-color-scheme: dark)"
|
// // "(prefers-color-scheme: dark)"
|
||||||
// ).matches;
|
// // ).matches;
|
||||||
document.documentElement.dataset.theme = forceTheme; // prefersDark ? "dark" : "light";
|
// document.documentElement.dataset.theme = forceTheme; // prefersDark ? "dark" : "light";
|
||||||
}
|
// }
|
||||||
|
|
||||||
window
|
// window
|
||||||
.matchMedia("(prefers-color-scheme: dark)")
|
// .matchMedia("(prefers-color-scheme: dark)")
|
||||||
.addEventListener("change", (event) => {
|
// ?.addEventListener("change", (event) => {
|
||||||
if (!localStorage.getItem("theme")) {
|
// if (!localStorage.getItem("theme")) {
|
||||||
document.documentElement.dataset.theme = event.matches
|
// document.documentElement.dataset.theme = event.matches
|
||||||
? "dark"
|
// ? "dark"
|
||||||
: "light";
|
// : "light";
|
||||||
}
|
// }
|
||||||
});
|
// });
|
||||||
</script>
|
</script>
|
||||||
</head>
|
</head>
|
||||||
<body
|
<body
|
||||||
|
|
Loading…
Reference in a new issue