aboutsummaryrefslogtreecommitdiffstats
path: root/ui/ui.dialog.js
diff options
context:
space:
mode:
authorScott González <scott.gonzalez@gmail.com>2008-09-06 16:50:05 +0000
committerScott González <scott.gonzalez@gmail.com>2008-09-06 16:50:05 +0000
commiteedbd524e22157a7430da60521903b64b9684183 (patch)
tree9e1683df0d36a66916b773cdf9e905a73130ded5 /ui/ui.dialog.js
parent0b771b43c6aa28a9ccbcb23c826351ea10da5383 (diff)
downloadjquery-ui-eedbd524e22157a7430da60521903b64b9684183.tar.gz
jquery-ui-eedbd524e22157a7430da60521903b64b9684183.zip
Dialog: Fixed #3123: Prevent tabbing out of modal dialogs.
Diffstat (limited to 'ui/ui.dialog.js')
-rw-r--r--ui/ui.dialog.js25
1 files changed, 24 insertions, 1 deletions
diff --git a/ui/ui.dialog.js b/ui/ui.dialog.js
index 2352cbee8..0f3511b83 100644
--- a/ui/ui.dialog.js
+++ b/ui/ui.dialog.js
@@ -269,6 +269,27 @@ $.widget("ui.dialog", {
(this.options.autoResize && this._size());
this._moveToTop(true);
+ // prevent tabbing out of modal dialogs
+ (this.options.modal && this.uiDialog.bind('keypress.ui-dialog', function(e) {
+ if (e.keyCode != $.keyCode.TAB) {
+ return;
+ }
+
+ var tabbables = $(':tabbable', this),
+ first = tabbables.filter(':first')[0],
+ last = tabbables.filter(':last')[0];
+
+ if (e.target == last && !e.shiftKey) {
+ setTimeout(function() {
+ first.focus();
+ }, 1);
+ } else if (e.target == first && e.shiftKey) {
+ setTimeout(function() {
+ last.focus();
+ }, 1);
+ }
+ }));
+
this._trigger('open', null, { options: this.options });
this._isOpen = true;
},
@@ -294,7 +315,9 @@ $.widget("ui.dialog", {
close: function() {
(this.overlay && this.overlay.destroy());
- this.uiDialog.hide(this.options.hide);
+ this.uiDialog
+ .hide(this.options.hide)
+ .unbind('keypress.ui-dialog');
this._trigger('close', null, { options: this.options });
$.ui.dialog.overlay.resize();