aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.effects.bounce.js
diff options
context:
space:
mode:
authorgnarf <gnarf@gnarf.net>2011-05-01 03:44:33 -0500
committergnarf <gnarf@gnarf.net>2011-05-01 03:44:33 -0500
commit321fd390579d38641c7adc0fa1ebe988bca3fde5 (patch)
treebda0764829459324b60fd8600a3fba5dc620850a /ui/jquery.effects.bounce.js
parentcc2342ac31cc618271de7c5e2fa20fad79d6aad8 (diff)
downloadjquery-ui-321fd390579d38641c7adc0fa1ebe988bca3fde5.tar.gz
jquery-ui-321fd390579d38641c7adc0fa1ebe988bca3fde5.zip
Some minor tweaks to the effects, trying to clean up code a bit + style guidance
Diffstat (limited to 'ui/jquery.effects.bounce.js')
-rw-r--r--ui/jquery.effects.bounce.js78
1 files changed, 41 insertions, 37 deletions
diff --git a/ui/jquery.effects.bounce.js b/ui/jquery.effects.bounce.js
index 4ccf4c77d..1ffd5ed5a 100644
--- a/ui/jquery.effects.bounce.js
+++ b/ui/jquery.effects.bounce.js
@@ -12,30 +12,28 @@
*/
(function( $, undefined ) {
-var rshowhide = /show|hide/;
-
$.effects.effect.bounce = function(o) {
- return this.queue(function() {
-
- // Create element
+ return this.queue( function( next ) {
var el = $( this ),
- props = [ 'position', 'top', 'bottom', 'left', 'right' ],
+ props = [ "position", "top", "bottom", "left", "right" ],
+
// defaults:
- mode = $.effects.setMode( el, o.mode || 'effect' ),
- showhide = rshowhide.test( mode ),
- direction = o.direction || 'up',
+ mode = $.effects.setMode( el, o.mode || "effect" ),
+ hide = mode === "hide",
+ show = mode === "show",
+ direction = o.direction || "up",
distance = o.distance || 20,
times = o.times || 5,
// number of internal animations
- anims = times * 2 + showhide,
+ anims = times * 2 + ( show || hide ? 1 : 0 ),
speed = o.duration / anims,
easing = o.easing,
// utility:
- ref = ( direction == 'up' || direction == 'down' ) ? 'top' : 'left',
- motion = ( direction == 'up' || direction == 'left' ), // true is positive
+ ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
+ motion = ( direction === "up" || direction === "left" ),
i,
upAnim,
downAnim,
@@ -45,8 +43,8 @@ $.effects.effect.bounce = function(o) {
queuelen = queue.length;
// Avoid touching opacity to prevent clearType and PNG issues in IE
- if ( showhide ) {
- props.push( 'opacity' );
+ if ( show || hide ) {
+ props.push( "opacity" );
}
$.effects.save( el, props );
@@ -55,41 +53,44 @@ $.effects.effect.bounce = function(o) {
// default distance for the BIGGEST bounce is the outer Distance / 3
if ( !distance ) {
- distance = el[ ref == 'top' ? 'outerHeight' : 'outerWidth' ]({ margin:true }) / 3;
+ distance = el[ ref === "top" ? "outerHeight" : "outerWidth" ]({ margin:true }) / 3;
}
- if ( mode == 'show' ) {
- upAnim = { opacity: 1 };
- upAnim[ ref ] = 0;
+ if ( show ) {
+ downAnim = { opacity: 1 };
+ downAnim[ ref ] = 0;
- // fade and set the initial position if we are showing
- el.css( 'opacity', 0 )
+ // if we are showing, force opacity 0 and set the initial position
+ // then do the "first" animation
+ el.css( "opacity", 0 )
.css( ref, motion ? -distance*2 : distance*2 )
- .animate( upAnim, speed, easing );
+ .animate( downAnim, speed, easing );
}
// start at the smallest distance if we are hiding
- if ( mode == 'hide' ) {
+ if ( hide ) {
distance = distance / ( ( times - 1 ) * 2 );
}
- // Bounces up then down (or reversed if motion) -- times * 2 animations happen here
+ downAnim = {};
+ downAnim[ ref ] = 0;
+ // Bounces up/down/left/right then back to 0 -- times * 2 animations happen here
for ( i = 0; i < times; i++ ) {
upAnim = {};
- downAnim = {};
- upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- downAnim[ ref ] = ( motion ? '+=' : '-=' ) + distance;
+ upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
+
+ // add the finish callback to the last animation if we aren't hiding
el.animate( upAnim, speed, easing )
.animate( downAnim, speed, easing,
- ( i == times - 1 ) && ( mode != "hide" ) ? finish : undefined );
+ ( ( i === times - 1 ) && !hide ) ? finish : undefined );
- distance = mode == 'hide' ? distance * 2 : distance / 2;
+ distance = hide ? distance * 2 : distance / 2;
}
- // Last Bounce
- if ( mode == 'hide' ) {
+ // Last Bounce when Hiding
+ if ( hide ) {
upAnim = { opacity: 0 };
- upAnim[ ref ] = ( motion ? '-=' : '+=' ) + distance;
+ upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
el.animate( upAnim, speed, easing, function(){
el.hide();
@@ -97,18 +98,21 @@ $.effects.effect.bounce = function(o) {
});
}
+ function finish() {
+ $.effects.restore( el, props );
+ $.effects.removeWrapper( el );
+ if ( o.complete ) {
+ o.complete.apply( el[ 0 ] );
+ }
+ }
+
// inject all the animations we just queued to be first in line (after "inprogress")
if ( queuelen > 1) {
queue.splice.apply( queue,
[ 1, 0 ].concat( queue.splice( queuelen, anims ) ) );
}
- el.dequeue();
+ next();
- function finish() {
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( el[ 0 ], arguments );
- }
});
};