From adfd94001b80c5f474dee3b493da4111f77569c8 Mon Sep 17 00:00:00 2001 From: tophf Date: Thu, 13 Jan 2022 13:51:32 +0300 Subject: [PATCH] implement messageBox.close() --- js/dlg/message-box.js | 33 +++++++++++++++------------------ manage/manage.js | 3 +-- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/js/dlg/message-box.js b/js/dlg/message-box.js index 423c39a3..c3e446b3 100644 --- a/js/dlg/message-box.js +++ b/js/dlg/message-box.js @@ -12,6 +12,19 @@ window.messageBox = { _resolve: null, }; +messageBox.close = async isAnimated => { + window.off('keydown', messageBox.listeners.key, true); + window.off('scroll', messageBox.listeners.scroll); + window.off('mouseup', messageBox.listeners.mouseUp); + window.off('mousemove', messageBox.listeners.mouseMove); + if (isAnimated) { + await animateElement(messageBox.element, 'fadeout'); + } + messageBox.element.remove(); + messageBox.element = null; + messageBox._resolve = null; +}; + /** * @param {Object} params * @param {String} params.title @@ -143,9 +156,7 @@ messageBox.show = async ({ function resolveWith(value) { setTimeout(messageBox._resolve, 0, value); - unbindGlobalListeners(); - animateElement(messageBox.element, 'fadeout') - .then(removeSelf); + messageBox.close(true); if (messageBox.element.contains(document.activeElement)) { messageBox._originalFocus.focus(); } @@ -153,8 +164,7 @@ messageBox.show = async ({ function createElement() { if (messageBox.element) { - unbindGlobalListeners(); - removeSelf(); + messageBox.close(); } const id = 'message-box'; messageBox.element = @@ -186,19 +196,6 @@ messageBox.show = async ({ } window.on('keydown', messageBox.listeners.key, true); } - - function unbindGlobalListeners() { - window.off('keydown', messageBox.listeners.key, true); - window.off('scroll', messageBox.listeners.scroll); - window.off('mouseup', messageBox.listeners.mouseUp); - window.off('mousemove', messageBox.listeners.mouseMove); - } - - function removeSelf() { - messageBox.element.remove(); - messageBox.element = null; - messageBox._resolve = null; - } }; /** diff --git a/manage/manage.js b/manage/manage.js index 3e169e81..3e574c1f 100644 --- a/manage/manage.js +++ b/manage/manage.js @@ -159,8 +159,7 @@ function EmbedDialog(create) { }); shown = true; } else if (!state && shown) { - // FIXME: close the dialog - // messageBoxProxy.close(); + messageBoxProxy.close(); shown = false; } }