@@ -59,90 +59,94 @@ asyncTest( "focus tabbable", function() {
59
59
60
60
element = $ ( markup ) . dialog ( options ) ;
61
61
setTimeout ( function ( ) {
62
- testFn ( ) ;
63
- element . remove ( ) ;
64
- setTimeout ( next ) ;
62
+ testFn ( function done ( ) {
63
+ element . remove ( ) ;
64
+ setTimeout ( next ) ;
65
+ } ) ;
65
66
} ) ;
66
67
}
67
68
68
69
function step1 ( ) {
69
- element = $ ( "<div><input><input></div>" ) . dialog ( options ) ;
70
- setTimeout ( function ( ) {
70
+ checkFocus ( "<div><input><input></div>" , options , function ( done ) {
71
71
var input = element . find ( "input:last" ) . focus ( ) . blur ( ) ;
72
72
element . dialog ( "instance" ) . _focusTabbable ( ) ;
73
73
setTimeout ( function ( ) {
74
74
equal ( document . activeElement , input [ 0 ] ,
75
75
"1. an element that was focused previously." ) ;
76
- element . remove ( ) ;
77
- setTimeout ( step2 ) ;
76
+ done ( ) ;
78
77
} ) ;
79
- } ) ;
78
+ } , step2 ) ;
80
79
}
81
80
82
81
function step2 ( ) {
83
- checkFocus ( "<div><input><input autofocus></div>" , options , function ( ) {
82
+ checkFocus ( "<div><input><input autofocus></div>" , options , function ( done ) {
84
83
equal ( document . activeElement , element . find ( "input" ) [ 1 ] ,
85
84
"2. first element inside the dialog matching [autofocus]" ) ;
85
+ done ( ) ;
86
86
} , step3 ) ;
87
87
}
88
88
89
89
function step3 ( ) {
90
- checkFocus ( "<div><input><input></div>" , options , function ( ) {
90
+ checkFocus ( "<div><input><input></div>" , options , function ( done ) {
91
91
equal ( document . activeElement , element . find ( "input" ) [ 0 ] ,
92
92
"3. tabbable element inside the content element" ) ;
93
+ done ( ) ;
93
94
} , step4 ) ;
94
95
}
95
96
96
97
function step4 ( ) {
97
- checkFocus ( "<div>text</div>" , options , function ( ) {
98
+ checkFocus ( "<div>text</div>" , options , function ( done ) {
98
99
equal ( document . activeElement ,
99
100
element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) [ 0 ] ,
100
101
"4. tabbable element inside the buttonpane" ) ;
102
+ done ( ) ;
101
103
} , step5 ) ;
102
104
}
103
105
104
106
function step5 ( ) {
105
- checkFocus ( "<div>text</div>" , { } , function ( ) {
107
+ checkFocus ( "<div>text</div>" , { } , function ( done ) {
106
108
equal ( document . activeElement ,
107
109
element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar .ui-dialog-titlebar-close" ) [ 0 ] ,
108
110
"5. the close button" ) ;
111
+ done ( ) ;
109
112
} , step6 ) ;
110
113
}
111
114
112
115
function step6 ( ) {
113
- element = $ ( "<div>text</div>" ) . dialog ( {
114
- autoOpen : false
115
- } ) ;
116
- element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . hide ( ) ;
117
- element . dialog ( "open" ) ;
118
- setTimeout ( function ( ) {
119
- equal ( document . activeElement , element . parent ( ) [ 0 ] , "6. the dialog itself" ) ;
120
- element . remove ( ) ;
121
- setTimeout ( step7 ) ;
122
- } ) ;
116
+ checkFocus ( "<div>text</div>" , { autoOpen : false } , function ( done ) {
117
+ element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . hide ( ) ;
118
+ element . dialog ( "open" ) ;
119
+ setTimeout ( function ( ) {
120
+ equal ( document . activeElement , element . parent ( ) [ 0 ] , "6. the dialog itself" ) ;
121
+ done ( ) ;
122
+ } ) ;
123
+ } , step7 ) ;
123
124
}
124
125
125
126
function step7 ( ) {
126
- element = $ ( "<div><input name='0'><input name='1' autofocus></div>" ) . dialog ( {
127
- open : function ( ) {
128
- var inputs = $ ( this ) . find ( "input" ) ;
129
- inputs . last ( ) . keydown ( function ( event ) {
130
- event . preventDefault ( ) ;
131
- inputs . first ( ) . focus ( ) ;
132
- } ) ;
133
- }
134
- } ) ;
135
- setTimeout ( function ( ) {
136
- var inputs = element . find ( "input" ) ;
137
- equal ( document . activeElement , inputs [ 1 ] , "Focus starts on second input" ) ;
138
- inputs . last ( ) . simulate ( "keydown" , { keyCode : $ . ui . keyCode . TAB } ) ;
139
- setTimeout ( function ( ) {
140
- equal ( document . activeElement , inputs [ 0 ] ,
141
- "Honor preventDefault, allowing custom focus management" ) ;
142
- element . remove ( ) ;
143
- start ( ) ;
144
- } , 50 ) ;
145
- } ) ;
127
+ checkFocus (
128
+ "<div><input><input autofocus></div>" ,
129
+ {
130
+ open : function ( ) {
131
+ var inputs = $ ( this ) . find ( "input" ) ;
132
+ inputs . last ( ) . keydown ( function ( event ) {
133
+ event . preventDefault ( ) ;
134
+ inputs . first ( ) . focus ( ) ;
135
+ } ) ;
136
+ }
137
+ } ,
138
+ function ( done ) {
139
+ var inputs = element . find ( "input" ) ;
140
+ equal ( document . activeElement , inputs [ 1 ] , "Focus starts on second input" ) ;
141
+ inputs . last ( ) . simulate ( "keydown" , { keyCode : $ . ui . keyCode . TAB } ) ;
142
+ setTimeout ( function ( ) {
143
+ equal ( document . activeElement , inputs [ 0 ] ,
144
+ "Honor preventDefault, allowing custom focus management" ) ;
145
+ done ( ) ;
146
+ } , 50 ) ;
147
+ } ,
148
+ start
149
+ ) ;
146
150
}
147
151
148
152
step1 ( ) ;
0 commit comments