2020-05-08 13:27:44 +00:00
|
|
|
// auxiliary function closes the user profile menu
|
|
|
|
function closeUserControls() {
|
|
|
|
let userControls = document.querySelector("#user-controls");
|
|
|
|
if (userControls) userControls.removeAttribute("open");
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeLeftMenu() {
|
|
|
|
let leftMenu = document.querySelector("#main__menu");
|
|
|
|
if (leftMenu) leftMenu.removeAttribute("open");
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeRightMenu() {
|
|
|
|
let rightMenu = document.querySelectorAll(".jsRightMenu");
|
|
|
|
if (Array.from(rightMenu).filter(el => el.hasAttribute("open")).length > 0) {
|
|
|
|
Array.from(document.querySelectorAll(".views-container")).forEach(vC =>
|
|
|
|
vC.classList.toggle("sidebar-is-closed")
|
|
|
|
);
|
|
|
|
Array.from(rightMenu).forEach(el => el.removeAttribute("open"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function openRightMenu() {
|
|
|
|
let rightMenu = document.querySelectorAll(".jsRightMenu");
|
|
|
|
Array.from(rightMenu).forEach(el => el.setAttribute("open", ""));
|
|
|
|
Array.from(document.querySelectorAll(".views-container")).forEach(vC =>
|
|
|
|
vC.classList.toggle("sidebar-is-closed")
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2020-08-24 12:50:22 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", function() {
|
2020-05-08 13:27:44 +00:00
|
|
|
|
|
|
|
//- View change event
|
2020-08-24 12:50:22 +00:00
|
|
|
window.addEventListener("navigate", () => {
|
2020-05-08 13:27:44 +00:00
|
|
|
closeLeftMenu();
|
|
|
|
closeUserControls();
|
|
|
|
});
|
|
|
|
// Document -> close menu
|
|
|
|
document.addEventListener("click", event => {
|
|
|
|
if (!event.target.closest("#user-controls")) {
|
|
|
|
closeUserControls();
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!event.target.closest("#main__menu") &&
|
|
|
|
event.target.id != "toggleMainMenu"
|
|
|
|
) {
|
|
|
|
closeLeftMenu();
|
|
|
|
}
|
|
|
|
if (
|
|
|
|
!event.target.className.includes("jsMobileSidebarOpenButton") &&
|
|
|
|
!event.target.className.includes("jsOffsiteToggle")
|
|
|
|
) {
|
|
|
|
closeRightMenu();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
// listen for keypress
|
|
|
|
document.onkeydown = e => {
|
|
|
|
e = e || window.event;
|
|
|
|
if (e.key === "Escape" || e.key === "Esc") {
|
|
|
|
closeUserControls();
|
|
|
|
closeLeftMenu();
|
|
|
|
closeRightMenu();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2020-08-24 12:50:22 +00:00
|
|
|
document.querySelector("#toggleMainMenu").addEventListener("click", () => {
|
2020-05-08 13:27:44 +00:00
|
|
|
let leftMenu = document.querySelector("#main__menu");
|
|
|
|
if (leftMenu.hasAttribute("open")) {
|
|
|
|
closeLeftMenu();
|
|
|
|
} else {
|
|
|
|
leftMenu.setAttribute("open", "");
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
const rightMenus = Array.from(document.querySelectorAll("nav.jsRightMenu"));
|
|
|
|
rightMenus.forEach(rightMenu => {
|
|
|
|
const btnRightMenu = rightMenu.querySelector("li.jsOffsiteToggle");
|
2020-08-24 12:50:22 +00:00
|
|
|
btnRightMenu.addEventListener("click", () => {
|
2020-05-08 13:27:44 +00:00
|
|
|
if (rightMenu.hasAttribute("open")) {
|
|
|
|
closeRightMenu();
|
|
|
|
} else {
|
|
|
|
openRightMenu();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
Array.from(document.querySelectorAll(".jsMobileSidebarOpenButton")).forEach(
|
|
|
|
el => {
|
2020-08-24 12:50:22 +00:00
|
|
|
el.addEventListener("click", () => {
|
2020-05-08 13:27:44 +00:00
|
|
|
openRightMenu();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
);
|
|
|
|
});
|