@@ -68,30 +68,48 @@ $.widget("ui.dialog", {
68
68
resizable : true ,
69
69
show : null ,
70
70
title : "" ,
71
- width : 300
71
+ width : 300 ,
72
+
73
+ // callbacks
74
+ beforeClose : null ,
75
+ close : null ,
76
+ drag : null ,
77
+ dragStart : null ,
78
+ dragStop : null ,
79
+ focus : null ,
80
+ open : null ,
81
+ resize : null ,
82
+ resizeStart : null ,
83
+ resizeStop : null
72
84
} ,
73
85
74
86
_create : function ( ) {
75
87
this . originalTitle = this . element . attr ( "title" ) ;
76
88
// #5742 - .attr() might return a DOMElement
89
+ // TODO WTF?
77
90
if ( typeof this . originalTitle !== "string" ) {
78
91
this . originalTitle = "" ;
79
92
}
80
93
this . oldPosition = {
81
94
parent : this . element . parent ( ) ,
82
95
index : this . element . parent ( ) . children ( ) . index ( this . element )
83
96
} ;
97
+ // TODO don't overwrite options
84
98
this . options . title = this . options . title || this . originalTitle ;
85
99
var that = this ,
86
100
options = this . options ,
87
101
102
+ // TODO make this the default for the title option?
88
103
title = options . title || " " ,
104
+ // TODO should use this.uiDialog instead
89
105
uiDialog ,
106
+ // TODO should use this.uiDialogTitlebar instead
90
107
uiDialogTitlebar ,
91
108
uiDialogTitlebarClose ,
92
109
uiDialogTitle ,
93
110
uiDialogButtonPane ;
94
111
112
+ // TODO extract into _createWrapper
95
113
uiDialog = ( this . uiDialog = $ ( "<div>" ) )
96
114
. addClass ( uiDialogClasses + options . dialogClass )
97
115
. hide ( )
@@ -115,9 +133,10 @@ $.widget("ui.dialog", {
115
133
. addClass ( "ui-dialog-content ui-widget-content" )
116
134
. appendTo ( uiDialog ) ;
117
135
136
+ // TODO extract this and the next three into a _createTitlebar method
118
137
uiDialogTitlebar = ( this . uiDialogTitlebar = $ ( "<div>" ) )
119
- . addClass ( "ui-dialog-titlebar ui-widget-header " +
120
- "ui-corner-all ui-helper-clearfix" )
138
+ . addClass ( "ui-dialog-titlebar ui-widget-header ui-corner-all ui-helper-clearfix" )
139
+ // TODO use _on, call _focusTabbable or _keepFocus
121
140
. bind ( "mousedown" , function ( ) {
122
141
// Dialog isn't getting focus when dragging (#8063)
123
142
uiDialog . focus ( ) ;
@@ -144,18 +163,21 @@ $.widget("ui.dialog", {
144
163
. html ( title )
145
164
. prependTo ( uiDialogTitlebar ) ;
146
165
166
+ // TODO extract this one and the next into a _createButtonPane method
147
167
uiDialogButtonPane = ( this . uiDialogButtonPane = $ ( "<div>" ) )
148
168
. addClass ( "ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" ) ;
149
169
150
170
( this . uiButtonSet = $ ( "<div>" ) )
151
171
. addClass ( "ui-dialog-buttonset" )
152
172
. appendTo ( uiDialogButtonPane ) ;
153
173
174
+ // TODO move into _createWrapper
154
175
uiDialog . attr ( {
155
176
role : "dialog" ,
156
177
"aria-labelledby" : uiDialogTitle . attr ( "id" )
157
178
} ) ;
158
179
180
+ // TODO move into _createWrapper
159
181
// We assume that any existing aria-describedby attribute means
160
182
// that the dialog content is marked up properly
161
183
// otherwise we brute force the content as the description
@@ -165,7 +187,11 @@ $.widget("ui.dialog", {
165
187
} ) ;
166
188
}
167
189
190
+ // TODO use andSelf()
191
+ // TODO get rid of this?! why do we need to disable selection anyway?
168
192
uiDialogTitlebar . find ( "*" ) . add ( uiDialogTitlebar ) . disableSelection ( ) ;
193
+
194
+ // TODO use button? or at least a button element, so that SPACE works?
169
195
this . _hoverable ( uiDialogTitlebarClose ) ;
170
196
this . _focusable ( uiDialogTitlebarClose ) ;
171
197
@@ -176,10 +202,14 @@ $.widget("ui.dialog", {
176
202
this . _makeResizable ( ) ;
177
203
}
178
204
205
+ // TODO merge with _createButtonPane?
179
206
this . _createButtons ( options . buttons ) ;
207
+
180
208
this . _isOpen = false ;
181
209
182
210
// prevent tabbing out of dialogs
211
+ // TODO move into _createWrapper
212
+ // TODO fix formatting
183
213
this . _on ( uiDialog , { keydown : function ( event ) {
184
214
if ( event . keyCode !== $ . ui . keyCode . TAB ) {
185
215
return ;
@@ -217,13 +247,15 @@ $.widget("ui.dialog", {
217
247
. removeUniqueId ( )
218
248
. removeClass ( "ui-dialog-content ui-widget-content" )
219
249
. hide ( )
250
+ // TODO restore old position directly, instead of appending to body first
220
251
. appendTo ( "body" ) ;
221
252
this . uiDialog . remove ( ) ;
222
253
223
254
if ( this . originalTitle ) {
224
255
this . element . attr ( "title" , this . originalTitle ) ;
225
256
}
226
257
258
+ // TODO do this before removing the wrapper
227
259
next = oldPosition . parent . children ( ) . eq ( oldPosition . index ) ;
228
260
// Don't try to place the dialog next to itself (#8613)
229
261
if ( next . length && next [ 0 ] !== this . element [ 0 ] ) {
@@ -244,6 +276,7 @@ $.widget("ui.dialog", {
244
276
return ;
245
277
}
246
278
279
+ // TODO fix yoda-if
247
280
if ( false === this . _trigger ( "beforeClose" , event ) ) {
248
281
return ;
249
282
}
@@ -261,6 +294,7 @@ $.widget("ui.dialog", {
261
294
$ ( this . document [ 0 ] . activeElement ) . blur ( ) ;
262
295
}
263
296
297
+ // TODO shouldn't _hide restore `this` to the instance? would also help tooltip
264
298
this . _hide ( this . uiDialog , this . options . hide , function ( ) {
265
299
that . _trigger ( "close" , event ) ;
266
300
} ) ;
@@ -279,11 +313,14 @@ $.widget("ui.dialog", {
279
313
280
314
open : function ( ) {
281
315
if ( this . _isOpen ) {
316
+ // TODO don't pass silent flag? should probably trigger focus when moving to top again
282
317
this . moveToTop ( null , true ) ;
318
+ // TODO run this only when dialog wasn't focused?
283
319
this . _focusTabbable ( ) ;
284
320
return ;
285
321
}
286
322
323
+ // TODO remove useless tmp vars
287
324
var options = this . options ,
288
325
uiDialog = this . uiDialog ;
289
326
@@ -304,6 +341,7 @@ $.widget("ui.dialog", {
304
341
return this ;
305
342
} ,
306
343
344
+ // TODO check if dialog already has focus, merge with _keepFocus
307
345
_focusTabbable : function ( ) {
308
346
// set focus to the first tabbable element in the content area or the first button
309
347
// if there are no tabbable elements, set focus on the dialog itself
@@ -342,6 +380,7 @@ $.widget("ui.dialog", {
342
380
this . uiDialogButtonPane . remove ( ) ;
343
381
this . uiButtonSet . empty ( ) ;
344
382
383
+ // TODO use jQuery.isEmptyObject()
345
384
if ( typeof buttons === "object" && buttons !== null ) {
346
385
$ . each ( buttons , function ( ) {
347
386
return ! ( hasButtons = true ) ;
@@ -360,6 +399,7 @@ $.widget("ui.dialog", {
360
399
} )
361
400
. appendTo ( that . uiButtonSet ) ;
362
401
if ( $ . fn . button ) {
402
+ // TODO allow passing through button options
363
403
button . button ( ) ;
364
404
}
365
405
} ) ;
@@ -405,6 +445,7 @@ $.widget("ui.dialog", {
405
445
} ) ;
406
446
} ,
407
447
448
+ // TODO why are handles passed by _setOption??
408
449
_makeResizable : function ( handles ) {
409
450
handles = ( handles === undefined ? this . options . resizable : handles ) ;
410
451
var that = this ,
@@ -469,6 +510,7 @@ $.widget("ui.dialog", {
469
510
isVisible ;
470
511
471
512
if ( position ) {
513
+ // TODO we don't support 1.3.2 anymore, clean this mess up
472
514
// deep extending converts arrays to objects in jQuery <= 1.3.2 :-(
473
515
// if (typeof position == 'string' || $.isArray(position)) {
474
516
// myAt = $.isArray(position) ? position : position.split(' ');
@@ -548,9 +590,11 @@ $.widget("ui.dialog", {
548
590
case "dialogClass" :
549
591
uiDialog
550
592
. removeClass ( this . options . dialogClass )
593
+ // TODO why adding uiDialogClasses again? we didn't remove those
551
594
. addClass ( uiDialogClasses + value ) ;
552
595
break ;
553
596
case "disabled" :
597
+ // TODO use toggleClass( "ui-dialog-disabled", value )
554
598
if ( value ) {
555
599
uiDialog . addClass ( "ui-dialog-disabled" ) ;
556
600
} else {
@@ -588,7 +632,8 @@ $.widget("ui.dialog", {
588
632
}
589
633
break ;
590
634
case "title" :
591
- // convert whatever was passed in o a string, for html() to not throw up
635
+ // convert whatever was passed in to a string, for html() to not throw up
636
+ // TODO deduplicate this (see _create)
592
637
$ ( ".ui-dialog-title" , this . uiDialogTitlebar )
593
638
. html ( "" + ( value || " " ) ) ;
594
639
break ;
@@ -640,8 +685,8 @@ $.widget("ui.dialog", {
640
685
} ) ;
641
686
642
687
$ . extend ( $ . ui . dialog , {
688
+ // TODO remove these
643
689
uuid : 0 ,
644
-
645
690
getTitleId : function ( $el ) {
646
691
var id = $el . attr ( "id" ) ;
647
692
if ( ! id ) {
@@ -651,17 +696,20 @@ $.extend($.ui.dialog, {
651
696
return "ui-dialog-title-" + id ;
652
697
} ,
653
698
699
+ // TODO move to dialog instance method
654
700
overlay : function ( dialog ) {
655
701
this . $el = $ . ui . dialog . overlay . create ( dialog ) ;
656
702
}
657
703
} ) ;
658
704
705
+ // TODO get rid of instance list, at least the oldInstance stuff, and inline as dialog methods
659
706
$ . extend ( $ . ui . dialog . overlay , {
660
707
instances : [ ] ,
661
708
// reuse old instances due to IE memory leak with alpha transparency (see #5185)
662
709
oldInstances : [ ] ,
663
710
create : function ( dialog ) {
664
711
if ( this . instances . length === 0 ) {
712
+ // TODO get rid of the timeout, which should remove the need for the #4065 workaround as well
665
713
// prevent use of anchors and inputs
666
714
// we use a setTimeout in case the overlay is created from an
667
715
// event that we're going to be cancelling (see #2804)
0 commit comments