]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Make sure the overlay instance still exists before trying to remove it. Fixes...
authorJay Merrifield <merrifieldj@pixia.com>
Fri, 12 Nov 2010 13:16:41 +0000 (08:16 -0500)
committerScott González <scott.gonzalez@gmail.com>
Fri, 12 Nov 2010 13:16:41 +0000 (08:16 -0500)
tests/unit/dialog/dialog_tickets.js
ui/jquery.ui.dialog.js

index f7b590b530112981982423413cdb37a2435ba17a..b9bf2f972acac59f79572c1b045167b1aeff35be 100644 (file)
@@ -76,6 +76,16 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() {
        equal($('input:checked').val(), 'b', "checkbox b is checked");
 
        d1.add(d2).remove();
-})
+});
+
+test("#6645: Missing element not found check in overlay", function(){
+    expect(2);
+    d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
+    d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove()}});
+    equals($.ui.dialog.overlay.instances.length, 2, 'two overlays created');
+    d2.dialog('close');
+    equals($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay');
+    d1.add(d2).remove();
+});
 
 })(jQuery);
index 3d38df4c000b12612d0423b56d34f93bb8f4a6df..efc445693ceefda33ea8498990b2aebc1c646aa2 100644 (file)
@@ -750,7 +750,10 @@ $.extend($.ui.dialog.overlay, {
        },
 
        destroy: function($el) {
-               this.oldInstances.push(this.instances.splice($.inArray($el, this.instances), 1)[0]);
+               var indexOf = $.inArray($el, this.instances);
+               if (indexOf != -1){
+                       this.oldInstances.push(this.instances.splice(indexOf, 1)[0]);
+               }
 
                if (this.instances.length === 0) {
                        $([document, window]).unbind('.dialog-overlay');