diff options
author | Scott González <scott.gonzalez@gmail.com> | 2011-08-02 10:28:57 -0700 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2011-08-02 10:28:57 -0700 |
commit | 4c57f361ada4a23d6a42a099604549753ea8fe6c (patch) | |
tree | bfa0e2f823537668579374946ec37194872f7fd3 | |
parent | 67ff57a79db5e7d5c8b053a0271be4696b1e0f22 (diff) | |
parent | abf97f73017794f93c52876221cf34018da5781c (diff) | |
download | jquery-ui-4c57f361ada4a23d6a42a099604549753ea8fe6c.tar.gz jquery-ui-4c57f361ada4a23d6a42a099604549753ea8fe6c.zip |
Merge pull request #415 from pelme/1-8-stable
Backport of #6966 fix (multiple dialogs and ESC)
-rw-r--r-- | tests/unit/dialog/dialog_tickets.js | 25 | ||||
-rw-r--r-- | ui/jquery.ui.dialog.js | 4 |
2 files changed, 27 insertions, 2 deletions
diff --git a/tests/unit/dialog/dialog_tickets.js b/tests/unit/dialog/dialog_tickets.js index b9bf2f972..def2452de 100644 --- a/tests/unit/dialog/dialog_tickets.js +++ b/tests/unit/dialog/dialog_tickets.js @@ -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); diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index af08e1b76..32846d3fd 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -110,7 +110,7 @@ $.widget("ui.dialog", { // setting tabIndex makes the div focusable // setting outline to 0 prevents a border on focus in Mozilla .attr('tabIndex', -1).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); @@ -748,7 +748,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); |