mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Dialog: Prevent dialog form losing focus (or move it back in IE <= 8).
This commit is contained in:
parent
3829a37ca1
commit
2a2a2c017c
@ -30,7 +30,7 @@
|
||||
|
||||
var datepickerDialog = $( "#dialog-datepicker" ).dialog({
|
||||
autoOpen: false,
|
||||
modal: true,
|
||||
modal: true
|
||||
}),
|
||||
|
||||
autocompleteDialog = $( "#dialog-autocomplete" ).dialog({
|
||||
|
23
ui/jquery.ui.dialog.js
vendored
23
ui/jquery.ui.dialog.js
vendored
@ -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();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user