♻️ Move home switcher JS to external file

This commit is contained in:
James Panther
2022-01-27 12:28:32 +11:00
parent cc3960cf2a
commit 15e67f5903
6 changed files with 31 additions and 23 deletions

Before

Width:  |  Height:  |  Size: 53 KiB

After

Width:  |  Height:  |  Size: 53 KiB

Before

Width:  |  Height:  |  Size: 25 KiB

After

Width:  |  Height:  |  Size: 25 KiB

+27
View File
@@ -0,0 +1,27 @@
function switchHomeLayout() {
const pageDiv = document.getElementById("page");
const profileDiv = document.getElementById("profile");
const layoutCode = document.querySelectorAll("code[id=layout]");
if (pageDiv.style.display === "none") {
pageDiv.style.display = "block";
profileDiv.style.display = "none";
layoutCode.forEach(function (el) {
el.innerText = "page";
});
} else {
pageDiv.style.display = "none";
profileDiv.style.display = "block";
layoutCode.forEach(function (el) {
el.innerText = "profile";
});
}
}
window.addEventListener("DOMContentLoaded", (event) => {
document.querySelectorAll("#switch-layout-button").forEach((button) =>
button.addEventListener("click", function (e) {
e.preventDefault();
switchHomeLayout();
})
);
});