22 * mobile flipswitch unit tests
33 */
44( function ( $ ) {
5- var oldTransitions , oldAnimations ;
5+ var oldTransitions , oldAnimations ,
6+ countEvents = function ( element , eventName ) {
7+ var count = 0 ,
8+ events = $ . _data ( element , "events" ) ;
9+
10+ if ( events && events [ eventName ] ) {
11+ count = events [ eventName ] . length ;
12+ }
13+
14+ return count ;
15+ } ,
16+ events = ( function ( ) {
17+ var nameIndex , match , event ,
18+ names = [
19+ "animation" , "transition" ,
20+ "mozAnimation" , "mozTransition" ,
21+ "oAnimation" , "oTransition" ,
22+ "webkitAnimation" , "webkitTransition"
23+ ] ,
24+ element = document . createElement ( "a" ) ,
25+ events = {
26+ animation : { name : "animationend" } ,
27+ transition : { name : "transitionend" }
28+ } ;
29+
30+ for ( nameIndex in names ) {
31+ if ( element . style [ names [ nameIndex ] ] !== undefined ) {
32+ match = names [ nameIndex ] . match ( / ( .* ) ( a n i m a t i o n | t r a n s i t i o n ) $ / i ) ;
33+ event = match [ 2 ] . toLowerCase ( ) ;
34+
35+ // Unprefixed is the best, so do not overwrite if we've already found an
36+ // unprefixed version
37+ if ( events [ event ] . prefix !== "" ) {
38+ events [ event ] = {
39+ name : match [ 1 ] + match [ 2 ] + ( match [ 1 ] ? "End" : "end" ) ,
40+ prefix : match [ 1 ]
41+ } ;
42+ }
43+ }
44+ }
45+
46+ return events ;
47+ } ) ( ) ;
48+
649 module ( "Callbacks: Event" , {
750 teardown : function ( ) {
851 $ ( "#transition-test" )
73116 $ ( "#animation-test" ) . removeClass ( "in" ) ;
74117 }
75118 } ) ;
76- asyncTest ( "call back executes immeditly when animations not supported on device" , function ( ) {
119+ asyncTest ( "callback executes immediately when animations unsupported on device" , function ( ) {
77120 expect ( 2 ) ;
78121 var transitionComplete = false ,
79122 animationComplete = false ;
140183 $ ( "#animation-test" ) . removeClass ( "in" ) ;
141184 }
142185 } ) ;
143- asyncTest ( "Make sure no bidnings when no cssanimation support" , function ( ) {
186+ asyncTest ( "Make sure no bindings when no cssanimation support" , function ( ) {
144187 expect ( 2 ) ;
145188 var transitionComplete = false ,
146189 animationComplete = false ;
167210 $ ( "#animation-test" ) . removeClass ( "in" ) ;
168211 }
169212 } ) ;
170- asyncTest ( "Make sure no bidnings remain after event" , function ( ) {
213+ asyncTest ( "Make sure no bindings remain after event" , function ( ) {
171214 expect ( 2 ) ;
172215 var transitionComplete = false ,
173216 animationComplete = false ;
190233 } , 800 ) ;
191234 } ) ;
192235 module ( "Event Removal: fallback" , {
236+ setup : function ( ) {
237+ $ ( "#transition-test" ) . on ( events . transition . name , $ . noop ) ;
238+ $ ( "#animation-test" ) . on ( events . animation . name , $ . noop ) ;
239+ } ,
193240 teardown : function ( ) {
194241 $ ( "#transition-test" )
195242 . removeClass ( "ui-panel-animate ui-panel-position-left ui-panel-display-overlay" ) ;
196243 $ ( "#animation-test" ) . removeClass ( "in" ) ;
244+ $ ( "#transition-test" ) . off ( events . transition . name , $ . noop ) ;
245+ $ ( "#animation-test" ) . off ( events . animation . name , $ . noop ) ;
197246 }
198247 } ) ;
199- asyncTest ( "Make sure no bidnings remain after fallback" , function ( ) {
248+ asyncTest ( "Make sure no bindings remain after fallback" , function ( ) {
200249 expect ( 2 ) ;
201250 var transitionComplete = false ,
202251 animationComplete = false ;
210259 } ) ;
211260
212261 window . setTimeout ( function ( ) {
213- ok ( $ . _data ( $ ( "#animation-test" ) [ 0 ] , " events" ) === undefined ,
262+ deepEqual ( countEvents ( $ ( "#animation-test" ) [ 0 ] , events . animation . name ) , 1 ,
214263 "no animation bindings remain" ) ;
215- ok ( $ . _data ( $ ( "#transition-test" ) [ 0 ] , " events" ) === undefined ,
264+ deepEqual ( countEvents ( $ ( "#transition-test" ) [ 0 ] , events . transition . name ) , 1 ,
216265 "no transition bindings remain" ) ;
217266 start ( ) ;
218267 } , 1200 ) ;
219268 } ) ;
220- } ) ( jQuery ) ;
269+ } ) ( jQuery ) ;
0 commit comments