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 = $('
'); + 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/tests/unit/menu/menu_events.js b/tests/unit/menu/menu_events.js index 79b98163b..9e68e0c67 100644 --- a/tests/unit/menu/menu_events.js +++ b/tests/unit/menu/menu_events.js @@ -93,12 +93,16 @@ asyncTest( "handle submenu auto collapse: mouseleave", function() { setTimeout(function() { equal( $menu.find( "ul[aria-expanded='true']" ).length, 2, "second submenu expanded" ); $menu.find( "ul[aria-expanded='true']:first" ).trigger( "mouseleave" ); - equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); - $menu.trigger( "mouseleave" ); - equal( $menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); - start(); - }, 400); - }, 200); + setTimeout(function() { + equal( $menu.find( "ul[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + $menu.trigger( "mouseleave" ); + setTimeout(function() { + equal( $menu.find( "ul[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + start(); + }, 1400); + }, 1050); + }, 700); + }, 350); }); asyncTest( "handle custom menu item submenu auto collapse: mouseleave", function() { @@ -112,17 +116,19 @@ asyncTest( "handle custom menu item submenu auto collapse: mouseleave", function setTimeout(function() { equal( $menu.find( "div[aria-expanded='true']" ).length, 2, "second submenu expanded" ); $menu.find( "div[aria-expanded='true']:first" ).trigger( "mouseleave" ); - equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); - - $menu.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); - ok( $menu.find( ".ui-state-active" ).is( "#menu5 :nth-child(7) a" ), - "down keypress selected an item from the first submenu" ); - - $menu.trigger( "mouseleave" ); - equal( $menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); - start(); - }, 400); - }, 200); + setTimeout(function() { + equal( $menu.find( "div[aria-expanded='true']" ).length, 1, "second submenu collapsed" ); + $menu.simulate( "keydown", { keyCode: $.ui.keyCode.DOWN }); + ok( $menu.find( ".ui-state-active" ).is( "#menu5 :nth-child(7) a" ), + "down keypress selected an item from the first submenu" ); + $menu.trigger( "mouseleave" ); + setTimeout(function() { + equal( $menu.find( "div[aria-expanded='true']" ).length, 0, "first submenu collapsed" ); + start(); + }, 1400); + }, 1050); + }, 700); + }, 350); }); diff --git a/ui/jquery.ui.autocomplete.js b/ui/jquery.ui.autocomplete.js index bd415aa2b..c054ba2dd 100644 --- a/ui/jquery.ui.autocomplete.js +++ b/ui/jquery.ui.autocomplete.js @@ -473,8 +473,8 @@ $.widget( "ui.autocomplete", { this.search( null, event ); return; } - if ( this.menu.first() && /^previous/.test(direction) || - this.menu.last() && /^next/.test(direction) ) { + if ( this.menu.isFirstItem() && /^previous/.test(direction) || + this.menu.isLastItem() && /^next/.test(direction) ) { this._value( this.term ); this.menu.blur(); return; 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() { diff --git a/ui/jquery.ui.menu.js b/ui/jquery.ui.menu.js index b73018a19..4fac02d2a 100644 --- a/ui/jquery.ui.menu.js +++ b/ui/jquery.ui.menu.js @@ -18,7 +18,7 @@ var idIncrement = 0; $.widget( "ui.menu", { version: "@VERSION", defaultElement: "