From 0e4f68e7c9c0bc8b796db6a86e462b9cb1dc5e43 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Tue, 6 Jun 2017 23:53:58 +0200 Subject: [PATCH] Allow the destruction of dialogs --- .../files/js/WoltLabSuite/Core/Ui/Dialog.js | 44 +++++++++++++++++-- 1 file changed, 40 insertions(+), 4 deletions(-) diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js index a04e1ba9da..0cb1ce2456 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js @@ -563,12 +563,12 @@ define( throw new Error("Expected a valid dialog id, '" + id + "' does not match any active dialog."); } + elAttr(data.dialog, 'aria-hidden', 'true'); + if (typeof data.onClose === 'function') { data.onClose(id); } - elAttr(data.dialog, 'aria-hidden', 'true'); - // get next active dialog _activeDialog = null; for (var i = 0; i < _container.childElementCount; i++) { @@ -603,14 +603,50 @@ define( * @return {(object|undefined)} dialog data or undefined if element id is unknown */ getDialog: function(id) { + return _dialogs.get(this._getDialogId(id)); + }, + + /** + * Returns true for open dialogs. + * + * @param {(string|object)} id element id or callback object + * @return {boolean} + */ + isOpen: function(id) { + var data = this.getDialog(id); + return (data !== undefined && elAttr(data.dialog, 'aria-hidden') === 'false'); + }, + + /** + * Destroys a dialog instance. + * + * @param {(string|object)} id element id or callback object + */ + destroy: function(id) { + id = this._getDialogId(id); + if (this.isOpen(id)) { + this.close(id); + } + + _dialogs.delete(id); + }, + + /** + * Returns a dialog's id. + * + * @param {(string|object)} id element id or callback object + * @return {string} + * @protected + */ + _getDialogId: function(id) { if (typeof id === 'object') { var dialogData = _dialogObjects.get(id); if (dialogData !== undefined) { - id = dialogData.id; + return dialogData.id; } } - return _dialogs.get(id); + return id.toString(); }, _ajaxSetup: function() { -- 2.20.1