@@ -59,90 +59,94 @@ asyncTest( "focus tabbable", function() {
5959
6060 element = $ ( markup ) . dialog ( options ) ;
6161 setTimeout ( function ( ) {
62- testFn ( ) ;
63- element . remove ( ) ;
64- setTimeout ( next ) ;
62+ testFn ( function done ( ) {
63+ element . remove ( ) ;
64+ setTimeout ( next ) ;
65+ } ) ;
6566 } ) ;
6667 }
6768
6869 function step1 ( ) {
69- element = $ ( "<div><input><input></div>" ) . dialog ( options ) ;
70- setTimeout ( function ( ) {
70+ checkFocus ( "<div><input><input></div>" , options , function ( done ) {
7171 var input = element . find ( "input:last" ) . focus ( ) . blur ( ) ;
7272 element . dialog ( "instance" ) . _focusTabbable ( ) ;
7373 setTimeout ( function ( ) {
7474 equal ( document . activeElement , input [ 0 ] ,
7575 "1. an element that was focused previously." ) ;
76- element . remove ( ) ;
77- setTimeout ( step2 ) ;
76+ done ( ) ;
7877 } ) ;
79- } ) ;
78+ } , step2 ) ;
8079 }
8180
8281 function step2 ( ) {
83- checkFocus ( "<div><input><input autofocus></div>" , options , function ( ) {
82+ checkFocus ( "<div><input><input autofocus></div>" , options , function ( done ) {
8483 equal ( document . activeElement , element . find ( "input" ) [ 1 ] ,
8584 "2. first element inside the dialog matching [autofocus]" ) ;
85+ done ( ) ;
8686 } , step3 ) ;
8787 }
8888
8989 function step3 ( ) {
90- checkFocus ( "<div><input><input></div>" , options , function ( ) {
90+ checkFocus ( "<div><input><input></div>" , options , function ( done ) {
9191 equal ( document . activeElement , element . find ( "input" ) [ 0 ] ,
9292 "3. tabbable element inside the content element" ) ;
93+ done ( ) ;
9394 } , step4 ) ;
9495 }
9596
9697 function step4 ( ) {
97- checkFocus ( "<div>text</div>" , options , function ( ) {
98+ checkFocus ( "<div>text</div>" , options , function ( done ) {
9899 equal ( document . activeElement ,
99100 element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) [ 0 ] ,
100101 "4. tabbable element inside the buttonpane" ) ;
102+ done ( ) ;
101103 } , step5 ) ;
102104 }
103105
104106 function step5 ( ) {
105- checkFocus ( "<div>text</div>" , { } , function ( ) {
107+ checkFocus ( "<div>text</div>" , { } , function ( done ) {
106108 equal ( document . activeElement ,
107109 element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar .ui-dialog-titlebar-close" ) [ 0 ] ,
108110 "5. the close button" ) ;
111+ done ( ) ;
109112 } , step6 ) ;
110113 }
111114
112115 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 ) ;
123124 }
124125
125126 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+ ) ;
146150 }
147151
148152 step1 ( ) ;
0 commit comments