Dialog: Refactor _createOverlay and _destroyOverlay to use widget methods and properties.

This commit is contained in:
Jörn Zaefferer 2012-12-04 01:17:00 +01:00
parent 1e8baf5683
commit 9bd44301d3

View File

@ -665,17 +665,19 @@ $.widget("ui.dialog", {
// prevent use of anchors and inputs // prevent use of anchors and inputs
// we use a setTimeout in case the overlay is created from an // we use a setTimeout in case the overlay is created from an
// event that we're going to be cancelling (see #2804) // event that we're going to be cancelling (see #2804)
setTimeout(function() { this._delay(function() {
// handle $(el).dialog().dialog('close') (see #4065) // handle $(el).dialog().dialog('close') (see #4065)
if ( $.ui.dialog.overlayInstances ) { if ( $.ui.dialog.overlayInstances ) {
$( document ).bind( "focusin.dialog-overlay", function( event ) { this._on( this.document, {
if ( !$( event.target ).closest( ".ui-dialog").length ) { focusin: function( event ) {
event.preventDefault(); if ( !$( event.target ).closest( ".ui-dialog").length ) {
$( ".ui-dialog:visible:last .ui-dialog-content" ).data( "ui-dialog" )._focusTabbable(); event.preventDefault();
$( ".ui-dialog:visible:last .ui-dialog-content" ).data( "ui-dialog" )._focusTabbable();
}
} }
}); });
} }
}, 1 ); });
} }
var $el = this.overlay = $( "<div>" ).addClass( "ui-widget-overlay ui-front" ); var $el = this.overlay = $( "<div>" ).addClass( "ui-widget-overlay ui-front" );
@ -692,7 +694,7 @@ $.widget("ui.dialog", {
} }
$.ui.dialog.overlayInstances -= 1; $.ui.dialog.overlayInstances -= 1;
if ( $.ui.dialog.overlayInstances === 0 ) { if ( $.ui.dialog.overlayInstances === 0 ) {
$( [ document, window ] ).unbind( ".dialog-overlay" ); this._off( this.document, "focusin" );
} }
this.overlay.remove(); this.overlay.remove();
} }