diff options
author | Jay Merrifield <fracmak@gmail.com> | 2012-05-03 19:02:23 -0400 |
---|---|---|
committer | Scott González <scott.gonzalez@gmail.com> | 2012-05-07 09:44:26 -0400 |
commit | cab4c467d9c12ec61a652c3bf68eedd166319b34 (patch) | |
tree | e9d601d2ba5cf14f40a09917ccc17361b56eb37a /ui/jquery.ui.dialog.js | |
parent | 32f356bbfa9a8f3b90b4e64331e9108b4d87a349 (diff) | |
download | jquery-ui-cab4c467d9c12ec61a652c3bf68eedd166319b34.tar.gz jquery-ui-cab4c467d9c12ec61a652c3bf68eedd166319b34.zip |
Dialog: Handle escape for all overlays. Fixes #8300 - Dialog: Incorrect behavior for ESCAPE with multiple modal dialogs.
Diffstat (limited to 'ui/jquery.ui.dialog.js')
-rw-r--r-- | ui/jquery.ui.dialog.js | 26 |
1 files changed, 15 insertions, 11 deletions
diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 144cf9725..45ee37789 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -713,21 +713,25 @@ $.extend( $.ui.dialog.overlay, { } }, 1 ); - // allow closing by pressing the escape key - $( document ).bind( "keydown.dialog-overlay", function( event ) { - if ( dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && - event.keyCode === $.ui.keyCode.ESCAPE ) { - - dialog.close( event ); - event.preventDefault(); - } - }); - // handle window resize $( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize ); } - + var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay" ) ); + + // allow closing by pressing the escape key + $( document ).bind( "keydown.dialog-overlay", function( event ) { + var instances = $.ui.dialog.overlay.instances; + // only react to the event if we're the top overlay + if ( instances.length !== 0 && instances[ instances.length - 1 ] === $el && + dialog.options.closeOnEscape && !event.isDefaultPrevented() && event.keyCode && + event.keyCode === $.ui.keyCode.ESCAPE ) { + + dialog.close( event ); + event.preventDefault(); + } + }); + $el.appendTo( document.body ).css({ width: this.width(), height: this.height() |