Esc key close rightmenu
This commit is contained in:
parent
c5eb67b4d4
commit
d63ee9b6fb
@ -42,6 +42,12 @@ function recursiveAdaptWidgets(prefix, element, user) {
|
||||
});
|
||||
}
|
||||
|
||||
// auxiliary function closes the user profile menu
|
||||
function closeUserControls() {
|
||||
let userControls = document.querySelector('#user-controls');
|
||||
if (userControls) userControls.removeAttribute("open");
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function (event) {
|
||||
const menuWrappers = Array.from(document.querySelectorAll('.menu-wrapper'));
|
||||
const rightMenus = Array.from(document.querySelectorAll('nav.jsRightMenu'));
|
||||
@ -83,10 +89,13 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
||||
|
||||
// Document -> close menu
|
||||
document.addEventListener("click", event => {
|
||||
if (!event.target.closest('#user-controls')) {
|
||||
let userControls = this.querySelector('#user-controls');
|
||||
if (userControls) userControls.removeAttribute("open");
|
||||
}
|
||||
if (!event.target.closest('#user-controls')) closeUserControls();
|
||||
});
|
||||
|
||||
// listen for keypress
|
||||
document.onkeydown = (e) => {
|
||||
e = e || window.event;
|
||||
if (e.key === "Escape" || e.key === "Esc") closeUserControls();
|
||||
};
|
||||
|
||||
});
|
Loading…
Reference in New Issue
Block a user