@@ -86,16 +86,14 @@ $.widget("ui.dialog", {
86
86
titleId = $ . ui . dialog . getTitleId ( self . element ) ,
87
87
88
88
uiDialog = ( self . uiDialog = $ ( "<div>" ) )
89
- . appendTo ( document . body )
90
- . hide ( )
91
89
. addClass ( uiDialogClasses + options . dialogClass )
92
90
. css ( {
91
+ display : "none" ,
92
+ outline : 0 , // TODO: move to stylesheet
93
93
zIndex : options . zIndex
94
94
} )
95
95
// setting tabIndex makes the div focusable
96
96
. attr ( "tabIndex" , - 1 )
97
- // TODO: move to stylesheet
98
- . css ( "outline" , 0 )
99
97
. keydown ( function ( event ) {
100
98
if ( options . closeOnEscape && ! event . isDefaultPrevented ( ) && event . keyCode &&
101
99
event . keyCode === $ . ui . keyCode . ESCAPE ) {
@@ -156,6 +154,8 @@ $.widget("ui.dialog", {
156
154
self . _createButtons ( options . buttons ) ;
157
155
self . _isOpen = false ;
158
156
157
+ uiDialog . appendTo ( document . body ) ;
158
+
159
159
if ( $ . fn . bgiframe ) {
160
160
uiDialog . bgiframe ( ) ;
161
161
}
@@ -310,9 +310,14 @@ $.widget("ui.dialog", {
310
310
311
311
// set focus to the first tabbable element in the content area or the first button
312
312
// if there are no tabbable elements, set focus on the dialog itself
313
- $ ( self . element . find ( ":tabbable" ) . get ( ) . concat (
314
- uiDialog . find ( ".ui-dialog-buttonpane :tabbable" ) . get ( ) . concat (
315
- uiDialog . get ( ) ) ) ) . eq ( 0 ) . focus ( ) ;
313
+ var hasFocus = self . element . find ( ":tabbable" ) ;
314
+ if ( ! hasFocus . length ) {
315
+ hasFocus = uiDialog . find ( ".ui-dialog-buttonpane :tabbable" ) ;
316
+ if ( ! hasFocus . length ) {
317
+ hasFocus = uiDialog ;
318
+ }
319
+ }
320
+ hasFocus . eq ( 0 ) . focus ( ) ;
316
321
317
322
self . _isOpen = true ;
318
323
self . _trigger ( "open" ) ;
@@ -322,12 +327,7 @@ $.widget("ui.dialog", {
322
327
323
328
_createButtons : function ( buttons ) {
324
329
var self = this ,
325
- hasButtons = false ,
326
- uiDialogButtonPane = $ ( "<div>" )
327
- . addClass ( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ) ,
328
- uiButtonSet = $ ( "<div>" )
329
- . addClass ( "ui-dialog-buttonset" )
330
- . appendTo ( uiDialogButtonPane ) ;
330
+ hasButtons = false ;
331
331
332
332
// if we already have a button pane, remove it
333
333
self . uiDialog . find ( ".ui-dialog-buttonpane" ) . remove ( ) ;
@@ -338,6 +338,12 @@ $.widget("ui.dialog", {
338
338
} ) ;
339
339
}
340
340
if ( hasButtons ) {
341
+ var uiDialogButtonPane = $ ( "<div>" )
342
+ . addClass ( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ) ,
343
+ uiButtonSet = $ ( "<div>" )
344
+ . addClass ( "ui-dialog-buttonset" )
345
+ . appendTo ( uiDialogButtonPane ) ;
346
+
341
347
$ . each ( buttons , function ( name , props ) {
342
348
props = $ . isFunction ( props ) ?
343
349
{ click : props , text : name } :
0 commit comments