mirror of
https://github.com/jquery/jquery-ui.git
synced 2025-01-07 20:34:24 +00:00
Dialog: Refactor overlay handling into two instance methods. Remove unaddressable TODOs.
This commit is contained in:
parent
a0310eb091
commit
41c2afd66b
67
ui/jquery.ui.dialog.js
vendored
67
ui/jquery.ui.dialog.js
vendored
@ -122,9 +122,7 @@ $.widget("ui.dialog", {
|
|||||||
var next,
|
var next,
|
||||||
oldPosition = this.oldPosition;
|
oldPosition = this.oldPosition;
|
||||||
|
|
||||||
if ( this.overlay ) {
|
this._destroyOverlay();
|
||||||
this.overlay.destroy();
|
|
||||||
}
|
|
||||||
this.uiDialog.hide();
|
this.uiDialog.hide();
|
||||||
this.element
|
this.element
|
||||||
.removeUniqueId()
|
.removeUniqueId()
|
||||||
@ -168,9 +166,7 @@ $.widget("ui.dialog", {
|
|||||||
|
|
||||||
this._isOpen = false;
|
this._isOpen = false;
|
||||||
|
|
||||||
if ( this.overlay ) {
|
this._destroyOverlay();
|
||||||
this.overlay.destroy();
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( !this.opener.filter( ":focusable" ).focus().length ) {
|
if ( !this.opener.filter( ":focusable" ).focus().length ) {
|
||||||
// Hiding a focused element doesn't trigger blur in WebKit
|
// Hiding a focused element doesn't trigger blur in WebKit
|
||||||
@ -212,9 +208,7 @@ $.widget("ui.dialog", {
|
|||||||
|
|
||||||
this._size();
|
this._size();
|
||||||
this._position();
|
this._position();
|
||||||
if ( this.options.modal ) {
|
this._createOverlay();
|
||||||
this.overlay = new $.ui.dialog.overlay( this );
|
|
||||||
}
|
|
||||||
this._moveToTop( null, true );
|
this._moveToTop( null, true );
|
||||||
this._show( this.uiDialog, this.options.show );
|
this._show( this.uiDialog, this.options.show );
|
||||||
|
|
||||||
@ -663,24 +657,13 @@ $.widget("ui.dialog", {
|
|||||||
if (this.uiDialog.is( ":data(ui-resizable)" ) ) {
|
if (this.uiDialog.is( ":data(ui-resizable)" ) ) {
|
||||||
this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
|
this.uiDialog.resizable( "option", "minHeight", this._minHeight() );
|
||||||
}
|
}
|
||||||
}
|
},
|
||||||
});
|
|
||||||
|
|
||||||
$.extend($.ui.dialog, {
|
_createOverlay: function() {
|
||||||
// TODO move to dialog instance method
|
if ( !this.options.modal ) {
|
||||||
overlay: function( dialog ) {
|
return;
|
||||||
this.$el = $.ui.dialog.overlay.create( dialog );
|
}
|
||||||
}
|
if ( $.ui.dialog.overlay.instances.length === 0 ) {
|
||||||
});
|
|
||||||
|
|
||||||
// TODO get rid of instance list, at least the oldInstance stuff, and inline as dialog methods
|
|
||||||
$.extend( $.ui.dialog.overlay, {
|
|
||||||
instances: [],
|
|
||||||
// reuse old instances due to IE memory leak with alpha transparency (see #5185)
|
|
||||||
oldInstances: [],
|
|
||||||
create: function( dialog ) {
|
|
||||||
if ( this.instances.length === 0 ) {
|
|
||||||
// TODO get rid of the timeout, which should remove the need for the #4065 workaround as well
|
|
||||||
// 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)
|
||||||
@ -697,38 +680,40 @@ $.extend( $.ui.dialog.overlay, {
|
|||||||
}, 1 );
|
}, 1 );
|
||||||
}
|
}
|
||||||
|
|
||||||
var $el = ( this.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay ui-front" ) );
|
// reuse old instances due to IE memory leak with alpha transparency (see #5185)
|
||||||
|
var $el = this.overlay = ( $.ui.dialog.overlay.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay ui-front" ) );
|
||||||
|
|
||||||
$el.appendTo( document.body );
|
$el.appendTo( document.body );
|
||||||
|
|
||||||
$el.bind( "mousedown", function( event ) {
|
this._on( $el, {
|
||||||
dialog._keepFocus( event );
|
mousedown: "_keepFocus"
|
||||||
});
|
});
|
||||||
|
|
||||||
this.instances.push( $el );
|
$.ui.dialog.overlay.instances.push( $el );
|
||||||
return $el;
|
|
||||||
},
|
},
|
||||||
|
|
||||||
destroy: function( $el ) {
|
_destroyOverlay: function() {
|
||||||
var indexOf = $.inArray( $el, this.instances );
|
if ( !this.options.modal ) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
var indexOf = $.inArray( this.overlay, $.ui.dialog.overlay.instances );
|
||||||
|
|
||||||
if ( indexOf !== -1 ) {
|
if ( indexOf !== -1 ) {
|
||||||
this.oldInstances.push( this.instances.splice( indexOf, 1 )[ 0 ] );
|
$.ui.dialog.overlay.oldInstances.push( $.ui.dialog.overlay.instances.splice( indexOf, 1 )[ 0 ] );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( this.instances.length === 0 ) {
|
if ( $.ui.dialog.overlay.instances.length === 0 ) {
|
||||||
$( [ document, window ] ).unbind( ".dialog-overlay" );
|
$( [ document, window ] ).unbind( ".dialog-overlay" );
|
||||||
}
|
}
|
||||||
|
|
||||||
$el.remove();
|
this.overlay.remove();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$.extend( $.ui.dialog.overlay.prototype, {
|
$.ui.dialog.overlay = {
|
||||||
destroy: function() {
|
instances: [],
|
||||||
$.ui.dialog.overlay.destroy( this.$el );
|
oldInstances: []
|
||||||
}
|
};
|
||||||
});
|
|
||||||
|
|
||||||
// DEPRECATED
|
// DEPRECATED
|
||||||
if ( $.uiBackCompat !== false ) {
|
if ( $.uiBackCompat !== false ) {
|
||||||
|
Loading…
Reference in New Issue
Block a user