diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-10-22 20:33:15 -0400 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-10-24 16:57:13 -0400 |
commit | 2a2a2c017c4395799ec07666f4ca14e078b52b5b (patch) | |
tree | 1ab26fecd080e12df192e72feacb29460c75fc76 /ui/jquery.ui.dialog.js | |
parent | 3829a37ca122e923c3a08b964c4b1a946a2a1456 (diff) | |
download | jquery-ui-2a2a2c017c4395799ec07666f4ca14e078b52b5b.tar.gz jquery-ui-2a2a2c017c4395799ec07666f4ca14e078b52b5b.zip |
Dialog: Prevent dialog form losing focus (or move it back in IE <= 8).
Diffstat (limited to 'ui/jquery.ui.dialog.js')
-rw-r--r-- | ui/jquery.ui.dialog.js | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/ui/jquery.ui.dialog.js b/ui/jquery.ui.dialog.js index 93a49cfd6..2b9846b3a 100644 --- a/ui/jquery.ui.dialog.js +++ b/ui/jquery.ui.dialog.js @@ -256,8 +256,6 @@ $.widget("ui.dialog", { this.uiDialog.hide(); this._trigger( "close", event ); } - - return this; }, isOpen: function() { @@ -305,6 +303,23 @@ $.widget("ui.dialog", { return this; }, + _keepFocus: function( event ) { + function checkFocus() { + var activeElement = this.document[ 0 ].activeElement, + isActive = this.uiDialog[ 0 ] === activeElement || + $.contains( this.uiDialog[ 0 ], activeElement ); + if ( !isActive ) { + this.uiDialog.focus(); + } + } + event.preventDefault(); + checkFocus.call( this ); + // support: IE + // IE <= 8 doesn't prevent moving focus even with event.preventDefault() + // so we check again later + this._delay( checkFocus ); + }, + _createButtons: function( buttons ) { var that = this, hasButtons = false; @@ -648,6 +663,10 @@ $.extend( $.ui.dialog.overlay, { $el.appendTo( document.body ); + $el.bind( "mousedown", function( event ) { + dialog._keepFocus( event ); + }); + if ( $.fn.bgiframe ) { $el.bgiframe(); } |