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) {
|
||||||
|
switchBtn.addEventListener("click", function () {
|
||||||
switchTheme()
|
switchTheme()
|
||||||
});
|
});
|
||||||
|
}
|
||||||
|
|
||||||
let settingBtn = document.getElementById("display-settings-switch");
|
let settingBtn = document.getElementById("display-settings-switch");
|
||||||
settingBtn!.addEventListener("click", function () {
|
if (settingBtn) {
|
||||||
|
settingBtn.addEventListener("click", function () {
|
||||||
let settingPanel = document.getElementById("display-setting");
|
let settingPanel = document.getElementById("display-setting");
|
||||||
settingPanel!.classList.toggle("float-panel-closed");
|
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) {
|
||||||
|
menuBtn.addEventListener("click", function () {
|
||||||
let menuPanel = document.getElementById("nav-menu-panel");
|
let menuPanel = document.getElementById("nav-menu-panel");
|
||||||
menuPanel!.classList.toggle("float-panel-closed");
|
if (menuPanel) {
|
||||||
|
menuPanel.classList.toggle("float-panel-closed");
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
loadButtonScript();
|
loadButtonScript();
|
||||||
|
|
Loading…
Reference in New Issue