aboutsummaryrefslogtreecommitdiffstats
path: root/ui/jquery.effects.bounce.js
diff options
context:
space:
mode:
authorJörn Zaefferer <joern.zaefferer@gmail.com>2011-05-10 17:10:45 +0200
committerJörn Zaefferer <joern.zaefferer@gmail.com>2011-05-10 17:10:45 +0200
commit1426f7edf31f69482a86ac4bca81110cf42f25c6 (patch)
treeb5e7b3943495cd8aa21b82b6560e3524e6c1c54e /ui/jquery.effects.bounce.js
parent5806d6554bfadc4500e97d57d07d6f44d2b90618 (diff)
parentb546f316bedcb74c507378b1460ed5c87d44e213 (diff)
downloadjquery-ui-1426f7edf31f69482a86ac4bca81110cf42f25c6.tar.gz
jquery-ui-1426f7edf31f69482a86ac4bca81110cf42f25c6.zip
Merge remote branch 'origin/master'
Diffstat (limited to 'ui/jquery.effects.bounce.js')
-rw-r--r--ui/jquery.effects.bounce.js146
1 files changed, 82 insertions, 64 deletions
diff --git a/ui/jquery.effects.bounce.js b/ui/jquery.effects.bounce.js
index 8da0feb76..bb386a4f4 100644
--- a/ui/jquery.effects.bounce.js
+++ b/ui/jquery.effects.bounce.js
@@ -12,89 +12,107 @@
*/
(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' ),
- direction = o.direction || 'up',
- distance = o.distance || 20,
- times = o.times || 5,
- speed = (o.duration || 250),
+ mode = $.effects.setMode( el, o.mode || "effect" ),
+ hide = mode === "hide",
+ show = mode === "show",
+ direction = o.direction || "up",
+ distance = o.distance,
+ times = o.times || 5,
+
+ // number of internal animations
+ 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
- i, animation, animation1, animation2;
-
+ ref = ( direction === "up" || direction === "down" ) ? "top" : "left",
+ motion = ( direction === "up" || direction === "left" ),
+ i,
+ upAnim,
+ downAnim,
+
+ // we will need to re-assemble the queue to stack our animations in place
+ queue = el.queue(),
+ queuelen = queue.length;
+
// Avoid touching opacity to prevent clearType and PNG issues in IE
- if ( rshowhide.test( mode ) ) {
- props.push( 'opacity' );
+ if ( show || hide ) {
+ props.push( "opacity" );
}
$.effects.save( el, props );
el.show();
$.effects.createWrapper( el ); // Create Wrapper
+ // 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" ]() / 3;
}
- if ( mode == 'show' ) el.css( 'opacity', 0 ).css( ref, motion ? -distance : distance ); // Shift
- if ( mode == 'hide' ) distance = distance / (times * 2);
- if ( mode != 'hide' ) times--;
-
- // Animate
- if ( mode == 'show' ) {
- animation = {
- opacity: 1
- };
- animation[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el.animate( animation, speed / 2, o.easing);
- distance = distance / 2;
- times--;
- };
-
- // Bounces
- for (i = 0; i < times; i++) {
- animation1 = {};
- animation2 = {};
- animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el.animate( animation1, speed / 2, o.easing ).animate( animation2, speed / 2, o.easing );
- distance = ( mode == 'hide' ) ? distance * 2 : distance / 2;
+
+ if ( show ) {
+ downAnim = { opacity: 1 };
+ downAnim[ ref ] = 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( downAnim, speed, easing );
+ }
+
+ // start at the smallest distance if we are hiding
+ if ( hide ) {
+ distance = distance / Math.pow( 2, times - 1 );
}
- // Last Bounce
- if ( mode == 'hide' ) {
- animation = {
- opacity: 0
- };
- animation[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- el.animate( animation, speed / 2, o.easing, function(){
+ 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 = {};
+ 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 ) && !hide ) ? finish : undefined );
+
+ distance = hide ? distance * 2 : distance / 2;
+ }
+
+ // Last Bounce when Hiding
+ if ( hide ) {
+ upAnim = { opacity: 0 };
+ upAnim[ ref ] = ( motion ? "-=" : "+=" ) + distance;
+
+ el.animate( upAnim, speed, easing, function(){
el.hide();
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
+ finish();
});
- } else {
- animation1 = {};
- animation2 = {};
- animation1[ ref ] = ( motion ? '-=' : '+=' ) + distance;
- animation2[ ref ] = ( motion ? '+=' : '-=' ) + distance;
- el
- .animate( animation1, speed / 2, o.easing )
- .animate( animation2, speed / 2, o.easing, function() {
- $.effects.restore( el, props );
- $.effects.removeWrapper( el );
- $.isFunction( o.complete ) && o.complete.apply( this, arguments );
- });
}
- el.dequeue();
+
+ 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 ) ) );
+ }
+ next();
+
});
};