19
19
*/
20
20
( function ( $ , undefined ) {
21
21
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 " ,
23
23
sizeRelatedOptions = {
24
24
buttons : true ,
25
25
height : true ,
@@ -39,6 +39,7 @@ var uiDialogClasses = "ui-dialog ui-widget ui-widget-content ui-corner-all ",
39
39
$ . widget ( "ui.dialog" , {
40
40
version : "@VERSION" ,
41
41
options : {
42
+ appendTo : null ,
42
43
autoOpen : true ,
43
44
buttons : { } ,
44
45
closeOnEscape : true ,
@@ -89,12 +90,26 @@ $.widget("ui.dialog", {
89
90
90
91
title = options . title || " " ,
91
92
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
+
92
108
uiDialog = ( this . uiDialog = $ ( "<div>" ) )
93
109
. addClass ( uiDialogClasses + options . dialogClass )
94
110
. css ( {
95
111
display : "none" ,
96
- outline : 0 , // TODO: move to stylesheet
97
- zIndex : options . zIndex
112
+ outline : 0 // TODO: move to stylesheet
98
113
} )
99
114
// setting tabIndex makes the div focusable
100
115
. attr ( "tabIndex" , - 1 )
@@ -105,10 +120,7 @@ $.widget("ui.dialog", {
105
120
event . preventDefault ( ) ;
106
121
}
107
122
} )
108
- . mousedown ( function ( event ) {
109
- that . moveToTop ( false , event ) ;
110
- } )
111
- . appendTo ( "body" ) ,
123
+ . appendTo ( appendToTarget ( ) ) ,
112
124
113
125
uiDialogContent = this . element
114
126
. show ( )
@@ -257,62 +269,13 @@ $.widget("ui.dialog", {
257
269
258
270
$ . ui . dialog . overlay . resize ( ) ;
259
271
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
-
274
272
return this ;
275
273
} ,
276
274
277
275
isOpen : function ( ) {
278
276
return this . _isOpen ;
279
277
} ,
280
278
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
-
316
279
open : function ( ) {
317
280
if ( this . _isOpen ) {
318
281
return ;
@@ -326,7 +289,6 @@ $.widget("ui.dialog", {
326
289
this . _position ( options . position ) ;
327
290
uiDialog . show ( options . show ) ;
328
291
this . overlay = options . modal ? new $ . ui . dialog . overlay ( this ) : null ;
329
- this . moveToTop ( true ) ;
330
292
331
293
// set focus to the first tabbable element in the content area or the first button
332
294
// if there are no tabbable elements, set focus on the dialog itself
@@ -694,22 +656,10 @@ $.extend( $.ui.dialog.overlay, {
694
656
}
695
657
) . join ( " " ) ,
696
658
create : function ( dialog ) {
659
+
697
660
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?
713
663
714
664
// handle window resize
715
665
$ ( window ) . bind ( "resize.dialog-overlay" , $ . ui . dialog . overlay . resize ) ;
@@ -756,12 +706,6 @@ $.extend( $.ui.dialog.overlay, {
756
706
}
757
707
758
708
$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 ;
765
709
} ,
766
710
767
711
height : function ( ) {
0 commit comments