Skip to content

Commit e9660b9

Browse files
author
Nate Eagle
committed
Dialog: removed z-index manipulation and added .ui-front logic.
This is a basic implementation of the logic described by Scott Gonzalez in this gist: https://gist.github.com/3893326 -- .ui-front NEED EXAMPLES OF WHAT IS CURRENTLY BROKEN datepicker with z-index: 10000 & $( document ).tooltip() http://bugs.jqueryui.com/ticket/8655 http://bugs.jqueryui.com/ticket/7884 z-indexy elements will have class .ui-front .ui-front applies z-index: 100 .ui-front element are always positioned by some other class (so that z-index applies) z-indexy elements will have an appendTo option default null, which means walk up DOM from associated element looking for .ui-front element e.g., autocomplete would walk up DOM from text field to find which element to append the menu to if no .ui-front element is found, append to body dialog stacking?
1 parent 112185e commit e9660b9

File tree

2 files changed

+24
-78
lines changed

2 files changed

+24
-78
lines changed

themes/base/jquery.ui.core.css

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
.ui-helper-clearfix { zoom: 1; }
2020
.ui-helper-zfix { width: 100%; height: 100%; top: 0; left: 0; position: absolute; opacity: 0; filter:Alpha(Opacity=0); }
2121

22+
.ui-front { z-index: 100; }
23+
2224

2325
/* Interaction Cues
2426
----------------------------------*/

ui/jquery.ui.dialog.js

Lines changed: 22 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
*/
2020
(function( $, undefined ) {
2121

22-
var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
22+
var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ui-front ",
2323
sizeRelatedOptions = {
2424
buttons: true,
2525
height: true,
@@ -39,6 +39,7 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
3939
$.widget("ui.dialog", {
4040
version: "@VERSION",
4141
options: {
42+
appendTo: null,
4243
autoOpen: true,
4344
buttons: {},
4445
closeOnEscape: true,
@@ -89,12 +90,26 @@ $.widget("ui.dialog", {
8990

9091
title = options.title || " ",
9192

93+
// Figure out where to append the dialog
94+
appendToTarget = function() {
95+
if ( options.appendTo ) {
96+
return $( options.appendTo );
97+
} else {
98+
var uiFront = that.element.closest(".ui-front");
99+
100+
if (uiFront.length) {
101+
return uiFront;
102+
} else {
103+
return document.body;
104+
}
105+
}
106+
},
107+
92108
uiDialog = ( this.uiDialog = $( "<div>" ) )
93109
.addClass( uiDialogClasses + options.dialogClass )
94110
.css({
95111
display: "none",
96-
outline: 0, // TODO: move to stylesheet
97-
zIndex: options.zIndex
112+
outline: 0 // TODO: move to stylesheet
98113
})
99114
// setting tabIndex makes the div focusable
100115
.attr( "tabIndex", -1)
@@ -105,10 +120,7 @@ $.widget("ui.dialog", {
105120
event.preventDefault();
106121
}
107122
})
108-
.mousedown(function( event ) {
109-
that.moveToTop( false, event );
110-
})
111-
.appendTo( "body" ),
123+
.appendTo( appendToTarget() ),
112124

113125
uiDialogContent = this.element
114126
.show()
@@ -257,62 +269,13 @@ $.widget("ui.dialog", {
257269

258270
$.ui.dialog.overlay.resize();
259271

260-
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
261-
if ( this.options.modal ) {
262-
maxZ = 0;
263-
$( ".ui-dialog" ).each(function() {
264-
if ( this !== that.uiDialog[0] ) {
265-
thisZ = $( this ).css( "z-index" );
266-
if ( !isNaN( thisZ ) ) {
267-
maxZ = Math.max( maxZ, thisZ );
268-
}
269-
}
270-
});
271-
$.ui.dialog.maxZ = maxZ;
272-
}
273-
274272
return this;
275273
},
276274

277275
isOpen: function() {
278276
return this._isOpen;
279277
},
280278

281-
// the force parameter allows us to move modal dialogs to their correct
282-
// position on open
283-
moveToTop: function( force, event ) {
284-
var options = this.options,
285-
saveScroll;
286-
287-
if ( ( options.modal && !force ) ||
288-
( !options.stack && !options.modal ) ) {
289-
return this._trigger( "focus", event );
290-
}
291-
292-
if ( options.zIndex > $.ui.dialog.maxZ ) {
293-
$.ui.dialog.maxZ = options.zIndex;
294-
}
295-
if ( this.overlay ) {
296-
$.ui.dialog.maxZ += 1;
297-
$.ui.dialog.overlay.maxZ = $.ui.dialog.maxZ;
298-
this.overlay.$el.css( "z-index", $.ui.dialog.overlay.maxZ );
299-
}
300-
301-
// Save and then restore scroll
302-
// Opera 9.5+ resets when parent z-index is changed.
303-
// http://bugs.jqueryui.com/ticket/3193
304-
saveScroll = {
305-
scrollTop: this.element.scrollTop(),
306-
scrollLeft: this.element.scrollLeft()
307-
};
308-
$.ui.dialog.maxZ += 1;
309-
this.uiDialog.css( "z-index", $.ui.dialog.maxZ );
310-
this.element.attr( saveScroll );
311-
this._trigger( "focus", event );
312-
313-
return this;
314-
},
315-
316279
open: function() {
317280
if ( this._isOpen ) {
318281
return;
@@ -326,7 +289,6 @@ $.widget("ui.dialog", {
326289
this._position( options.position );
327290
uiDialog.show( options.show );
328291
this.overlay = options.modal ? new $.ui.dialog.overlay( this ) : null;
329-
this.moveToTop( true );
330292

331293
// set focus to the first tabbable element in the content area or the first button
332294
// if there are no tabbable elements, set focus on the dialog itself
@@ -694,22 +656,10 @@ $.extend( $.ui.dialog.overlay, {
694656
}
695657
).join( " " ),
696658
create: function( dialog ) {
659+
697660
if ( this.instances.length === 0 ) {
698-
// prevent use of anchors and inputs
699-
// we use a setTimeout in case the overlay is created from an
700-
// event that we're going to be cancelling (see #2804)
701-
setTimeout(function() {
702-
// handle $(el).dialog().dialog('close') (see #4065)
703-
if ( $.ui.dialog.overlay.instances.length ) {
704-
$( document ).bind( $.ui.dialog.overlay.events, function( event ) {
705-
// stop events if the z-index of the target is < the z-index of the overlay
706-
// we cannot return true when we don't want to cancel the event (#3523)
707-
if ( $( event.target ).zIndex() < $.ui.dialog.overlay.maxZ ) {
708-
return false;
709-
}
710-
});
711-
}
712-
}, 1 );
661+
// TODO: Do we need to write new logic to prevent use of anchors
662+
// and inputs using the .ui-front system?
713663

714664
// handle window resize
715665
$( window ).bind( "resize.dialog-overlay", $.ui.dialog.overlay.resize );
@@ -756,12 +706,6 @@ $.extend( $.ui.dialog.overlay, {
756706
}
757707

758708
$el.height( 0 ).width( 0 ).remove();
759-
760-
// adjust the maxZ to allow other modal dialogs to continue to work (see #4309)
761-
$.each( this.instances, function() {
762-
maxZ = Math.max( maxZ, this.css( "z-index" ) );
763-
});
764-
this.maxZ = maxZ;
765709
},
766710

767711
height: function() {

0 commit comments

Comments
 (0)