diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-12-15 12:59:39 -0800 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-12-15 12:59:39 -0800 |
commit | 76c7bf6c3ffbe4952b4cfd50443ff13745202605 (patch) | |
tree | a9e3f1d06c1ab5b9157dba1c7ca1510595d63e81 | |
parent | cf1470dcefb5952e463854fa58a942c0c717f4ff (diff) | |
parent | a4b7feabd3aa59bbd5523a8a199b0afbce070d7f (diff) | |
download | jquery-ui-76c7bf6c3ffbe4952b4cfd50443ff13745202605.tar.gz jquery-ui-76c7bf6c3ffbe4952b4cfd50443ff13745202605.zip |
Merge pull request #553 from AlbertoMonteiro/master
Dialog: When destroy is called place the element back in original DOM position. Fixed #4980 - Dialog: Destroy should place element back in original DOM position
-rw-r--r-- | tests/unit/dialog/dialog_tickets.js | 9 | ||||
-rw-r--r-- | ui/jquery.ui.dialog.js | 17 |
2 files changed, 23 insertions, 3 deletions
diff --git a/tests/unit/dialog/dialog_tickets.js b/tests/unit/dialog/dialog_tickets.js index b203ca7d5..f8ab8b423 100644 --- a/tests/unit/dialog/dialog_tickets.js +++ b/tests/unit/dialog/dialog_tickets.js @@ -140,4 +140,13 @@ test("#6966: Escape key closes all dialogs, not the top one", function(){ d1.remove(); }); +test("#4980: Destroy should place element back in original DOM position", function(){ + container = $('<div id="container"><div id="modal">Content</div></div>'); + modal = container.find('#modal'); + modal.dialog(); + ok(!$.contains(container[0], modal[0]), 'dialog should move modal element to outside container element'); + modal.dialog('destroy'); + ok($.contains(container[0], modal[0]), 'dialog(destroy) should place element back in original DOM position'); +}); + })(jQuery); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 3d7638667..1f959a837 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -77,8 +77,11 @@ $.widget("ui.dialog", { // #5742 - .attr() might return a DOMElement if ( typeof this.originalTitle !== "string" ) { this.originalTitle = ""; - } - + } + this.oldPosition = { + parent: this.element.parent(), + index: this.element.parent().children().index( this.element ) + }; this.options.title = this.options.title || this.originalTitle; var self = this, options = self.options, @@ -168,7 +171,8 @@ $.widget("ui.dialog", { }, _destroy: function() { - var self = this; + var self = this, next, + oldPosition = this.oldPosition; if ( self.overlay ) { self.overlay.destroy(); @@ -183,6 +187,13 @@ $.widget("ui.dialog", { if ( self.originalTitle ) { self.element.attr( "title", self.originalTitle ); } + + next = oldPosition.parent.children().eq( oldPosition.index ); + if ( next.length ) { + next.before( self.element ); + } else { + oldPosition.parent.append( self.element ); + } }, widget: function() { |