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

Closed
wants to merge 3 commits into
from
@@ -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() {
expect(6);
@@ -33,7 +33,8 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
maxWidth: true,
minHeight: true,
minWidth: true
- };
+ },
+ dialogs = {};
$.widget("ui.dialog", {
version: "@VERSION",
@@ -142,6 +143,8 @@ $.widget("ui.dialog", {
.html( title )
.prependTo( uiDialogTitlebar );
+ self.titleId = titleId;
+
uiDialogTitlebar.find( "*" ).add( uiDialogTitlebar ).disableSelection();
this._hoverable( uiDialogTitlebarClose );
this._focusable( uiDialogTitlebarClose );
@@ -159,6 +162,8 @@ $.widget("ui.dialog", {
if ( $.fn.bgiframe ) {
uiDialog.bgiframe();
}
+
+ dialogs[self.titleId] = this;
},
_init: function() {
@@ -174,6 +179,8 @@ $.widget("ui.dialog", {
self.overlay.destroy();
}
self.uiDialog.hide();
+ delete dialogs[self.titleId];
+
self.element
.removeClass( "ui-dialog-content ui-widget-content" )
.hide()
@@ -220,21 +227,27 @@ $.widget("ui.dialog", {
$.ui.dialog.overlay.resize();
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
- if ( self.options.modal ) {
- maxZ = 0;
- $( ".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;
+ if (self.options.modal) {
+ self._updateMaxZ();
}
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() {
return this._isOpen;
@@ -252,26 +265,24 @@ $.widget("ui.dialog", {
return self._trigger( "focus", event );
}
- if ( options.zIndex > $.ui.dialog.maxZ ) {
- $.ui.dialog.maxZ = options.zIndex;
- }
- if ( self.overlay ) {
+ //moveToTop method does not have a true/false passed down from dialog('moveToTop')
+ if (force || force === undefined) {
+ self._updateMaxZ();
+
+ 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.overlay.maxZ = $.ui.dialog.maxZ;
- self.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
- }
-
- // Save and then restore scroll
- // 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 );
+ self.uiDialog.css('z-index', $.ui.dialog.maxZ);
+ self.element.attr(saveScroll);
+ }
+
+ self._trigger('focus', event);
return self;
},
@@ -324,7 +335,7 @@ $.widget("ui.dialog", {
hasFocus.eq( 0 ).focus();
self._isOpen = true;
- self._trigger( "open" );
+ self._trigger('open');
return self;
},