2013-09-09 15:26:21 +00:00
|
|
|
define(function( require ) {
|
2013-08-15 18:15:49 +00:00
|
|
|
|
2013-09-09 15:26:21 +00:00
|
|
|
var
|
|
|
|
jQuery = require( "./core" ),
|
|
|
|
pnum = require( "./var/pnum" ),
|
|
|
|
cssExpand = require( "./css/var/cssExpand" ),
|
|
|
|
isHidden = require( "./css/var/isHidden" ),
|
|
|
|
defaultDisplay = require( "./css/defaultDisplay" ),
|
|
|
|
support = require( "./css/support" ),
|
|
|
|
|
|
|
|
fxNow, timerId,
|
2010-09-22 13:16:28 +00:00
|
|
|
rfxtypes = /^(?:toggle|show|hide)$/,
|
2013-08-15 18:15:49 +00:00
|
|
|
rfxnum = new RegExp( "^(?:([+-])=|)(" + pnum + ")([a-z%]*)$", "i" ),
|
2012-05-23 03:04:45 +00:00
|
|
|
rrun = /queueHooks$/,
|
2012-05-11 20:20:32 +00:00
|
|
|
animationPrefilters = [ defaultPrefilter ],
|
2012-04-23 19:05:12 +00:00
|
|
|
tweeners = {
|
|
|
|
"*": [function( prop, value ) {
|
2013-05-09 02:56:51 +00:00
|
|
|
var tween = this.createTween( prop, value ),
|
2012-06-26 17:48:31 +00:00
|
|
|
target = tween.cur(),
|
2013-05-09 02:56:51 +00:00
|
|
|
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 ) ),
|
2012-09-15 15:57:01 +00:00
|
|
|
scale = 1,
|
|
|
|
maxIterations = 20;
|
2012-04-23 19:05:12 +00:00
|
|
|
|
2013-05-09 02:56:51 +00:00
|
|
|
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;
|
2010-10-26 21:37:44 +00:00
|
|
|
|
2013-05-09 02:56:51 +00:00
|
|
|
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 ) {
|
2013-05-26 20:02:32 +00:00
|
|
|
start = tween.start = +start || +target || 0;
|
2012-04-23 19:05:12 +00:00
|
|
|
tween.unit = unit;
|
|
|
|
// If a +=/-= token was provided, we're doing a relative animation
|
2013-05-09 02:56:51 +00:00
|
|
|
tween.end = parts[ 1 ] ?
|
|
|
|
start + ( parts[ 1 ] + 1 ) * parts[ 2 ] :
|
|
|
|
+parts[ 2 ];
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2013-05-09 02:56:51 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
return tween;
|
|
|
|
}]
|
2012-05-29 02:25:04 +00:00
|
|
|
};
|
2010-10-26 21:37:44 +00:00
|
|
|
|
2013-09-09 15:26:21 +00:00
|
|
|
// Dependencies not needed as vars
|
|
|
|
require( "./effects/Tween" );
|
|
|
|
require( "./queue" );
|
|
|
|
require( "./css" );
|
|
|
|
require( "./deferred" );
|
|
|
|
require( "./traversing" );
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
// Animations created synchronously will run synchronously
|
|
|
|
function createFxNow() {
|
|
|
|
setTimeout(function() {
|
|
|
|
fxNow = undefined;
|
2012-12-10 08:00:12 +00:00
|
|
|
});
|
2012-04-23 19:05:12 +00:00
|
|
|
return ( fxNow = jQuery.now() );
|
|
|
|
}
|
2010-10-26 21:37:44 +00:00
|
|
|
|
2013-05-09 02:56:51 +00:00
|
|
|
function createTween( value, prop, animation ) {
|
|
|
|
var tween,
|
|
|
|
collection = ( tweeners[ prop ] || [] ).concat( tweeners[ "*" ] ),
|
|
|
|
index = 0,
|
|
|
|
length = collection.length;
|
|
|
|
for ( ; index < length; index++ ) {
|
|
|
|
if ( (tween = collection[ index ].call( animation, prop, value )) ) {
|
2012-05-18 17:48:24 +00:00
|
|
|
|
2013-05-09 02:56:51 +00:00
|
|
|
// we're done with this property
|
|
|
|
return tween;
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2013-05-09 02:56:51 +00:00
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2011-04-17 18:07:42 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
function Animation( elem, properties, options ) {
|
|
|
|
var result,
|
2013-01-08 01:16:50 +00:00
|
|
|
stopped,
|
2012-04-23 19:05:12 +00:00
|
|
|
index = 0,
|
|
|
|
length = animationPrefilters.length,
|
2012-06-22 20:03:39 +00:00
|
|
|
deferred = jQuery.Deferred().always( function() {
|
2012-05-18 17:48:24 +00:00
|
|
|
// don't match elem in the :animated selector
|
|
|
|
delete tick.elem;
|
2012-04-23 19:05:12 +00:00
|
|
|
}),
|
2012-05-18 17:48:24 +00:00
|
|
|
tick = function() {
|
2013-01-08 01:16:50 +00:00
|
|
|
if ( stopped ) {
|
|
|
|
return false;
|
|
|
|
}
|
2012-05-18 17:48:24 +00:00
|
|
|
var currentTime = fxNow || createFxNow(),
|
|
|
|
remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
|
2012-11-08 03:29:55 +00:00
|
|
|
// archaic crash bug won't allow us to use 1 - ( 0.5 || 0 ) (#12497)
|
|
|
|
temp = remaining / animation.duration || 0,
|
|
|
|
percent = 1 - temp,
|
2012-05-18 17:48:24 +00:00
|
|
|
index = 0,
|
|
|
|
length = animation.tweens.length;
|
|
|
|
|
|
|
|
for ( ; index < length ; index++ ) {
|
|
|
|
animation.tweens[ index ].run( percent );
|
|
|
|
}
|
|
|
|
|
2012-06-23 21:50:57 +00:00
|
|
|
deferred.notifyWith( elem, [ animation, percent, remaining ]);
|
|
|
|
|
2012-05-18 17:48:24 +00:00
|
|
|
if ( percent < 1 && length ) {
|
|
|
|
return remaining;
|
|
|
|
} else {
|
2012-06-22 20:03:39 +00:00
|
|
|
deferred.resolveWith( elem, [ animation ] );
|
2012-05-18 17:48:24 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
},
|
2012-04-23 19:05:12 +00:00
|
|
|
animation = deferred.promise({
|
|
|
|
elem: elem,
|
2012-05-11 20:20:32 +00:00
|
|
|
props: jQuery.extend( {}, properties ),
|
|
|
|
opts: jQuery.extend( true, { specialEasing: {} }, options ),
|
2012-04-23 19:05:12 +00:00
|
|
|
originalProperties: properties,
|
|
|
|
originalOptions: options,
|
|
|
|
startTime: fxNow || createFxNow(),
|
|
|
|
duration: options.duration,
|
|
|
|
tweens: [],
|
2012-10-17 16:50:12 +00:00
|
|
|
createTween: function( prop, end ) {
|
2012-04-23 19:05:12 +00:00
|
|
|
var tween = jQuery.Tween( elem, animation.opts, prop, end,
|
|
|
|
animation.opts.specialEasing[ prop ] || animation.opts.easing );
|
|
|
|
animation.tweens.push( tween );
|
|
|
|
return tween;
|
|
|
|
},
|
|
|
|
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;
|
2013-01-08 01:16:50 +00:00
|
|
|
if ( stopped ) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
stopped = true;
|
2012-04-23 19:05:12 +00:00
|
|
|
for ( ; index < length ; index++ ) {
|
|
|
|
animation.tweens[ index ].run( 1 );
|
2009-02-09 15:58:12 +00:00
|
|
|
}
|
2012-06-22 20:03:39 +00:00
|
|
|
|
|
|
|
// resolve when we played the last frame
|
|
|
|
// otherwise, reject
|
|
|
|
if ( gotoEnd ) {
|
|
|
|
deferred.resolveWith( elem, [ animation, gotoEnd ] );
|
|
|
|
} else {
|
|
|
|
deferred.rejectWith( elem, [ animation, gotoEnd ] );
|
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
return this;
|
2009-02-16 21:20:51 +00:00
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
}),
|
|
|
|
props = animation.props;
|
2009-02-09 15:58:12 +00:00
|
|
|
|
2012-05-11 20:20:32 +00:00
|
|
|
propFilter( props, animation.opts.specialEasing );
|
2010-10-26 21:37:44 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
for ( ; index < length ; index++ ) {
|
2012-06-22 20:03:39 +00:00
|
|
|
result = animationPrefilters[ index ].call( animation, elem, props, animation.opts );
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( result ) {
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
}
|
2011-04-17 18:07:42 +00:00
|
|
|
|
2013-05-09 02:56:51 +00:00
|
|
|
jQuery.map( props, createTween, animation );
|
2012-06-22 20:03:39 +00:00
|
|
|
|
|
|
|
if ( jQuery.isFunction( animation.opts.start ) ) {
|
|
|
|
animation.opts.start.call( elem, animation );
|
|
|
|
}
|
2009-03-23 01:55:17 +00:00
|
|
|
|
2012-05-18 17:48:24 +00:00
|
|
|
jQuery.fx.timer(
|
|
|
|
jQuery.extend( tick, {
|
2013-01-12 22:11:07 +00:00
|
|
|
elem: elem,
|
2012-05-18 17:48:24 +00:00
|
|
|
anim: animation,
|
2013-01-12 22:11:07 +00:00
|
|
|
queue: animation.opts.queue
|
2012-05-18 17:48:24 +00:00
|
|
|
})
|
|
|
|
);
|
2012-06-22 20:03:39 +00:00
|
|
|
|
|
|
|
// attach callbacks from options
|
2012-06-23 21:50:57 +00:00
|
|
|
return animation.progress( animation.opts.progress )
|
|
|
|
.done( animation.opts.done, animation.opts.complete )
|
2012-06-22 20:03:39 +00:00
|
|
|
.fail( animation.opts.fail )
|
|
|
|
.always( animation.opts.always );
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2009-12-18 16:16:26 +00:00
|
|
|
|
2012-05-11 20:20:32 +00:00
|
|
|
function propFilter( props, specialEasing ) {
|
2013-03-13 23:23:36 +00:00
|
|
|
var index, name, easing, value, hooks;
|
2010-12-30 06:34:48 +00:00
|
|
|
|
2012-05-11 20:20:32 +00:00
|
|
|
// camelCase, specialEasing and expand cssHook pass
|
2012-04-23 19:05:12 +00:00
|
|
|
for ( index in props ) {
|
|
|
|
name = jQuery.camelCase( index );
|
2012-05-11 20:20:32 +00:00
|
|
|
easing = specialEasing[ name ];
|
|
|
|
value = props[ index ];
|
|
|
|
if ( jQuery.isArray( value ) ) {
|
|
|
|
easing = value[ 1 ];
|
|
|
|
value = props[ index ] = value[ 0 ];
|
|
|
|
}
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( index !== name ) {
|
2012-05-11 20:20:32 +00:00
|
|
|
props[ name ] = value;
|
2012-04-23 19:05:12 +00:00
|
|
|
delete props[ index ];
|
|
|
|
}
|
2011-11-01 13:46:20 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
hooks = jQuery.cssHooks[ name ];
|
|
|
|
if ( hooks && "expand" in hooks ) {
|
2012-05-11 20:20:32 +00:00
|
|
|
value = hooks.expand( value );
|
2012-04-23 19:05:12 +00:00
|
|
|
delete props[ name ];
|
2009-02-09 15:58:12 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
// not quite $.extend, this wont overwrite keys already present.
|
|
|
|
// also - reusing 'index' from above because we have the correct "name"
|
2012-05-11 20:20:32 +00:00
|
|
|
for ( index in value ) {
|
|
|
|
if ( !( index in props ) ) {
|
|
|
|
props[ index ] = value[ index ];
|
|
|
|
specialEasing[ index ] = easing;
|
2011-04-17 18:07:42 +00:00
|
|
|
}
|
2008-12-19 18:21:12 +00:00
|
|
|
}
|
2012-05-11 20:20:32 +00:00
|
|
|
} else {
|
|
|
|
specialEasing[ name ] = easing;
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2009-02-09 15:58:12 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.Animation = jQuery.extend( Animation, {
|
|
|
|
|
|
|
|
tweener: function( props, callback ) {
|
|
|
|
if ( jQuery.isFunction( props ) ) {
|
|
|
|
callback = props;
|
|
|
|
props = [ "*" ];
|
|
|
|
} else {
|
|
|
|
props = props.split(" ");
|
|
|
|
}
|
|
|
|
|
|
|
|
var prop,
|
|
|
|
index = 0,
|
|
|
|
length = props.length;
|
|
|
|
|
|
|
|
for ( ; index < length ; index++ ) {
|
|
|
|
prop = props[ index ];
|
|
|
|
tweeners[ prop ] = tweeners[ prop ] || [];
|
|
|
|
tweeners[ prop ].unshift( callback );
|
2008-12-19 18:21:12 +00:00
|
|
|
}
|
2007-01-07 21:43:38 +00:00
|
|
|
},
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
prefilter: function( callback, prepend ) {
|
|
|
|
if ( prepend ) {
|
|
|
|
animationPrefilters.unshift( callback );
|
|
|
|
} else {
|
|
|
|
animationPrefilters.push( callback );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2012-05-11 20:20:32 +00:00
|
|
|
function defaultPrefilter( elem, props, opts ) {
|
2013-03-13 23:23:36 +00:00
|
|
|
/* jshint validthis: true */
|
2013-05-09 02:56:51 +00:00
|
|
|
var prop, value, toggle, tween, hooks, oldfire,
|
2012-05-23 03:04:45 +00:00
|
|
|
anim = this,
|
2012-05-11 20:20:32 +00:00
|
|
|
orig = {},
|
2013-05-09 02:56:51 +00:00
|
|
|
style = elem.style,
|
|
|
|
hidden = elem.nodeType && isHidden( elem ),
|
|
|
|
dataShow = jQuery._data( elem, "fxshow" );
|
2008-12-25 20:13:42 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
// handle queue: false promises
|
|
|
|
if ( !opts.queue ) {
|
|
|
|
hooks = jQuery._queueHooks( elem, "fx" );
|
|
|
|
if ( hooks.unqueued == null ) {
|
|
|
|
hooks.unqueued = 0;
|
|
|
|
oldfire = hooks.empty.fire;
|
|
|
|
hooks.empty.fire = function() {
|
|
|
|
if ( !hooks.unqueued ) {
|
|
|
|
oldfire();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
hooks.unqueued++;
|
2012-06-22 20:03:39 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
anim.always(function() {
|
2012-06-22 20:03:39 +00:00
|
|
|
// doing this makes sure that the complete handler will be called
|
|
|
|
// before this completes
|
|
|
|
anim.always(function() {
|
|
|
|
hooks.unqueued--;
|
|
|
|
if ( !jQuery.queue( elem, "fx" ).length ) {
|
|
|
|
hooks.empty.fire();
|
|
|
|
}
|
|
|
|
});
|
2012-05-23 03:04:45 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
// height/width overflow pass
|
2012-07-20 23:36:55 +00:00
|
|
|
if ( elem.nodeType === 1 && ( "height" in props || "width" in props ) ) {
|
2012-04-23 19:05:12 +00:00
|
|
|
// Make sure that nothing sneaks out
|
|
|
|
// Record all 3 overflow attributes because IE does not
|
|
|
|
// change the overflow attribute when overflowX and
|
|
|
|
// overflowY are set to the same value
|
|
|
|
opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
|
2009-12-18 16:16:26 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
// Set display property to inline-block for height/width
|
|
|
|
// animations on inline elements that are having width/height animated
|
|
|
|
if ( jQuery.css( elem, "display" ) === "inline" &&
|
|
|
|
jQuery.css( elem, "float" ) === "none" ) {
|
|
|
|
|
|
|
|
// inline-level elements accept inline-block;
|
|
|
|
// block-level elements need to be inline with layout
|
2013-09-02 17:21:09 +00:00
|
|
|
if ( !support.inlineBlockNeedsLayout || defaultDisplay( elem.nodeName ) === "inline" ) {
|
2012-04-23 19:05:12 +00:00
|
|
|
style.display = "inline-block";
|
|
|
|
} else {
|
|
|
|
style.zoom = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( opts.overflow ) {
|
|
|
|
style.overflow = "hidden";
|
2013-09-02 17:21:09 +00:00
|
|
|
if ( !support.shrinkWrapBlocks() ) {
|
2013-01-27 03:02:15 +00:00
|
|
|
anim.always(function() {
|
2012-06-09 03:11:34 +00:00
|
|
|
style.overflow = opts.overflow[ 0 ];
|
|
|
|
style.overflowX = opts.overflow[ 1 ];
|
|
|
|
style.overflowY = opts.overflow[ 2 ];
|
|
|
|
});
|
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2009-12-18 16:16:26 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
|
2012-05-11 20:20:32 +00:00
|
|
|
// show/hide pass
|
2013-05-09 02:56:51 +00:00
|
|
|
for ( prop in props ) {
|
|
|
|
value = props[ prop ];
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( rfxtypes.exec( value ) ) {
|
2013-05-09 02:56:51 +00:00
|
|
|
delete props[ prop ];
|
2012-11-08 01:23:24 +00:00
|
|
|
toggle = toggle || value === "toggle";
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( value === ( hidden ? "hide" : "show" ) ) {
|
2013-08-30 16:38:43 +00:00
|
|
|
|
|
|
|
// 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 {
|
|
|
|
continue;
|
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2013-05-09 02:56:51 +00:00
|
|
|
orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-05-09 02:56:51 +00:00
|
|
|
if ( !jQuery.isEmptyObject( orig ) ) {
|
|
|
|
if ( dataShow ) {
|
|
|
|
if ( "hidden" in dataShow ) {
|
|
|
|
hidden = dataShow.hidden;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
dataShow = jQuery._data( elem, "fxshow", {} );
|
2012-11-08 01:23:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// store state if its toggle - enables .stop().toggle() to "reverse"
|
|
|
|
if ( toggle ) {
|
|
|
|
dataShow.hidden = !hidden;
|
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( hidden ) {
|
2012-05-29 02:25:04 +00:00
|
|
|
jQuery( elem ).show();
|
2009-12-18 16:16:26 +00:00
|
|
|
} else {
|
2012-06-22 20:03:39 +00:00
|
|
|
anim.done(function() {
|
2012-05-29 02:25:04 +00:00
|
|
|
jQuery( elem ).hide();
|
2012-04-23 19:05:12 +00:00
|
|
|
});
|
2009-12-18 16:16:26 +00:00
|
|
|
}
|
2012-06-22 20:03:39 +00:00
|
|
|
anim.done(function() {
|
2012-04-23 19:05:12 +00:00
|
|
|
var prop;
|
2012-10-16 15:15:41 +00:00
|
|
|
jQuery._removeData( elem, "fxshow" );
|
2012-04-23 19:05:12 +00:00
|
|
|
for ( prop in orig ) {
|
|
|
|
jQuery.style( elem, prop, orig[ prop ] );
|
|
|
|
}
|
|
|
|
});
|
2013-05-09 02:56:51 +00:00
|
|
|
for ( prop in orig ) {
|
|
|
|
tween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
|
2012-04-23 19:05:12 +00:00
|
|
|
|
|
|
|
if ( !( prop in dataShow ) ) {
|
|
|
|
dataShow[ prop ] = tween.start;
|
|
|
|
if ( hidden ) {
|
|
|
|
tween.end = tween.start;
|
|
|
|
tween.start = prop === "width" || prop === "height" ? 1 : 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-05-11 20:20:32 +00:00
|
|
|
}
|
2009-12-18 16:16:26 +00:00
|
|
|
|
2012-05-29 02:25:04 +00:00
|
|
|
jQuery.each([ "toggle", "show", "hide" ], function( i, name ) {
|
|
|
|
var cssFn = jQuery.fn[ name ];
|
|
|
|
jQuery.fn[ name ] = function( speed, easing, callback ) {
|
2012-10-16 04:15:22 +00:00
|
|
|
return speed == null || typeof speed === "boolean" ?
|
2012-05-29 02:25:04 +00:00
|
|
|
cssFn.apply( this, arguments ) :
|
|
|
|
this.animate( genFx( name, true ), speed, easing, callback );
|
|
|
|
};
|
|
|
|
});
|
2007-09-07 21:57:40 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.fn.extend({
|
|
|
|
fadeTo: function( speed, to, easing, callback ) {
|
2012-05-23 02:36:55 +00:00
|
|
|
|
|
|
|
// 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 );
|
2012-04-23 19:05:12 +00:00
|
|
|
},
|
|
|
|
animate: function( prop, speed, easing, callback ) {
|
2012-06-22 20:03:39 +00:00
|
|
|
var empty = jQuery.isEmptyObject( prop ),
|
|
|
|
optall = jQuery.speed( speed, easing, callback ),
|
2012-04-23 19:05:12 +00:00
|
|
|
doAnimation = function() {
|
2012-06-22 20:03:39 +00:00
|
|
|
// Operate on a copy of prop so per-property easing won't be lost
|
|
|
|
var anim = Animation( this, jQuery.extend( {}, prop ), optall );
|
2013-05-25 14:18:57 +00:00
|
|
|
|
2013-01-08 01:16:50 +00:00
|
|
|
// Empty animations, or finishing resolves immediately
|
|
|
|
if ( empty || jQuery._data( this, "finish" ) ) {
|
2012-06-22 20:03:39 +00:00
|
|
|
anim.stop( true );
|
|
|
|
}
|
|
|
|
};
|
2013-01-08 01:16:50 +00:00
|
|
|
doAnimation.finish = doAnimation;
|
2012-04-23 19:05:12 +00:00
|
|
|
|
2012-06-22 20:03:39 +00:00
|
|
|
return empty || optall.queue === false ?
|
2011-09-19 20:08:00 +00:00
|
|
|
this.each( doAnimation ) :
|
2011-09-28 15:55:29 +00:00
|
|
|
this.queue( optall.queue, doAnimation );
|
2007-01-07 21:43:38 +00:00
|
|
|
},
|
2011-10-12 01:21:59 +00:00
|
|
|
stop: function( type, clearQueue, gotoEnd ) {
|
2012-05-23 03:04:45 +00:00
|
|
|
var stopQueue = function( hooks ) {
|
|
|
|
var stop = hooks.stop;
|
|
|
|
delete hooks.stop;
|
|
|
|
stop( gotoEnd );
|
2012-04-23 19:05:12 +00:00
|
|
|
};
|
|
|
|
|
2011-10-12 01:21:59 +00:00
|
|
|
if ( typeof type !== "string" ) {
|
|
|
|
gotoEnd = clearQueue;
|
|
|
|
clearQueue = type;
|
|
|
|
type = undefined;
|
|
|
|
}
|
2011-09-28 15:55:29 +00:00
|
|
|
if ( clearQueue && type !== false ) {
|
|
|
|
this.queue( type || "fx", [] );
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
2009-12-18 16:16:26 +00:00
|
|
|
|
2011-09-28 15:55:29 +00:00
|
|
|
return this.each(function() {
|
2012-05-23 03:04:45 +00:00
|
|
|
var dequeue = true,
|
|
|
|
index = type != null && type + "queueHooks",
|
2011-09-28 15:55:29 +00:00
|
|
|
timers = jQuery.timers,
|
|
|
|
data = jQuery._data( this );
|
2011-09-12 23:48:44 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
if ( index ) {
|
|
|
|
if ( data[ index ] && data[ index ].stop ) {
|
|
|
|
stopQueue( data[ index ] );
|
|
|
|
}
|
|
|
|
} else {
|
2011-11-11 20:05:06 +00:00
|
|
|
for ( index in data ) {
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
|
2012-05-23 03:04:45 +00:00
|
|
|
stopQueue( data[ index ] );
|
2011-09-28 15:55:29 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-11-11 20:05:06 +00:00
|
|
|
for ( index = timers.length; index--; ) {
|
|
|
|
if ( timers[ index ].elem === this && (type == null || timers[ index ].queue === type) ) {
|
2012-04-23 19:05:12 +00:00
|
|
|
timers[ index ].anim.stop( gotoEnd );
|
2012-05-23 03:04:45 +00:00
|
|
|
dequeue = false;
|
2011-11-11 20:05:06 +00:00
|
|
|
timers.splice( index, 1 );
|
2007-11-30 21:36:49 +00:00
|
|
|
}
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
2009-12-18 16:16:26 +00:00
|
|
|
|
2011-09-28 15:55:29 +00:00
|
|
|
// start the next in the queue if the last step wasn't forced
|
|
|
|
// timers currently will call their complete callbacks, which will dequeue
|
|
|
|
// but only if they were gotoEnd
|
2012-05-23 03:04:45 +00:00
|
|
|
if ( dequeue || !gotoEnd ) {
|
2011-09-28 15:55:29 +00:00
|
|
|
jQuery.dequeue( this, type );
|
|
|
|
}
|
|
|
|
});
|
2013-01-08 01:16:50 +00:00
|
|
|
},
|
|
|
|
finish: function( type ) {
|
|
|
|
if ( type !== false ) {
|
|
|
|
type = type || "fx";
|
|
|
|
}
|
|
|
|
return this.each(function() {
|
|
|
|
var index,
|
|
|
|
data = jQuery._data( this ),
|
|
|
|
queue = data[ type + "queue" ],
|
|
|
|
hooks = data[ type + "queueHooks" ],
|
|
|
|
timers = jQuery.timers,
|
|
|
|
length = queue ? queue.length : 0;
|
|
|
|
|
|
|
|
// enable finishing flag on private data
|
|
|
|
data.finish = true;
|
|
|
|
|
|
|
|
// empty the queue first
|
|
|
|
jQuery.queue( this, type, [] );
|
|
|
|
|
2013-05-25 14:18:57 +00:00
|
|
|
if ( hooks && hooks.stop ) {
|
|
|
|
hooks.stop.call( this, true );
|
2013-01-08 01:16:50 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// look for any active animations, and finish them
|
|
|
|
for ( index = timers.length; index--; ) {
|
|
|
|
if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
|
|
|
|
timers[ index ].anim.stop( true );
|
|
|
|
timers.splice( index, 1 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// look for any animations in the old queue and finish them
|
|
|
|
for ( index = 0; index < length; index++ ) {
|
|
|
|
if ( queue[ index ] && queue[ index ].finish ) {
|
|
|
|
queue[ index ].finish.call( this );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// turn off finishing flag
|
|
|
|
delete data.finish;
|
|
|
|
});
|
2007-01-07 21:43:38 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-04-17 18:08:52 +00:00
|
|
|
// Generate parameters to create a standard animation
|
2012-04-23 19:05:12 +00:00
|
|
|
function genFx( type, includeWidth ) {
|
|
|
|
var which,
|
|
|
|
attrs = { height: type },
|
|
|
|
i = 0;
|
|
|
|
|
|
|
|
// if we include width, step value is 1 to do all cssExpand values,
|
|
|
|
// if we don't include width, step value is 2 to skip over Left and Right
|
2012-08-30 14:47:47 +00:00
|
|
|
includeWidth = includeWidth? 1 : 0;
|
2012-04-23 19:05:12 +00:00
|
|
|
for( ; i < 4 ; i += 2 - includeWidth ) {
|
2012-07-10 01:38:11 +00:00
|
|
|
which = cssExpand[ i ];
|
2012-04-23 19:05:12 +00:00
|
|
|
attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
|
|
|
|
}
|
2011-04-17 18:08:52 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( includeWidth ) {
|
|
|
|
attrs.opacity = attrs.width = type;
|
|
|
|
}
|
2011-04-17 18:08:52 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
return attrs;
|
2011-04-17 18:08:52 +00:00
|
|
|
}
|
|
|
|
|
2008-07-03 22:54:12 +00:00
|
|
|
// Generate shortcuts for custom animations
|
|
|
|
jQuery.each({
|
2012-04-23 19:05:12 +00:00
|
|
|
slideDown: genFx("show"),
|
|
|
|
slideUp: genFx("hide"),
|
|
|
|
slideToggle: genFx("toggle"),
|
2008-07-03 22:54:12 +00:00
|
|
|
fadeIn: { opacity: "show" },
|
2010-10-17 18:26:32 +00:00
|
|
|
fadeOut: { opacity: "hide" },
|
|
|
|
fadeToggle: { opacity: "toggle" }
|
2009-12-22 00:58:13 +00:00
|
|
|
}, function( name, props ) {
|
Added full support for easing in all shorthand effects methods (hide, show, toggle, fadeTo, slideUp, etc.). Previously, these methods could only be used with two of the three (speed, easing, callback) arguments, or, in the case of fadeTo, 3 of the 4 (speed, opacity, easing, callback) arguments. Added three more sets of tests to the series of "Chain" tests. Fixes #7014
2010-09-08 20:31:32 +00:00
|
|
|
jQuery.fn[ name ] = function( speed, easing, callback ) {
|
|
|
|
return this.animate( props, speed, easing, callback );
|
2008-07-03 22:54:12 +00:00
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.speed = function( speed, easing, fn ) {
|
|
|
|
var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
|
|
|
|
complete: fn || !fn && easing ||
|
|
|
|
jQuery.isFunction( speed ) && speed,
|
|
|
|
duration: speed,
|
|
|
|
easing: fn && easing || easing && !jQuery.isFunction( easing ) && easing
|
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
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;
|
2007-03-17 02:02:01 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
// normalize opt.queue - true/undefined/null -> "fx"
|
|
|
|
if ( opt.queue == null || opt.queue === true ) {
|
|
|
|
opt.queue = "fx";
|
2007-09-07 21:57:40 +00:00
|
|
|
}
|
2007-01-07 21:43:38 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
// Queueing
|
|
|
|
opt.old = opt.complete;
|
2007-03-17 02:02:01 +00:00
|
|
|
|
2012-05-23 03:04:45 +00:00
|
|
|
opt.complete = function() {
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( jQuery.isFunction( opt.old ) ) {
|
|
|
|
opt.old.call( this );
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
2011-09-12 23:48:44 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( opt.queue ) {
|
|
|
|
jQuery.dequeue( this, opt.queue );
|
2011-09-12 23:48:44 +00:00
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
return opt;
|
|
|
|
};
|
2007-01-07 21:43:38 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.timers = [];
|
|
|
|
jQuery.fx.tick = function() {
|
|
|
|
var timer,
|
|
|
|
timers = jQuery.timers,
|
|
|
|
i = 0;
|
|
|
|
|
2012-11-08 01:22:14 +00:00
|
|
|
fxNow = jQuery.now();
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
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 );
|
2009-11-27 19:28:42 +00:00
|
|
|
}
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
2010-10-05 18:38:19 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
if ( !timers.length ) {
|
|
|
|
jQuery.fx.stop();
|
|
|
|
}
|
2012-11-08 01:22:14 +00:00
|
|
|
fxNow = undefined;
|
2012-04-23 19:05:12 +00:00
|
|
|
};
|
2010-10-05 18:38:19 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.fx.timer = function( timer ) {
|
2012-11-08 06:02:14 +00:00
|
|
|
if ( timer() && jQuery.timers.push( timer ) ) {
|
|
|
|
jQuery.fx.start();
|
2012-04-23 19:05:12 +00:00
|
|
|
}
|
|
|
|
};
|
2010-10-05 18:38:19 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.fx.interval = 13;
|
2009-06-02 02:14:58 +00:00
|
|
|
|
2012-11-08 06:02:14 +00:00
|
|
|
jQuery.fx.start = function() {
|
|
|
|
if ( !timerId ) {
|
|
|
|
timerId = setInterval( jQuery.fx.tick, jQuery.fx.interval );
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.fx.stop = function() {
|
|
|
|
clearInterval( timerId );
|
|
|
|
timerId = null;
|
|
|
|
};
|
2008-05-13 01:45:58 +00:00
|
|
|
|
2012-04-23 19:05:12 +00:00
|
|
|
jQuery.fx.speeds = {
|
|
|
|
slow: 600,
|
|
|
|
fast: 200,
|
|
|
|
// Default speed
|
|
|
|
_default: 400
|
|
|
|
};
|
2009-10-26 22:07:57 +00:00
|
|
|
|
2013-09-09 01:25:27 +00:00
|
|
|
return jQuery;
|
2013-08-15 18:15:49 +00:00
|
|
|
});
|