12
12
*/
13
13
( function ( $ , undefined ) {
14
14
15
- var rshowhide = / s h o w | h i d e / ;
16
-
17
15
$ . effects . effect . bounce = function ( o ) {
18
16
19
- return this . queue ( function ( ) {
20
-
21
- // Create element
17
+ return this . queue ( function ( next ) {
22
18
var el = $ ( this ) ,
23
- props = [ 'position' , 'top' , 'bottom' , 'left' , 'right' ] ,
19
+ props = [ "position" , "top" , "bottom" , "left" , "right" ] ,
20
+
24
21
// defaults:
25
- mode = $ . effects . setMode ( el , o . mode || 'effect' ) ,
26
- showhide = rshowhide . test ( mode ) ,
27
- direction = o . direction || 'up' ,
22
+ mode = $ . effects . setMode ( el , o . mode || "effect" ) ,
23
+ hide = mode === "hide" ,
24
+ show = mode === "show" ,
25
+ direction = o . direction || "up" ,
28
26
distance = o . distance || 20 ,
29
27
times = o . times || 5 ,
30
28
31
29
// number of internal animations
32
- anims = times * 2 + showhide ,
30
+ anims = times * 2 + ( show || hide ? 1 : 0 ) ,
33
31
speed = o . duration / anims ,
34
32
easing = o . easing ,
35
33
36
34
// utility:
37
- ref = ( direction == 'up' || direction == ' down' ) ? ' top' : ' left' ,
38
- motion = ( direction == 'up' || direction == ' left' ) , // true is positive
35
+ ref = ( direction === "up" || direction === " down" ) ? " top" : " left" ,
36
+ motion = ( direction === "up" || direction === " left" ) ,
39
37
i ,
40
38
upAnim ,
41
39
downAnim ,
@@ -45,8 +43,8 @@ $.effects.effect.bounce = function(o) {
45
43
queuelen = queue . length ;
46
44
47
45
// Avoid touching opacity to prevent clearType and PNG issues in IE
48
- if ( showhide ) {
49
- props . push ( ' opacity' ) ;
46
+ if ( show || hide ) {
47
+ props . push ( " opacity" ) ;
50
48
}
51
49
52
50
$ . effects . save ( el , props ) ;
@@ -55,60 +53,66 @@ $.effects.effect.bounce = function(o) {
55
53
56
54
// default distance for the BIGGEST bounce is the outer Distance / 3
57
55
if ( ! distance ) {
58
- distance = el [ ref == ' top' ? ' outerHeight' : ' outerWidth' ] ( { margin :true } ) / 3 ;
56
+ distance = el [ ref === " top" ? " outerHeight" : " outerWidth" ] ( { margin :true } ) / 3 ;
59
57
}
60
58
61
- if ( mode == ' show' ) {
62
- upAnim = { opacity : 1 } ;
63
- upAnim [ ref ] = 0 ;
59
+ if ( show ) {
60
+ downAnim = { opacity : 1 } ;
61
+ downAnim [ ref ] = 0 ;
64
62
65
- // fade and set the initial position if we are showing
66
- el . css ( 'opacity' , 0 )
63
+ // if we are showing, force opacity 0 and set the initial position
64
+ // then do the "first" animation
65
+ el . css ( "opacity" , 0 )
67
66
. css ( ref , motion ? - distance * 2 : distance * 2 )
68
- . animate ( upAnim , speed , easing ) ;
67
+ . animate ( downAnim , speed , easing ) ;
69
68
}
70
69
71
70
// start at the smallest distance if we are hiding
72
- if ( mode == ' hide' ) {
71
+ if ( hide ) {
73
72
distance = distance / ( ( times - 1 ) * 2 ) ;
74
73
}
75
74
76
- // Bounces up then down (or reversed if motion) -- times * 2 animations happen here
75
+ downAnim = { } ;
76
+ downAnim [ ref ] = 0 ;
77
+ // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
77
78
for ( i = 0 ; i < times ; i ++ ) {
78
79
upAnim = { } ;
79
- downAnim = { } ;
80
- upAnim [ ref ] = ( motion ? '-=' : '+=' ) + distance ;
81
- downAnim [ ref ] = ( motion ? '+=' : '-=' ) + distance ;
80
+ upAnim [ ref ] = ( motion ? "-=" : "+=" ) + distance ;
81
+
82
+ // add the finish callback to the last animation if we aren't hiding
82
83
el . animate ( upAnim , speed , easing )
83
84
. animate ( downAnim , speed , easing ,
84
- ( i == times - 1 ) && ( mode != " hide" ) ? finish : undefined ) ;
85
+ ( ( i === times - 1 ) && ! hide ) ? finish : undefined ) ;
85
86
86
- distance = mode == ' hide' ? distance * 2 : distance / 2 ;
87
+ distance = hide ? distance * 2 : distance / 2 ;
87
88
}
88
89
89
- // Last Bounce
90
- if ( mode == ' hide' ) {
90
+ // Last Bounce when Hiding
91
+ if ( hide ) {
91
92
upAnim = { opacity : 0 } ;
92
- upAnim [ ref ] = ( motion ? '-=' : '+=' ) + distance ;
93
+ upAnim [ ref ] = ( motion ? "-=" : "+=" ) + distance ;
93
94
94
95
el . animate ( upAnim , speed , easing , function ( ) {
95
96
el . hide ( ) ;
96
97
finish ( ) ;
97
98
} ) ;
98
99
}
99
100
101
+ function finish ( ) {
102
+ $ . effects . restore ( el , props ) ;
103
+ $ . effects . removeWrapper ( el ) ;
104
+ if ( o . complete ) {
105
+ o . complete . apply ( el [ 0 ] ) ;
106
+ }
107
+ }
108
+
100
109
// inject all the animations we just queued to be first in line (after "inprogress")
101
110
if ( queuelen > 1 ) {
102
111
queue . splice . apply ( queue ,
103
112
[ 1 , 0 ] . concat ( queue . splice ( queuelen , anims ) ) ) ;
104
113
}
105
- el . dequeue ( ) ;
114
+ next ( ) ;
106
115
107
- function finish ( ) {
108
- $ . effects . restore ( el , props ) ;
109
- $ . effects . removeWrapper ( el ) ;
110
- $ . isFunction ( o . complete ) && o . complete . apply ( el [ 0 ] , arguments ) ;
111
- }
112
116
} ) ;
113
117
114
118
} ;
0 commit comments