]> source.dussan.org Git - jquery-ui.git/commitdiff
Dialog: Before handling escape key presses, check if the default action has been...
authorJay Merrifield <fracmak@gmail.com>
Tue, 8 Mar 2011 14:42:10 +0000 (09:42 -0500)
committerScott González <scott.gonzalez@gmail.com>
Tue, 8 Mar 2011 14:42:10 +0000 (09:42 -0500)
tests/unit/dialog/dialog_tickets.js
ui/jquery.ui.dialog.js

index b9bf2f972acac59f79572c1b045167b1aeff35be..def2452dedfc5bfb30915b57f55d7626d6847e61 100644 (file)
@@ -88,4 +88,29 @@ test("#6645: Missing element not found check in overlay", function(){
     d1.add(d2).remove();
 });
 
+test("#6966: Escape key closes all dialogs, not the top one", function(){
+       expect(8);
+    // test with close function removing dialog
+    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()}});
+    ok(d1.dialog("isOpen"), 'first dialog is open');
+    ok(d2.dialog("isOpen"), 'second dialog is open');
+    d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
+    ok(d1.dialog("isOpen"), 'first dialog still open');
+    ok(!d2.data('dialog'), 'second dialog is closed');
+    d2.remove();
+    d1.remove();
+
+    // test without close function removing dialog
+    d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true});
+    d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true});
+    ok(d1.dialog("isOpen"), 'first dialog is open');
+    ok(d2.dialog("isOpen"), 'second dialog is open');
+    d2.simulate("keydown", {keyCode: $.ui.keyCode.ESCAPE});
+    ok(d1.dialog("isOpen"), 'first dialog still open');
+    ok(!d2.dialog("isOpen"), 'second dialog is closed');
+    d2.remove();
+    d1.remove();
+});
+
 })(jQuery);
index 49378389646e1e2020880c35739a5f9630de6fd0..c14237b6a3a2d4de2de1614139615084533aaac9 100644 (file)
@@ -97,7 +97,7 @@ $.widget("ui.dialog", {
                                // TODO: move to stylesheet
                                .css( "outline", 0 )
                                .keydown(function( event ) {
-                                       if ( options.closeOnEscape && event.keyCode &&
+                                       if ( options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
                                                        event.keyCode === $.ui.keyCode.ESCAPE ) {
                                                self.close( event );
                                                event.preventDefault();
@@ -699,7 +699,7 @@ $.extend( $.ui.dialog.overlay, {
 
                        // allow closing by pressing the escape key
                        $( document ).bind( "keydown.dialog-overlay", function( event ) {
-                               if ( dialog.options.closeOnEscape && event.keyCode &&
+                               if ( dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode &&
                                        event.keyCode === $.ui.keyCode.ESCAPE ) {
                                        
                                        dialog.close( event );