@@ -39,7 +39,7 @@ test("widget method", function() {
39
39
dialog . remove ( ) ;
40
40
} ) ;
41
41
42
- test ( "focus tabbable" , function ( ) {
42
+ asyncTest ( "focus tabbable" , function ( ) {
43
43
expect ( 5 ) ;
44
44
var el ,
45
45
options = {
@@ -49,36 +49,59 @@ test( "focus tabbable", function() {
49
49
} ]
50
50
} ;
51
51
52
- el = $ ( "<div><input><input autofocus></div>" ) . dialog ( options ) ;
53
- equal ( document . activeElement , el . find ( "input" ) [ 1 ] , "1. first element inside the dialog matching [autofocus]" ) ;
54
- el . remove ( ) ;
52
+ function checkFocus ( markup , options , testFn , next ) {
53
+ el = $ ( markup ) . dialog ( options ) ;
54
+ setTimeout ( function ( ) {
55
+ testFn ( ) ;
56
+ el . remove ( ) ;
57
+ setTimeout ( next ) ;
58
+ } ) ;
59
+ }
55
60
56
- // IE8 fails to focus the input, <body> ends up being the activeElement
57
- // so wait for that stupid browser
58
- stop ( ) ;
59
- setTimeout ( function ( ) {
60
- el = $ ( "<div><input><input></div>" ) . dialog ( options ) ;
61
- equal ( document . activeElement , el . find ( "input" ) [ 0 ] , "2. tabbable element inside the content element" ) ;
62
- el . remove ( ) ;
61
+ function step1 ( ) {
62
+ checkFocus ( "<div><input><input autofocus></div>" , options , function ( ) {
63
+ equal ( document . activeElement , el . find ( "input" ) [ 1 ] ,
64
+ "1. first element inside the dialog matching [autofocus]" ) ;
65
+ } , step2 ) ;
66
+ }
63
67
64
- el = $ ( "<div>text</div>" ) . dialog ( options ) ;
65
- equal ( document . activeElement , el . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) [ 0 ] , "3. tabbable element inside the buttonpane" ) ;
66
- el . remove ( ) ;
68
+ function step2 ( ) {
69
+ checkFocus ( "<div><input><input></div>" , options , function ( ) {
70
+ equal ( document . activeElement , el . find ( "input" ) [ 0 ] ,
71
+ "2. tabbable element inside the content element" ) ;
72
+ } , step3 ) ;
73
+ }
67
74
68
- el = $ ( "<div>text</div>" ) . dialog ( ) ;
69
- equal ( document . activeElement , el . dialog ( "widget" ) . find ( ".ui-dialog-titlebar .ui-dialog-titlebar-close" ) [ 0 ] , "4. the close button" ) ;
70
- el . remove ( ) ;
75
+ function step3 ( ) {
76
+ checkFocus ( "<div>text</div>" , options , function ( ) {
77
+ equal ( document . activeElement ,
78
+ el . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) [ 0 ] ,
79
+ "3. tabbable element inside the buttonpane" ) ;
80
+ } , step4 ) ;
81
+ }
82
+
83
+ function step4 ( ) {
84
+ checkFocus ( "<div>text</div>" , { } , function ( ) {
85
+ equal ( document . activeElement ,
86
+ el . dialog ( "widget" ) . find ( ".ui-dialog-titlebar .ui-dialog-titlebar-close" ) [ 0 ] ,
87
+ "4. the close button" ) ;
88
+ } , step5 ) ;
89
+ }
71
90
91
+ function step5 ( ) {
72
92
el = $ ( "<div>text</div>" ) . dialog ( {
73
93
autoOpen : false
74
94
} ) ;
75
95
el . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . hide ( ) ;
76
96
el . dialog ( "open" ) ;
77
- equal ( document . activeElement , el . parent ( ) [ 0 ] , "5. the dialog itself" ) ;
78
- el . remove ( ) ;
97
+ setTimeout ( function ( ) {
98
+ equal ( document . activeElement , el . parent ( ) [ 0 ] , "5. the dialog itself" ) ;
99
+ el . remove ( ) ;
100
+ start ( ) ;
101
+ } ) ;
102
+ }
79
103
80
- start ( ) ;
81
- } , 13 ) ;
104
+ step1 ( ) ;
82
105
} ) ;
83
106
84
107
test ( "#7960: resizable handles below modal overlays" , function ( ) {
@@ -93,10 +116,10 @@ test( "#7960: resizable handles below modal overlays", function() {
93
116
dialog . dialog ( "destroy" ) ;
94
117
} ) ;
95
118
96
- asyncTest ( "#3123: Prevent tabbing out of modal dialogs" , function ( ) {
119
+ asyncTest ( "Prevent tabbing out of dialogs" , function ( ) {
97
120
expect ( 3 ) ;
98
121
99
- var el = $ ( "<div><input id='t3123-first' ><input id='t3123-last' ></div>" ) . dialog ( { modal : true } ) ,
122
+ var el = $ ( "<div><input><input></div>" ) . dialog ( ) ,
100
123
inputs = el . find ( "input" ) ,
101
124
widget = el . dialog ( "widget" ) [ 0 ] ;
102
125
@@ -105,21 +128,23 @@ asyncTest( "#3123: Prevent tabbing out of modal dialogs", function() {
105
128
106
129
// check shift tab
107
130
$ ( document . activeElement ) . simulate ( "keydown" , { keyCode : $ . ui . keyCode . TAB , shiftKey : true } ) ;
108
- setTimeout ( checkShiftTab , 2 ) ;
131
+ setTimeout ( checkShiftTab ) ;
109
132
}
110
133
111
134
function checkShiftTab ( ) {
112
135
ok ( $ . contains ( widget , document . activeElement ) , "Shift-Tab key event moved focus within the modal" ) ;
113
136
114
137
el . remove ( ) ;
115
- start ( ) ;
138
+ setTimeout ( start ) ;
116
139
}
117
140
118
- inputs . eq ( 1 ) . focus ( ) ;
119
- equal ( document . activeElement , inputs [ 1 ] , "Focus set on second input" ) ;
120
- inputs . eq ( 1 ) . simulate ( "keydown" , { keyCode : $ . ui . keyCode . TAB } ) ;
141
+ inputs [ 1 ] . focus ( ) ;
142
+ setTimeout ( function ( ) {
143
+ equal ( document . activeElement , inputs [ 1 ] , "Focus set on second input" ) ;
144
+ inputs . eq ( 1 ) . simulate ( "keydown" , { keyCode : $ . ui . keyCode . TAB } ) ;
121
145
122
- setTimeout ( checkTab , 2 ) ;
146
+ setTimeout ( checkTab ) ;
147
+ } ) ;
123
148
} ) ;
124
149
125
150
} ) ( jQuery ) ;
0 commit comments