Allow the destruction of dialogs
authorAlexander Ebert <ebert@woltlab.com>
Tue, 6 Jun 2017 21:53:58 +0000 (23:53 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 6 Jun 2017 21:54:47 +0000 (23:54 +0200)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Dialog.js

index a04e1ba9da6175cddc573771b70f6698787b0b9c..0cb1ce245653459b5445ecf35316fee8760e22e0 100644 (file)
@@ -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() {