-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
toggle function now adds global brand name as a class to the body, or removes it when not viewing a brand.
- Loading branch information
1 parent
130e6f0
commit 10a56e6
Showing
2 changed files
with
16 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; | ||
}); | ||
} | ||
}); |