diff options
Diffstat (limited to 'js/vendor/jquery/src/effects.js')
-rw-r--r-- | js/vendor/jquery/src/effects.js | 211 |
1 files changed, 96 insertions, 115 deletions
diff --git a/js/vendor/jquery/src/effects.js b/js/vendor/jquery/src/effects.js index 90226bd49..178fa42f0 100644 --- a/js/vendor/jquery/src/effects.js +++ b/js/vendor/jquery/src/effects.js @@ -1,10 +1,13 @@ -define([ +define( [ "./core", - "./var/pnum", + "./var/document", + "./var/rcssNum", "./css/var/cssExpand", + "./var/rnotwhite", "./css/var/isHidden", + "./css/adjustCSS", "./css/defaultDisplay", - "./data/var/data_priv", + "./data/var/dataPriv", "./core/init", "./effects/Tween", @@ -12,70 +15,19 @@ define([ "./css", "./deferred", "./traversing" -], function( jQuery, pnum, cssExpand, isHidden, defaultDisplay, data_priv ) { +], function( jQuery, document, rcssNum, cssExpand, rnotwhite, + isHidden, adjustCSS, defaultDisplay, dataPriv ) { 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 string for doubling 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(), - // break 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; @@ -121,7 +73,7 @@ function defaultPrefilter( elem, props, opts ) { orig = {}, style = elem.style, hidden = elem.nodeType && isHidden( elem ), - dataShow = data_priv.get( elem, "fxshow" ); + dataShow = dataPriv.get( elem, "fxshow" ); // Handle queue: false promises if ( !opts.queue ) { @@ -137,19 +89,21 @@ function defaultPrefilter( elem, props, opts ) { } hooks.unqueued++; - anim.always(function() { + anim.always( function() { + // Ensure the complete handler is 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 IE9-10 do not // change the overflow attribute when overflowX and @@ -162,7 +116,7 @@ function defaultPrefilter( elem, props, opts ) { // Test default display if display is currently "none" checkDisplay = display === "none" ? - data_priv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display; + dataPriv.get( elem, "olddisplay" ) || defaultDisplay( elem.nodeName ) : display; if ( checkDisplay === "inline" && jQuery.css( elem, "float" ) === "none" ) { style.display = "inline-block"; @@ -171,11 +125,11 @@ function defaultPrefilter( elem, props, opts ) { if ( opts.overflow ) { style.overflow = "hidden"; - anim.always(function() { + anim.always( function() { style.overflow = opts.overflow[ 0 ]; style.overflowX = opts.overflow[ 1 ]; style.overflowY = opts.overflow[ 2 ]; - }); + } ); } // show/hide pass @@ -186,7 +140,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 { @@ -207,7 +162,7 @@ function defaultPrefilter( elem, props, opts ) { hidden = dataShow.hidden; } } else { - dataShow = data_priv.access( elem, "fxshow", {} ); + dataShow = dataPriv.access( elem, "fxshow", {} ); } // Store state if its toggle - enables .stop().toggle() to "reverse" @@ -217,18 +172,18 @@ 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; - data_priv.remove( elem, "fxshow" ); + dataPriv.remove( elem, "fxshow" ); for ( prop in orig ) { jQuery.style( elem, prop, orig[ prop ] ); } - }); + } ); for ( prop in orig ) { tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim ); @@ -242,7 +197,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; } } @@ -288,17 +243,19 @@ 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 ), + // Support: Android 2.3 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497) temp = remaining / animation.duration || 0, @@ -310,7 +267,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; @@ -319,10 +276,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(), @@ -336,6 +296,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; @@ -349,20 +310,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; } } @@ -378,7 +344,7 @@ function Animation( elem, properties, options ) { elem: elem, anim: animation, queue: animation.opts.queue - }) + } ) ); // attach callbacks from options @@ -389,13 +355,20 @@ 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, @@ -404,19 +377,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 ) : { @@ -426,8 +401,9 @@ jQuery.speed = function( speed, easing, fn ) { easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing }; - 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 = 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; // Normalize opt.queue - true/undefined/null -> "fx" if ( opt.queue == null || opt.queue === true ) { @@ -450,24 +426,25 @@ 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 ); // Empty animations, or finishing resolves immediately - if ( empty || data_priv.get( this, "finish" ) ) { + if ( empty || dataPriv.get( this, "finish" ) ) { anim.stop( true ); } }; @@ -493,11 +470,11 @@ 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, - data = data_priv.get( this ); + data = dataPriv.get( this ); if ( index ) { if ( data[ index ] && data[ index ].stop ) { @@ -512,7 +489,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 ); @@ -525,15 +504,15 @@ 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 = data_priv.get( this ), + data = dataPriv.get( this ), queue = data[ type + "queue" ], hooks = data[ type + "queueHooks" ], timers = jQuery.timers, @@ -566,24 +545,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" } @@ -591,7 +570,7 @@ jQuery.each({ jQuery.fn[ name ] = function( speed, easing, callback ) { return this.animate( props, speed, easing, callback ); }; -}); +} ); jQuery.timers = []; jQuery.fx.tick = function() { @@ -603,6 +582,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 ); @@ -625,24 +605,25 @@ jQuery.fx.timer = function( timer ) { }; 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; -}); +} ); |