fix: errors when `themeColor.fixed` is set to `true` (#160)
Prevent null errors in Navbar.astro by verifying DOM elements before attaching event listeners
This commit is contained in:
parent
075cb8e10a
commit
a6bc4c00b0
|
@ -84,21 +84,31 @@ function switchTheme() {
|
||||||
|
|
||||||
function loadButtonScript() {
|
function loadButtonScript() {
|
||||||
let switchBtn = document.getElementById("scheme-switch");
|
let switchBtn = document.getElementById("scheme-switch");
|
||||||
switchBtn!.addEventListener("click", function () {
|
if (switchBtn) {
|
||||||
switchTheme()
|
switchBtn.addEventListener("click", function () {
|
||||||
});
|
switchTheme()
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let settingBtn = document.getElementById("display-settings-switch");
|
let settingBtn = document.getElementById("display-settings-switch");
|
||||||
settingBtn!.addEventListener("click", function () {
|
if (settingBtn) {
|
||||||
let settingPanel = document.getElementById("display-setting");
|
settingBtn.addEventListener("click", function () {
|
||||||
settingPanel!.classList.toggle("float-panel-closed");
|
let settingPanel = document.getElementById("display-setting");
|
||||||
});
|
if (settingPanel) {
|
||||||
|
settingPanel.classList.toggle("float-panel-closed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let menuBtn = document.getElementById("nav-menu-switch");
|
let menuBtn = document.getElementById("nav-menu-switch");
|
||||||
menuBtn!.addEventListener("click", function () {
|
if (menuBtn) {
|
||||||
let menuPanel = document.getElementById("nav-menu-panel");
|
menuBtn.addEventListener("click", function () {
|
||||||
menuPanel!.classList.toggle("float-panel-closed");
|
let menuPanel = document.getElementById("nav-menu-panel");
|
||||||
});
|
if (menuPanel) {
|
||||||
|
menuPanel.classList.toggle("float-panel-closed");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadButtonScript();
|
loadButtonScript();
|
||||||
|
@ -119,4 +129,4 @@ async function loadPagefind() {
|
||||||
pagefind.search('') // speed up the first search
|
pagefind.search('') // speed up the first search
|
||||||
}
|
}
|
||||||
loadPagefind()
|
loadPagefind()
|
||||||
</script>}
|
</script>}
|
||||||
|
|
Loading…
Reference in New Issue