Merge branch 'esc-close-rightmenu' into 'staging'

Esc key close rightmenu

See merge request startinblox/applications/sib-app!82
This commit is contained in:
Jean-Baptiste Pasquier 2019-11-25 18:54:54 +00:00
commit 19bd61ae38

View File

@ -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();
};
});