Skip to content

Commit 5cae674

Browse files
committed
Dialog: find the highest zIndex dialog with overlay to close on ESC key. Fixed #5356 - ESC key problem
* along the way fixed a related bug with more than one dialog getting closed * added visual test case
1 parent 75329fa commit 5cae674

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8" />
5+
<title>Dialog Visual Test : Ticket 5365 - ESC key problem</title>
6+
<link rel="stylesheet" href="../visual.css" type="text/css" />
7+
<link rel="stylesheet" href="../../../themes/base/jquery.ui.all.css" type="text/css">
8+
<script type="text/javascript" src="../../../jquery-1.4.2.js"></script>
9+
<script type="text/javascript" src="../../../external/jquery.bgiframe-2.1.1.js"></script>
10+
<script type="text/javascript" src="../../../ui/jquery.ui.core.js"></script>
11+
<script type="text/javascript" src="../../../ui/jquery.ui.widget.js"></script>
12+
<script type="text/javascript" src="../../../ui/jquery.ui.mouse.js"></script>
13+
<script type="text/javascript" src="../../../ui/jquery.ui.draggable.js"></script>
14+
<script type="text/javascript" src="../../../ui/jquery.ui.position.js"></script>
15+
<script type="text/javascript" src="../../../ui/jquery.ui.resizable.js"></script>
16+
<script type="text/javascript" src="../../../ui/jquery.ui.dialog.js"></script>
17+
<script type="text/javascript">
18+
$(function() {
19+
var dialogsCount = 0;
20+
var openModal = function() {
21+
dialogsCount++;
22+
$('<div></div>').append('<p> Dialog' + dialogsCount + ' Conent')
23+
.dialog({
24+
modal: true,
25+
buttons: {
26+
"Close": function(){$(this).dialog('close');},
27+
"OpenNew": openModal
28+
}
29+
})
30+
}
31+
openModal();
32+
});
33+
</script>
34+
</head>
35+
<body>
36+
</body>
37+
</html>

ui/jquery.ui.dialog.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ $.widget("ui.dialog", {
7171

7272
self.close(event);
7373
event.preventDefault();
74+
event.stopPropagation();
7475
}
7576
})
7677
.attr({
@@ -681,6 +682,7 @@ $.extend($.ui.dialog.overlay, {
681682
events: $.map('focus,mousedown,mouseup,keydown,keypress,click'.split(','),
682683
function(event) { return event + '.dialog-overlay'; }).join(' '),
683684
create: function(dialog) {
685+
var self = this;
684686
if (this.instances.length === 0) {
685687
// prevent use of anchors and inputs
686688
// we use a setTimeout in case the overlay is created from an
@@ -694,14 +696,18 @@ $.extend($.ui.dialog.overlay, {
694696
});
695697
}
696698
}, 1);
697-
699+
698700
// allow closing by pressing the escape key
699701
$(document).bind('keydown.dialog-overlay', function(event) {
700702
if (dialog.options.closeOnEscape && event.keyCode &&
701-
event.keyCode === $.ui.keyCode.ESCAPE) {
703+
event.keyCode === $.ui.keyCode.ESCAPE ) {
702704

703-
dialog.close(event);
705+
$.grep(self.instances, function(instance){
706+
return instance.zIndex() == $.ui.dialog.overlay.maxZ;
707+
})[0].dialog.close(event);
708+
704709
event.preventDefault();
710+
event.stopPropagation();
705711
}
706712
});
707713

@@ -715,6 +721,7 @@ $.extend($.ui.dialog.overlay, {
715721
width: this.width(),
716722
height: this.height()
717723
});
724+
$el.dialog = dialog;
718725

719726
if ($.fn.bgiframe) {
720727
$el.bgiframe();

0 commit comments

Comments
 (0)