Skip to content

Commit

Permalink
add globalBrand to body class
Browse files Browse the repository at this point in the history
toggle function now adds global brand name as a class to the body, or removes it when not viewing a brand.
  • Loading branch information
thedannywahl committed Jan 5, 2024
1 parent 130e6f0 commit 10a56e6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
isp-site/.yarn/install-state.gz
23 changes: 15 additions & 8 deletions isp-site/src/components/toggle.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,34 @@
import { globalBrands } from "variables/brands";
const body = document.querySelector("body");

const toggle = (u, n) => {
n.forEach((e) => {
for (const e of n) {
e.removeAttribute("aria-current");
e.classList.remove("active");
});
}

if (u !== null && u.hash !== "#/") {
u.setAttribute("aria-current", "page");
u.classList.add("active");
}

//TODO ADD Brand to body classList
body.classList.remove(...globalBrands.map((brand) => brand.toLowerCase()));
if (u.id.length) body.classList.add(u.id);
};

document.addEventListener("DOMContentLoaded", function () {
document.addEventListener("DOMContentLoaded", () => {
let u = document.location.href.split("#")[1];
let n = document.querySelectorAll("nav a");
const n = document.querySelectorAll("nav a");

if (u !== undefined && u !== "/" && u !== null) {
u = document.getElementById(u.split("/")[1]);
toggle(u, n);
}

n.forEach((el) => {
el.onclick = function () {
toggle(el, n);
for (const e of n) {
e.onclick = () => {
toggle(e, n);
};
});
}
});

0 comments on commit 10a56e6

Please sign in to comment.