Skip to content

Commit

Permalink
Take '$.ui.dialog.maxZ' and 'self.overlay' into account.
Browse files Browse the repository at this point in the history
  • Loading branch information
PaulUithol committed May 20, 2011
1 parent b4c5a46 commit c0b88f3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 5 deletions.
13 changes: 9 additions & 4 deletions tests/unit/dialog/dialog_options.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,7 +442,7 @@ test("width", function() {
});

test("zIndex", function() {
expect(6);
expect(9);

el = $('<div></div>').dialog( { autoOpen: false } );
equals(dlg().css( 'zIndex' ), 1000, "default zIndex");
Expand All @@ -454,11 +454,16 @@ test("zIndex", function() {
equals(dlg().css( 'zIndex' ), $.ui.dialog.maxZ, "default zIndex");
el.remove();

// The z-index will always be 1 higher than requested if 'moveToTop' gets called, such as when 'autoOpen' is true.
el = $('<div></div>').dialog({zIndex: 2932 });
equals(dlg().css('zIndex'), 2932 + 1, "explicit zIndex");
// The z-index will be 1 higher than requested if 'moveToTop' gets called, such as when 'autoOpen' is true.
newZIndex = $.ui.dialog.maxZ + 2932;
el = $('<div></div>').dialog({zIndex: newZIndex });
equals(dlg().css('zIndex'), newZIndex + 1, "explicit zIndex");
equals( el.dialog( 'option', 'zIndex' ), newZIndex, 'get works for zIndex' );
equals( newZIndex + 1, $.ui.dialog.maxZ, '$.ui.dialog.maxZ is updated to the new value' );

el.dialog('option', 'zIndex', 1748);
equals(dlg().css('zIndex'), 1748, 'explicit zIndex after init');
equals( el.dialog( 'option', 'zIndex' ), 1748 );
el.remove();

// At the moment, an explicit zIndex option lower than $.ui.dialog.maxZ will be ignored since 'open' calls
Expand Down
15 changes: 14 additions & 1 deletion ui/jquery.ui.dialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,20 @@ $.widget("ui.dialog", {
.html( "" + ( value || "&#160;" ) );
break;
case "zIndex":
uiDialog.css({ zIndex: value });
if ( value > $.ui.dialog.maxZ ) {
$.ui.dialog.maxZ = value;

if ( self.overlay ) {
$.ui.dialog.maxZ += 1;
$.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
}

value = $.ui.dialog.maxZ;
}

self.overlay && self.overlay.$el.css( "z-index", value > 0 ? value : 0 );
uiDialog.css( "z-index", value );

break;
}

Expand Down

0 comments on commit c0b88f3

Please sign in to comment.