only close last popup with escape
This commit is contained in:
parent
75afe29f28
commit
9fee731cac
|
@ -22,6 +22,10 @@ export const POPUP_RESULT = {
|
|||
|
||||
|
||||
export class Popup {
|
||||
/**@type {Popup[]}*/
|
||||
static stack = [];
|
||||
|
||||
|
||||
/**@type {POPUP_TYPE}*/ type;
|
||||
|
||||
/**@type {HTMLElement}*/ dom;
|
||||
|
@ -119,11 +123,13 @@ export class Popup {
|
|||
const keyListener = (evt) => {
|
||||
switch (evt.key) {
|
||||
case 'Escape': {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this.completeCancelled();
|
||||
window.removeEventListener('keydown', keyListenerBound);
|
||||
break;
|
||||
if (Popup.stack.slice(-1)[0] == this) {
|
||||
evt.preventDefault();
|
||||
evt.stopPropagation();
|
||||
this.completeCancelled();
|
||||
window.removeEventListener('keydown', keyListenerBound);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -132,6 +138,7 @@ export class Popup {
|
|||
}
|
||||
|
||||
async show() {
|
||||
Popup.stack.push(this);
|
||||
document.body.append(this.dom);
|
||||
this.dom.style.display = 'block';
|
||||
switch (this.type) {
|
||||
|
@ -198,6 +205,7 @@ export class Popup {
|
|||
|
||||
|
||||
hide() {
|
||||
Popup.stack.splice(Popup.stack.indexOf(this), 1);
|
||||
$(this.dom).transition({
|
||||
opacity: 0,
|
||||
duration: animation_duration,
|
||||
|
|
Loading…
Reference in New Issue