@@ -40,7 +40,7 @@ test("widget method", function() {
40
40
} ) ;
41
41
42
42
asyncTest ( "focus tabbable" , function ( ) {
43
- expect ( 5 ) ;
43
+ expect ( 6 ) ;
44
44
var element ,
45
45
options = {
46
46
buttons : [ {
@@ -50,6 +50,12 @@ asyncTest( "focus tabbable", function() {
50
50
} ;
51
51
52
52
function checkFocus ( markup , options , testFn , next ) {
53
+
54
+ // Support: IE8
55
+ // For some reason the focus doesn't get set properly if we don't
56
+ // focus the body first.
57
+ $ ( "body" ) . focus ( ) ;
58
+
53
59
element = $ ( markup ) . dialog ( options ) ;
54
60
setTimeout ( function ( ) {
55
61
testFn ( ) ;
@@ -59,43 +65,57 @@ asyncTest( "focus tabbable", function() {
59
65
}
60
66
61
67
function step1 ( ) {
68
+ element = $ ( "<div><input><input></div>" ) . dialog ( options ) ;
69
+ setTimeout ( function ( ) {
70
+ var input = element . find ( "input:last" ) . focus ( ) . blur ( ) ;
71
+ element . dialog ( "instance" ) . _focusTabbable ( ) ;
72
+ setTimeout ( function ( ) {
73
+ equal ( document . activeElement , input [ 0 ] ,
74
+ "1. an element that was focused previously." ) ;
75
+ element . remove ( ) ;
76
+ setTimeout ( step2 ) ;
77
+ } ) ;
78
+ } ) ;
79
+ }
80
+
81
+ function step2 ( ) {
62
82
checkFocus ( "<div><input><input autofocus></div>" , options , function ( ) {
63
83
equal ( document . activeElement , element . find ( "input" ) [ 1 ] ,
64
- "1 . first element inside the dialog matching [autofocus]" ) ;
65
- } , step2 ) ;
84
+ "2 . first element inside the dialog matching [autofocus]" ) ;
85
+ } , step3 ) ;
66
86
}
67
87
68
- function step2 ( ) {
88
+ function step3 ( ) {
69
89
checkFocus ( "<div><input><input></div>" , options , function ( ) {
70
90
equal ( document . activeElement , element . find ( "input" ) [ 0 ] ,
71
- "2 . tabbable element inside the content element" ) ;
72
- } , step3 ) ;
91
+ "3 . tabbable element inside the content element" ) ;
92
+ } , step4 ) ;
73
93
}
74
94
75
- function step3 ( ) {
95
+ function step4 ( ) {
76
96
checkFocus ( "<div>text</div>" , options , function ( ) {
77
97
equal ( document . activeElement ,
78
98
element . dialog ( "widget" ) . find ( ".ui-dialog-buttonpane button" ) [ 0 ] ,
79
- "3 . tabbable element inside the buttonpane" ) ;
80
- } , step4 ) ;
99
+ "4 . tabbable element inside the buttonpane" ) ;
100
+ } , step5 ) ;
81
101
}
82
102
83
- function step4 ( ) {
103
+ function step5 ( ) {
84
104
checkFocus ( "<div>text</div>" , { } , function ( ) {
85
105
equal ( document . activeElement ,
86
106
element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar .ui-dialog-titlebar-close" ) [ 0 ] ,
87
- "4 . the close button" ) ;
88
- } , step5 ) ;
107
+ "5 . the close button" ) ;
108
+ } , step6 ) ;
89
109
}
90
110
91
- function step5 ( ) {
111
+ function step6 ( ) {
92
112
element = $ ( "<div>text</div>" ) . dialog ( {
93
113
autoOpen : false
94
114
} ) ;
95
115
element . dialog ( "widget" ) . find ( ".ui-dialog-titlebar-close" ) . hide ( ) ;
96
116
element . dialog ( "open" ) ;
97
117
setTimeout ( function ( ) {
98
- equal ( document . activeElement , element . parent ( ) [ 0 ] , "5 . the dialog itself" ) ;
118
+ equal ( document . activeElement , element . parent ( ) [ 0 ] , "6 . the dialog itself" ) ;
99
119
element . remove ( ) ;
100
120
start ( ) ;
101
121
} ) ;
0 commit comments