diff options
Diffstat (limited to 'libs/bower_components/jquery/src/effects.js')
-rw-r--r-- | libs/bower_components/jquery/src/effects.js | 198 |
1 files changed, 91 insertions, 107 deletions
diff --git a/libs/bower_components/jquery/src/effects.js b/libs/bower_components/jquery/src/effects.js index 0469eefb62..93ea0d95de 100644 --- a/libs/bower_components/jquery/src/effects.js +++ b/libs/bower_components/jquery/src/effects.js @@ -1,81 +1,33 @@ -define([ +define( [ "./core", - "./var/pnum", + "./effects/support", + "./var/rcssNum", + "./var/rnotwhite", "./css/var/cssExpand", "./css/var/isHidden", + "./css/adjustCSS", "./css/defaultDisplay", - "./effects/support", + "./var/document", "./core/init", "./effects/Tween", "./queue", "./css", "./deferred", "./traversing" -], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, support ) { +], function( jQuery, support, rcssNum, rnotwhite, + cssExpand, isHidden, adjustCSS, defaultDisplay ) { var fxNow, timerId, rfxtypes = /^(?:toggle|show|hide)$/, - rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ), - rrun = /queueHooks$/, - animationPrefilters = [ defaultPrefilter ], - tweeners = { - "*": [ function( prop, value ) { - var tween = this.createTween( prop, value ), - target = tween.cur(), - parts = rfxnum.exec( value ), - unit = parts && parts[ 3 ] || ( jQuery.cssNumber[ prop ] ? "" : "px" ), - - // Starting value computation is required for potential unit mismatches - start = ( jQuery.cssNumber[ prop ] || unit !== "px" && +target ) && - rfxnum.exec( jQuery.css( tween.elem, prop ) ), - scale = 1, - maxIterations = 20; - - if ( start && start[ 3 ] !== unit ) { - // Trust units reported by jQuery.css - unit = unit || start[ 3 ]; - - // Make sure we update the tween properties later on - parts = parts || []; - - // Iteratively approximate from a nonzero starting point - start = +target || 1; - - do { - // If previous iteration zeroed out, double until we get *something* - // Use a string for doubling factor so we don't accidentally see scale as unchanged below - scale = scale || ".5"; - - // Adjust and apply - start = start / scale; - jQuery.style( tween.elem, prop, start + unit ); - - // Update scale, tolerating zero or NaN from tween.cur() - // And breaking the loop if scale is unchanged or perfect, or if we've just had enough - } while ( scale !== (scale = tween.cur() / target) && scale !== 1 && --maxIterations ); - } - - // Update tween properties - if ( parts ) { - start = tween.start = +start || +target || 0; - tween.unit = unit; - // If a +=/-= token was provided, we're doing a relative animation - tween.end = parts[ 1 ] ? - start + ( parts[ 1 ] + 1 ) * parts[ 2 ] : - +parts[ 2 ]; - } - - return tween; - } ] - }; + rrun = /queueHooks$/; // Animations created synchronously will run synchronously function createFxNow() { - setTimeout(function() { + window.setTimeout( function() { fxNow = undefined; - }); + } ); return ( fxNow = jQuery.now() ); } @@ -102,11 +54,11 @@ function genFx( type, includeWidth ) { function createTween( value, prop, animation ) { var tween, - collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ), + collection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ "*" ] ), index = 0, length = collection.length; for ( ; index < length; index++ ) { - if ( (tween = collection[ index ].call( animation, prop, value )) ) { + if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) { // we're done with this property return tween; @@ -137,20 +89,22 @@ function defaultPrefilter( elem, props, opts ) { } hooks.unqueued++; - anim.always(function() { + anim.always( function() { + // doing this makes sure that the complete handler will be called // before this completes - anim.always(function() { + anim.always( function() { hooks.unqueued--; if ( !jQuery.queue( elem, "fx" ).length ) { hooks.empty.fire(); } - }); - }); + } ); + } ); } // height/width overflow pass if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) { + // Make sure that nothing sneaks out // Record all 3 overflow attributes because IE does not // change the overflow attribute when overflowX and @@ -180,11 +134,11 @@ function defaultPrefilter( elem, props, opts ) { if ( opts.overflow ) { style.overflow = "hidden"; if ( !support.shrinkWrapBlocks() ) { - anim.always(function() { + anim.always( function() { style.overflow = opts.overflow[ 0 ]; style.overflowX = opts.overflow[ 1 ]; style.overflowY = opts.overflow[ 2 ]; - }); + } ); } } @@ -196,7 +150,8 @@ function defaultPrefilter( elem, props, opts ) { toggle = toggle || value === "toggle"; if ( value === ( hidden ? "hide" : "show" ) ) { - // If there is dataShow left over from a stopped hide or show and we are going to proceed with show, we should pretend to be hidden + // If there is dataShow left over from a stopped hide or show + // and we are going to proceed with show, we should pretend to be hidden if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) { hidden = true; } else { @@ -227,17 +182,17 @@ function defaultPrefilter( elem, props, opts ) { if ( hidden ) { jQuery( elem ).show(); } else { - anim.done(function() { + anim.done( function() { jQuery( elem ).hide(); - }); + } ); } - anim.done(function() { + anim.done( function() { var prop; jQuery._removeData( elem, "fxshow" ); for ( prop in orig ) { jQuery.style( elem, prop, orig[ prop ] ); } - }); + } ); for ( prop in orig ) { tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim ); @@ -251,7 +206,7 @@ function defaultPrefilter( elem, props, opts ) { } // If this is a noop like .hide().hide(), restore an overwritten display value - } else if ( (display === "none" ? defaultDisplay( elem.nodeName ) : display) === "inline" ) { + } else if ( ( display === "none" ? defaultDisplay( elem.nodeName ) : display ) === "inline" ) { style.display = display; } } @@ -297,18 +252,21 @@ function Animation( elem, properties, options ) { var result, stopped, index = 0, - length = animationPrefilters.length, + length = Animation.prefilters.length, deferred = jQuery.Deferred().always( function() { + // don't match elem in the :animated selector delete tick.elem; - }), + } ), tick = function() { if ( stopped ) { return false; } var currentTime = fxNow || createFxNow(), remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ), - // archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497) + + // Support: Android 2.3 + // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497) temp = remaining / animation.duration || 0, percent = 1 - temp, index = 0, @@ -318,7 +276,7 @@ function Animation( elem, properties, options ) { animation.tweens[ index ].run( percent ); } - deferred.notifyWith( elem, [ animation, percent, remaining ]); + deferred.notifyWith( elem, [ animation, percent, remaining ] ); if ( percent < 1 && length ) { return remaining; @@ -327,10 +285,13 @@ function Animation( elem, properties, options ) { return false; } }, - animation = deferred.promise({ + animation = deferred.promise( { elem: elem, props: jQuery.extend( {}, properties ), - opts: jQuery.extend( true, { specialEasing: {} }, options ), + opts: jQuery.extend( true, { + specialEasing: {}, + easing: jQuery.easing._default + }, options ), originalProperties: properties, originalOptions: options, startTime: fxNow || createFxNow(), @@ -344,6 +305,7 @@ function Animation( elem, properties, options ) { }, stop: function( gotoEnd ) { var index = 0, + // if we are going to the end, we want to run all the tweens // otherwise we skip this part length = gotoEnd ? animation.tweens.length : 0; @@ -358,20 +320,25 @@ function Animation( elem, properties, options ) { // resolve when we played the last frame // otherwise, reject if ( gotoEnd ) { + deferred.notifyWith( elem, [ animation, 1, 0 ] ); deferred.resolveWith( elem, [ animation, gotoEnd ] ); } else { deferred.rejectWith( elem, [ animation, gotoEnd ] ); } return this; } - }), + } ), props = animation.props; propFilter( props, animation.opts.specialEasing ); for ( ; index < length ; index++ ) { - result = animationPrefilters[ index ].call( animation, elem, props, animation.opts ); + result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts ); if ( result ) { + if ( jQuery.isFunction( result.stop ) ) { + jQuery._queueHooks( animation.elem, animation.opts.queue ).stop = + jQuery.proxy( result.stop, result ); + } return result; } } @@ -387,7 +354,7 @@ function Animation( elem, properties, options ) { elem: elem, anim: animation, queue: animation.opts.queue - }) + } ) ); // attach callbacks from options @@ -398,12 +365,21 @@ function Animation( elem, properties, options ) { } jQuery.Animation = jQuery.extend( Animation, { + + tweeners: { + "*": [ function( prop, value ) { + var tween = this.createTween( prop, value ); + adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween ); + return tween; + } ] + }, + tweener: function( props, callback ) { if ( jQuery.isFunction( props ) ) { callback = props; props = [ "*" ]; } else { - props = props.split(" "); + props = props.match( rnotwhite ); } var prop, @@ -412,19 +388,21 @@ jQuery.Animation = jQuery.extend( Animation, { for ( ; index < length ; index++ ) { prop = props[ index ]; - tweeners[ prop ] = tweeners[ prop ] || []; - tweeners[ prop ].unshift( callback ); + Animation.tweeners[ prop ] = Animation.tweeners[ prop ] || []; + Animation.tweeners[ prop ].unshift( callback ); } }, + prefilters: [ defaultPrefilter ], + prefilter: function( callback, prepend ) { if ( prepend ) { - animationPrefilters.unshift( callback ); + Animation.prefilters.unshift( callback ); } else { - animationPrefilters.push( callback ); + Animation.prefilters.push( callback ); } } -}); +} ); jQuery.speed = function( speed, easing, fn ) { var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : { @@ -435,7 +413,8 @@ jQuery.speed = function( speed, easing, fn ) { }; opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration : - opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default; + opt.duration in jQuery.fx.speeds ? + jQuery.fx.speeds[ opt.duration ] : jQuery.fx.speeds._default; // normalize opt.queue - true/undefined/null -> "fx" if ( opt.queue == null || opt.queue === true ) { @@ -458,19 +437,20 @@ jQuery.speed = function( speed, easing, fn ) { return opt; }; -jQuery.fn.extend({ +jQuery.fn.extend( { fadeTo: function( speed, to, easing, callback ) { // show any hidden elements after setting opacity to 0 return this.filter( isHidden ).css( "opacity", 0 ).show() // animate to the value specified - .end().animate({ opacity: to }, speed, easing, callback ); + .end().animate( { opacity: to }, speed, easing, callback ); }, animate: function( prop, speed, easing, callback ) { var empty = jQuery.isEmptyObject( prop ), optall = jQuery.speed( speed, easing, callback ), doAnimation = function() { + // Operate on a copy of prop so per-property easing won't be lost var anim = Animation( this, jQuery.extend( {}, prop ), optall ); @@ -501,7 +481,7 @@ jQuery.fn.extend({ this.queue( type || "fx", [] ); } - return this.each(function() { + return this.each( function() { var dequeue = true, index = type != null && type + "queueHooks", timers = jQuery.timers, @@ -520,7 +500,9 @@ jQuery.fn.extend({ } for ( index = timers.length; index--; ) { - if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) { + if ( timers[ index ].elem === this && + ( type == null || timers[ index ].queue === type ) ) { + timers[ index ].anim.stop( gotoEnd ); dequeue = false; timers.splice( index, 1 ); @@ -533,13 +515,13 @@ jQuery.fn.extend({ if ( dequeue || !gotoEnd ) { jQuery.dequeue( this, type ); } - }); + } ); }, finish: function( type ) { if ( type !== false ) { type = type || "fx"; } - return this.each(function() { + return this.each( function() { var index, data = jQuery._data( this ), queue = data[ type + "queue" ], @@ -574,24 +556,24 @@ jQuery.fn.extend({ // turn off finishing flag delete data.finish; - }); + } ); } -}); +} ); -jQuery.each([ "toggle", "show", "hide" ], function( i, name ) { +jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) { var cssFn = jQuery.fn[ name ]; jQuery.fn[ name ] = function( speed, easing, callback ) { return speed == null || typeof speed === "boolean" ? cssFn.apply( this, arguments ) : this.animate( genFx( name, true ), speed, easing, callback ); }; -}); +} ); // Generate shortcuts for custom animations -jQuery.each({ - slideDown: genFx("show"), - slideUp: genFx("hide"), - slideToggle: genFx("toggle"), +jQuery.each( { + slideDown: genFx( "show" ), + slideUp: genFx( "hide" ), + slideToggle: genFx( "toggle" ), fadeIn: { opacity: "show" }, fadeOut: { opacity: "hide" }, fadeToggle: { opacity: "toggle" } @@ -599,7 +581,7 @@ jQuery.each({ jQuery.fn[ name ] = function( speed, easing, callback ) { return this.animate( props, speed, easing, callback ); }; -}); +} ); jQuery.timers = []; jQuery.fx.tick = function() { @@ -611,6 +593,7 @@ jQuery.fx.tick = function() { for ( ; i < timers.length; i++ ) { timer = timers[ i ]; + // Checks the timer has not already been removed if ( !timer() && timers[ i ] === timer ) { timers.splice( i--, 1 ); @@ -636,21 +619,22 @@ jQuery.fx.interval = 13; jQuery.fx.start = function() { if ( !timerId ) { - timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval ); + timerId = window.setInterval( jQuery.fx.tick, jQuery.fx.interval ); } }; jQuery.fx.stop = function() { - clearInterval( timerId ); + window.clearInterval( timerId ); timerId = null; }; jQuery.fx.speeds = { slow: 600, fast: 200, + // Default speed _default: 400 }; return jQuery; -}); +} ); |