Skip to content

Commit 1e8baf5

Browse files
committed
Dialog: Remove the instance-storing for the overlay, just create one whenever it is needed. Heavily simplifies the code, while the memorly leak should be hardly an issue anymore, since fixed positioning restricts the overlay size to the window dimensions. Fixes #6058 - Dialog overlays are not properly reused when multiple instances of a Dialog exist.
1 parent b9068c1 commit 1e8baf5

File tree

2 files changed

+7
-31
lines changed

2 files changed

+7
-31
lines changed

tests/unit/dialog/dialog_tickets.js

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -107,17 +107,6 @@ test("#6137: dialog('open') causes form elements to reset on IE7", function() {
107107
d1.remove();
108108
});
109109

110-
test("#6645: Missing element not found check in overlay", function(){
111-
expect(2);
112-
var d1 = $('<div title="dialog 1">Dialog 1</div>').dialog({modal: true}),
113-
d2 = $('<div title="dialog 2">Dialog 2</div>').dialog({modal: true, close: function(){ d2.remove(); }});
114-
115-
equal($.ui.dialog.overlay.instances.length, 2, 'two overlays created');
116-
d2.dialog('close');
117-
equal($.ui.dialog.overlay.instances.length, 1, 'one overlay remains after closing the 2nd overlay');
118-
d1.add(d2).remove();
119-
});
120-
121110
// TODO merge this with the main destroy test
122111
test("#4980: Destroy should place element back in original DOM position", function(){
123112
expect( 2 );

ui/jquery.ui.dialog.js

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -661,13 +661,13 @@ $.widget("ui.dialog", {
661661
if ( !this.options.modal ) {
662662
return;
663663
}
664-
if ( $.ui.dialog.overlay.instances.length === 0 ) {
664+
if ( $.ui.dialog.overlayInstances === 0 ) {
665665
// prevent use of anchors and inputs
666666
// we use a setTimeout in case the overlay is created from an
667667
// event that we're going to be cancelling (see #2804)
668668
setTimeout(function() {
669669
// handle $(el).dialog().dialog('close') (see #4065)
670-
if ( $.ui.dialog.overlay.instances.length ) {
670+
if ( $.ui.dialog.overlayInstances ) {
671671
$( document ).bind( "focusin.dialog-overlay", function( event ) {
672672
if ( !$( event.target ).closest( ".ui-dialog").length ) {
673673
event.preventDefault();
@@ -678,40 +678,27 @@ $.widget("ui.dialog", {
678678
}, 1 );
679679
}
680680

681-
// reuse old instances due to IE memory leak with alpha transparency (see #5185)
682-
var $el = this.overlay = ( $.ui.dialog.overlay.oldInstances.pop() || $( "<div>" ).addClass( "ui-widget-overlay ui-front" ) );
683-
681+
var $el = this.overlay = $( "<div>" ).addClass( "ui-widget-overlay ui-front" );
684682
$el.appendTo( this.document[ 0 ].body );
685-
686683
this._on( $el, {
687684
mousedown: "_keepFocus"
688685
});
689-
690-
$.ui.dialog.overlay.instances.push( $el );
686+
$.ui.dialog.overlayInstances += 1;
691687
},
692688

693689
_destroyOverlay: function() {
694690
if ( !this.options.modal ) {
695691
return;
696692
}
697-
var indexOf = $.inArray( this.overlay, $.ui.dialog.overlay.instances );
698-
699-
if ( indexOf !== -1 ) {
700-
$.ui.dialog.overlay.oldInstances.push( $.ui.dialog.overlay.instances.splice( indexOf, 1 )[ 0 ] );
701-
}
702-
703-
if ( $.ui.dialog.overlay.instances.length === 0 ) {
693+
$.ui.dialog.overlayInstances -= 1;
694+
if ( $.ui.dialog.overlayInstances === 0 ) {
704695
$( [ document, window ] ).unbind( ".dialog-overlay" );
705696
}
706-
707697
this.overlay.remove();
708698
}
709699
});
710700

711-
$.ui.dialog.overlay = {
712-
instances: [],
713-
oldInstances: []
714-
};
701+
$.ui.dialog.overlayInstances = 0;
715702

716703
// DEPRECATED
717704
if ( $.uiBackCompat !== false ) {

0 commit comments

Comments
 (0)