Merge branch 'esc-close-rightmenu' into 'staging'
Esc key close rightmenu See merge request startinblox/applications/sib-app!82
This commit is contained in:
commit
19bd61ae38
@ -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) {
|
document.addEventListener('DOMContentLoaded', function (event) {
|
||||||
const menuWrappers = Array.from(document.querySelectorAll('.menu-wrapper'));
|
const menuWrappers = Array.from(document.querySelectorAll('.menu-wrapper'));
|
||||||
const rightMenus = Array.from(document.querySelectorAll('nav.jsRightMenu'));
|
const rightMenus = Array.from(document.querySelectorAll('nav.jsRightMenu'));
|
||||||
@ -83,10 +89,13 @@ document.addEventListener('DOMContentLoaded', function (event) {
|
|||||||
|
|
||||||
// Document -> close menu
|
// Document -> close menu
|
||||||
document.addEventListener("click", event => {
|
document.addEventListener("click", event => {
|
||||||
if (!event.target.closest('#user-controls')) {
|
if (!event.target.closest('#user-controls')) closeUserControls();
|
||||||
let userControls = this.querySelector('#user-controls');
|
|
||||||
if (userControls) userControls.removeAttribute("open");
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// 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