Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dialog http://bugs.jqueryui.com/ticket/5388 #510

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions tests/unit/dialog/dialog_tickets.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -34,6 +34,42 @@ asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
} }
}); });


test("#5388: Don't change z-index when already at the top", function() {
expect(8);

var d1 = $('<div></div>').appendTo(document.body).dialog({ modal: true, autoOpen: false }),
d2 = $('<div></div>').appendTo(document.body).dialog({ modal: true, autoOpen: false }),
d3 = $('<div></div>').appendTo(document.body).dialog({ modal: true, autoOpen: false });

for (var i=0; i < 10; i++) {
d1.dialog('open').dialog('close');
d2.dialog('open').dialog('close');
}

equals($.ui.dialog.maxZ, 1000, 'MaxZ set to original');
d1.dialog('open');
equals(d1.dialog('widget').css('zIndex'), '1002', 'One dialog open maintained proper z-index');
d2.dialog('open');
equals(d2.dialog('widget').css('zIndex'), '1004', 'Two dialogs opened maintained proper z-index');
d1.dialog('close');

equals($.ui.dialog.maxZ, 1004, 'MaxZ set correctly');

equals(d2.dialog('widget').css('zIndex'), '1004', 'Second dialog remained open and first closed maintained proper z-index');
d3.dialog('open');
equals(d3.dialog('widget').css('zIndex'), '1006', 'Opened a third dialog and maintained proper z-index');
d1.dialog('open');
equals(d1.dialog('widget').css('zIndex'), '1008', 'Reopened first dialog and maintained proper z-index');

d1.dialog('close');
d2.remove();
d3.dialog('close');
equals($.ui.dialog.maxZ, 1000, 'Reset to original');

d1.remove();
d3.remove();
});

test("#4826: setting resizable false toggles resizable on dialog", function() { test("#4826: setting resizable false toggles resizable on dialog", function() {
expect(6); expect(6);


Expand Down
75 changes: 43 additions & 32 deletions ui/jquery.ui.dialog.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
maxWidth: true, maxWidth: true,
minHeight: true, minHeight: true,
minWidth: true minWidth: true
}; },
dialogs = {};


$.widget("ui.dialog", { $.widget("ui.dialog", {
version: "@VERSION", version: "@VERSION",
Expand Down Expand Up @@ -142,6 +143,8 @@ $.widget("ui.dialog", {
.html( title ) .html( title )
.prependTo( uiDialogTitlebar ); .prependTo( uiDialogTitlebar );


self.titleId = titleId;

uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection(); uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
this._hoverable( uiDialogTitlebarClose ); this._hoverable( uiDialogTitlebarClose );
this._focusable( uiDialogTitlebarClose ); this._focusable( uiDialogTitlebarClose );
Expand All @@ -159,6 +162,8 @@ $.widget("ui.dialog", {
if ( $.fn.bgiframe ) { if ( $.fn.bgiframe ) {
uiDialog.bgiframe(); uiDialog.bgiframe();
} }

dialogs[self.titleId] = this;
}, },


_init: function() { _init: function() {
Expand All @@ -174,6 +179,8 @@ $.widget("ui.dialog", {
self.overlay.destroy(); self.overlay.destroy();
} }
self.uiDialog.hide(); self.uiDialog.hide();
delete dialogs[self.titleId];

self.element self.element
.removeClass( "ui-dialog-content ui-widget-content" ) .removeClass( "ui-dialog-content ui-widget-content" )
.hide() .hide()
Expand Down Expand Up @@ -220,21 +227,27 @@ $.widget("ui.dialog", {
$.ui.dialog.overlay.resize(); $.ui.dialog.overlay.resize();


// adjust the maxZ to allow other modal dialogs to continue to work (see #4309) // adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
if ( self.options.modal ) { if (self.options.modal) {
maxZ = 0; self._updateMaxZ();
$( ".ui-dialog" ).each(function() {
if ( this !== self.uiDialog[0] ) {
thisZ = $( this ).css( "z-index" );
if ( !isNaN( thisZ ) ) {
maxZ = Math.max( maxZ, thisZ );
}
}
});
$.ui.dialog.maxZ = maxZ;
} }


return self; return self;
}, },

_updateMaxZ: function() {
var self = this,
maxZ = self.options.zIndex;

$.each(dialogs, function() {
if (this.uiDialog[0] !== self.uiDialog[0] && this._isOpen) {
thisZ = this.uiDialog.css('z-index');
if(!isNaN(thisZ)) {
maxZ = Math.max(maxZ, thisZ);
}
}
});
$.ui.dialog.maxZ = maxZ;
},


isOpen: function() { isOpen: function() {
return this._isOpen; return this._isOpen;
Expand All @@ -252,26 +265,24 @@ $.widget("ui.dialog", {
return self._trigger( "focus", event ); return self._trigger( "focus", event );
} }


if ( options.zIndex > $.ui.dialog.maxZ ) { //moveToTop method does not have a true/false passed down from dialog('moveToTop')
$.ui.dialog.maxZ = options.zIndex; if (force || force === undefined) {
} self._updateMaxZ();
if ( self.overlay ) {
if (self.overlay) {
$.ui.dialog.maxZ += 1;
self.overlay.$el.css('z-index', $.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ);
}

//Save and then restore scroll since Opera 9.5+ resets when parent z-Index is changed.
// http://ui.jquery.com/bugs/ticket/3193
saveScroll = { scrollTop: self.element.scrollTop(), scrollLeft: self.element.scrollLeft() };
$.ui.dialog.maxZ += 1; $.ui.dialog.maxZ += 1;
$.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ; self.uiDialog.css('z-index', $.ui.dialog.maxZ);
self.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ ); self.element.attr(saveScroll);
} }


// Save and then restore scroll self._trigger('focus', event);
// Opera 9.5+ resets when parent z-index is changed.
// http://bugs.jqueryui.com/ticket/3193
saveScroll = {
scrollTop: self.element.scrollTop(),
scrollLeft: self.element.scrollLeft()
};
$.ui.dialog.maxZ += 1;
self.uiDialog.css( "z-index", $.ui.dialog.maxZ );
self.element.attr( saveScroll );
self._trigger( "focus", event );


return self; return self;
}, },
Expand Down Expand Up @@ -324,7 +335,7 @@ $.widget("ui.dialog", {
hasFocus.eq( 0 ).focus(); hasFocus.eq( 0 ).focus();


self._isOpen = true; self._isOpen = true;
self._trigger( "open" ); self._trigger('open');


return self; return self;
}, },
Expand Down