Skip to content

Commit dfb3544

Browse files
Jay Merrifieldscottgonzalez
Jay Merrifield
authored andcommitted
Dialog: Make sure the overlay instance still exists before trying to remove it. Fixes #6645 - Dialog: Missing element not found check in overlay code.
1 parent 320dfb8 commit dfb3544

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

tests/unit/dialog/dialog_tickets.js

+11-1
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,16 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() {
7676
equal($('input:checked').val(), 'b', "checkbox b is checked");
7777

7878
d1.add(d2).remove();
79-
})
79+
});
80+
81+
test("#6645: Missing element not found check in overlay", function(){
82+
expect(2);
83+
d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
84+
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove()}});
85+
equals($.ui.dialog.overlay.instances.length, 2, 'two overlays created');
86+
d2.dialog('close');
87+
equals($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay');
88+
d1.add(d2).remove();
89+
});
8090

8191
})(jQuery);

ui/jquery.ui.dialog.js

+4-1
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,10 @@ $.extend($.ui.dialog.overlay, {
750750
},
751751

752752
destroy: function($el) {
753-
this.oldInstances.push(this.instances.splice($.inArray($el, this.instances), 1)[0]);
753+
var indexOf = $.inArray($el, this.instances);
754+
if (indexOf != -1){
755+
this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
756+
}
754757

755758
if (this.instances.length === 0) {
756759
$([document, window]).unbind('.dialog-overlay');

0 commit comments

Comments
 (0)