8 "./css/var/isHiddenWithinTree",
12 "./data/var/dataPriv",
22 ], function( jQuery, document, isFunction, rcssNum, rnothtmlwhite, cssExpand,
23 isHiddenWithinTree, swap, adjustCSS, cssCamelCase, dataPriv, showHide ) {
29 rfxtypes = /^(?:toggle|show|hide)$/,
34 if ( document.hidden === false && window.requestAnimationFrame ) {
35 window.requestAnimationFrame( schedule );
37 window.setTimeout( schedule, jQuery.fx.interval );
44 // Animations created synchronously will run synchronously
45 function createFxNow() {
46 window.setTimeout( function() {
49 return ( fxNow = Date.now() );
52 // Generate parameters to create a standard animation
53 function genFx( type, includeWidth ) {
56 attrs = { height: type };
58 // If we include width, step value is 1 to do all cssExpand values,
59 // otherwise step value is 2 to skip over Left and Right
60 includeWidth = includeWidth ? 1 : 0;
61 for ( ; i < 4; i += 2 - includeWidth ) {
62 which = cssExpand[ i ];
63 attrs[ "margin" + which ] = attrs[ "padding" + which ] = type;
67 attrs.opacity = attrs.width = type;
73 function createTween( value, prop, animation ) {
75 collection = ( Animation.tweeners[ prop ] || [] ).concat( Animation.tweeners[ "*" ] ),
77 length = collection.length;
78 for ( ; index < length; index++ ) {
79 if ( ( tween = collection[ index ].call( animation, prop, value ) ) ) {
81 // We're done with this property
87 function defaultPrefilter( elem, props, opts ) {
88 var prop, value, toggle, hooks, oldfire, propTween, restoreDisplay, display,
89 isBox = "width" in props || "height" in props,
93 hidden = elem.nodeType && isHiddenWithinTree( elem ),
94 dataShow = dataPriv.get( elem, "fxshow" );
96 // Queue-skipping animations hijack the fx hooks
98 hooks = jQuery._queueHooks( elem, "fx" );
99 if ( hooks.unqueued == null ) {
101 oldfire = hooks.empty.fire;
102 hooks.empty.fire = function() {
103 if ( !hooks.unqueued ) {
110 anim.always( function() {
112 // Ensure the complete handler is called before this completes
113 anim.always( function() {
115 if ( !jQuery.queue( elem, "fx" ).length ) {
122 // Detect show/hide animations
123 for ( prop in props ) {
124 value = props[ prop ];
125 if ( rfxtypes.test( value ) ) {
126 delete props[ prop ];
127 toggle = toggle || value === "toggle";
128 if ( value === ( hidden ? "hide" : "show" ) ) {
130 // Pretend to be hidden if this is a "show" and
131 // there is still data from a stopped show/hide
132 if ( value === "show" && dataShow && dataShow[ prop ] !== undefined ) {
135 // Ignore all other no-op show/hide data
140 orig[ prop ] = dataShow && dataShow[ prop ] || jQuery.style( elem, prop );
144 // Bail out if this is a no-op like .hide().hide()
145 propTween = !jQuery.isEmptyObject( props );
146 if ( !propTween && jQuery.isEmptyObject( orig ) ) {
150 // Restrict "overflow" and "display" styles during box animations
151 if ( isBox && elem.nodeType === 1 ) {
153 // Support: IE <=9 - 11, Edge 12 - 15
154 // Record all 3 overflow attributes because IE does not infer the shorthand
155 // from identically-valued overflowX and overflowY and Edge just mirrors
156 // the overflowX value there.
157 opts.overflow = [ style.overflow, style.overflowX, style.overflowY ];
159 // Identify a display type, preferring old show/hide data over the CSS cascade
160 restoreDisplay = dataShow && dataShow.display;
161 if ( restoreDisplay == null ) {
162 restoreDisplay = dataPriv.get( elem, "display" );
164 display = jQuery.css( elem, "display" );
165 if ( display === "none" ) {
166 if ( restoreDisplay ) {
167 display = restoreDisplay;
170 // Get nonempty value(s) by temporarily forcing visibility
171 showHide( [ elem ], true );
172 restoreDisplay = elem.style.display || restoreDisplay;
173 display = jQuery.css( elem, "display" );
174 showHide( [ elem ] );
178 // Animate inline elements as inline-block
179 if ( display === "inline" || display === "inline-block" && restoreDisplay != null ) {
180 if ( jQuery.css( elem, "float" ) === "none" ) {
182 // Restore the original display value at the end of pure show/hide animations
184 anim.done( function() {
185 style.display = restoreDisplay;
187 if ( restoreDisplay == null ) {
188 display = style.display;
189 restoreDisplay = display === "none" ? "" : display;
192 style.display = "inline-block";
197 if ( opts.overflow ) {
198 style.overflow = "hidden";
199 anim.always( function() {
200 style.overflow = opts.overflow[ 0 ];
201 style.overflowX = opts.overflow[ 1 ];
202 style.overflowY = opts.overflow[ 2 ];
206 // Implement show/hide animations
208 for ( prop in orig ) {
210 // General show/hide setup for this element animation
213 if ( "hidden" in dataShow ) {
214 hidden = dataShow.hidden;
217 dataShow = dataPriv.access( elem, "fxshow", { display: restoreDisplay } );
220 // Store hidden/visible for toggle so `.stop().toggle()` "reverses"
222 dataShow.hidden = !hidden;
225 // Show elements before animating them
227 showHide( [ elem ], true );
230 /* eslint-disable no-loop-func */
232 anim.done( function() {
234 /* eslint-enable no-loop-func */
236 // The final step of a "hide" animation is actually hiding the element
238 showHide( [ elem ] );
240 dataPriv.remove( elem, "fxshow" );
241 for ( prop in orig ) {
242 jQuery.style( elem, prop, orig[ prop ] );
247 // Per-property setup
248 propTween = createTween( hidden ? dataShow[ prop ] : 0, prop, anim );
249 if ( !( prop in dataShow ) ) {
250 dataShow[ prop ] = propTween.start;
252 propTween.end = propTween.start;
259 function propFilter( props, specialEasing ) {
260 var index, name, easing, value, hooks;
262 // camelCase, specialEasing and expand cssHook pass
263 for ( index in props ) {
264 name = cssCamelCase( index );
265 easing = specialEasing[ name ];
266 value = props[ index ];
267 if ( Array.isArray( value ) ) {
269 value = props[ index ] = value[ 0 ];
272 if ( index !== name ) {
273 props[ name ] = value;
274 delete props[ index ];
277 hooks = jQuery.cssHooks[ name ];
278 if ( hooks && "expand" in hooks ) {
279 value = hooks.expand( value );
280 delete props[ name ];
282 // Not quite $.extend, this won't overwrite existing keys.
283 // Reusing 'index' because we have the correct "name"
284 for ( index in value ) {
285 if ( !( index in props ) ) {
286 props[ index ] = value[ index ];
287 specialEasing[ index ] = easing;
291 specialEasing[ name ] = easing;
296 function Animation( elem, properties, options ) {
300 length = Animation.prefilters.length,
301 deferred = jQuery.Deferred().always( function() {
303 // Don't match elem in the :animated selector
310 var currentTime = fxNow || createFxNow(),
311 remaining = Math.max( 0, animation.startTime + animation.duration - currentTime ),
313 // Support: Android 2.3 only
314 // Archaic crash bug won't allow us to use `1 - ( 0.5 || 0 )` (#12497)
315 temp = remaining / animation.duration || 0,
318 length = animation.tweens.length;
320 for ( ; index < length; index++ ) {
321 animation.tweens[ index ].run( percent );
324 deferred.notifyWith( elem, [ animation, percent, remaining ] );
326 // If there's more to do, yield
327 if ( percent < 1 && length ) {
331 // If this was an empty animation, synthesize a final progress notification
333 deferred.notifyWith( elem, [ animation, 1, 0 ] );
336 // Resolve the animation and report its conclusion
337 deferred.resolveWith( elem, [ animation ] );
340 animation = deferred.promise( {
342 props: jQuery.extend( {}, properties ),
343 opts: jQuery.extend( true, {
345 easing: jQuery.easing._default
347 originalProperties: properties,
348 originalOptions: options,
349 startTime: fxNow || createFxNow(),
350 duration: options.duration,
352 createTween: function( prop, end ) {
353 var tween = jQuery.Tween( elem, animation.opts, prop, end,
354 animation.opts.specialEasing[ prop ] || animation.opts.easing );
355 animation.tweens.push( tween );
358 stop: function( gotoEnd ) {
361 // If we are going to the end, we want to run all the tweens
362 // otherwise we skip this part
363 length = gotoEnd ? animation.tweens.length : 0;
368 for ( ; index < length; index++ ) {
369 animation.tweens[ index ].run( 1 );
372 // Resolve when we played the last frame; otherwise, reject
374 deferred.notifyWith( elem, [ animation, 1, 0 ] );
375 deferred.resolveWith( elem, [ animation, gotoEnd ] );
377 deferred.rejectWith( elem, [ animation, gotoEnd ] );
382 props = animation.props;
384 propFilter( props, animation.opts.specialEasing );
386 for ( ; index < length; index++ ) {
387 result = Animation.prefilters[ index ].call( animation, elem, props, animation.opts );
389 if ( isFunction( result.stop ) ) {
390 jQuery._queueHooks( animation.elem, animation.opts.queue ).stop =
391 result.stop.bind( result );
397 jQuery.map( props, createTween, animation );
399 if ( isFunction( animation.opts.start ) ) {
400 animation.opts.start.call( elem, animation );
403 // Attach callbacks from options
405 .progress( animation.opts.progress )
406 .done( animation.opts.done, animation.opts.complete )
407 .fail( animation.opts.fail )
408 .always( animation.opts.always );
411 jQuery.extend( tick, {
414 queue: animation.opts.queue
421 jQuery.Animation = jQuery.extend( Animation, {
424 "*": [ function( prop, value ) {
425 var tween = this.createTween( prop, value );
426 adjustCSS( tween.elem, prop, rcssNum.exec( value ), tween );
431 tweener: function( props, callback ) {
432 if ( isFunction( props ) ) {
436 props = props.match( rnothtmlwhite );
441 length = props.length;
443 for ( ; index < length; index++ ) {
444 prop = props[ index ];
445 Animation.tweeners[ prop ] = Animation.tweeners[ prop ] || [];
446 Animation.tweeners[ prop ].unshift( callback );
450 prefilters: [ defaultPrefilter ],
452 prefilter: function( callback, prepend ) {
454 Animation.prefilters.unshift( callback );
456 Animation.prefilters.push( callback );
461 jQuery.speed = function( speed, easing, fn ) {
462 var opt = speed && typeof speed === "object" ? jQuery.extend( {}, speed ) : {
463 complete: fn || !fn && easing ||
464 isFunction( speed ) && speed,
466 easing: fn && easing || easing && !isFunction( easing ) && easing
469 // Go to the end state if fx are off
470 if ( jQuery.fx.off ) {
474 if ( typeof opt.duration !== "number" ) {
475 if ( opt.duration in jQuery.fx.speeds ) {
476 opt.duration = jQuery.fx.speeds[ opt.duration ];
479 opt.duration = jQuery.fx.speeds._default;
484 // Normalize opt.queue - true/undefined/null -> "fx"
485 if ( opt.queue == null || opt.queue === true ) {
490 opt.old = opt.complete;
492 opt.complete = function() {
493 if ( isFunction( opt.old ) ) {
494 opt.old.call( this );
498 jQuery.dequeue( this, opt.queue );
506 fadeTo: function( speed, to, easing, callback ) {
508 // Show any hidden elements after setting opacity to 0
509 return this.filter( isHiddenWithinTree ).css( "opacity", 0 ).show()
511 // Animate to the value specified
512 .end().animate( { opacity: to }, speed, easing, callback );
514 animate: function( prop, speed, easing, callback ) {
515 var empty = jQuery.isEmptyObject( prop ),
516 optall = jQuery.speed( speed, easing, callback ),
517 doAnimation = function() {
519 // Operate on a copy of prop so per-property easing won't be lost
520 var anim = Animation( this, jQuery.extend( {}, prop ), optall );
522 // Empty animations, or finishing resolves immediately
523 if ( empty || dataPriv.get( this, "finish" ) ) {
527 doAnimation.finish = doAnimation;
529 return empty || optall.queue === false ?
530 this.each( doAnimation ) :
531 this.queue( optall.queue, doAnimation );
533 stop: function( type, clearQueue, gotoEnd ) {
534 var stopQueue = function( hooks ) {
535 var stop = hooks.stop;
540 if ( typeof type !== "string" ) {
541 gotoEnd = clearQueue;
545 if ( clearQueue && type !== false ) {
546 this.queue( type || "fx", [] );
549 return this.each( function() {
551 index = type != null && type + "queueHooks",
552 timers = jQuery.timers,
553 data = dataPriv.get( this );
556 if ( data[ index ] && data[ index ].stop ) {
557 stopQueue( data[ index ] );
560 for ( index in data ) {
561 if ( data[ index ] && data[ index ].stop && rrun.test( index ) ) {
562 stopQueue( data[ index ] );
567 for ( index = timers.length; index--; ) {
568 if ( timers[ index ].elem === this &&
569 ( type == null || timers[ index ].queue === type ) ) {
571 timers[ index ].anim.stop( gotoEnd );
573 timers.splice( index, 1 );
577 // Start the next in the queue if the last step wasn't forced.
578 // Timers currently will call their complete callbacks, which
579 // will dequeue but only if they were gotoEnd.
580 if ( dequeue || !gotoEnd ) {
581 jQuery.dequeue( this, type );
585 finish: function( type ) {
586 if ( type !== false ) {
589 return this.each( function() {
591 data = dataPriv.get( this ),
592 queue = data[ type + "queue" ],
593 hooks = data[ type + "queueHooks" ],
594 timers = jQuery.timers,
595 length = queue ? queue.length : 0;
597 // Enable finishing flag on private data
600 // Empty the queue first
601 jQuery.queue( this, type, [] );
603 if ( hooks && hooks.stop ) {
604 hooks.stop.call( this, true );
607 // Look for any active animations, and finish them
608 for ( index = timers.length; index--; ) {
609 if ( timers[ index ].elem === this && timers[ index ].queue === type ) {
610 timers[ index ].anim.stop( true );
611 timers.splice( index, 1 );
615 // Look for any animations in the old queue and finish them
616 for ( index = 0; index < length; index++ ) {
617 if ( queue[ index ] && queue[ index ].finish ) {
618 queue[ index ].finish.call( this );
622 // Turn off finishing flag
628 jQuery.each( [ "toggle", "show", "hide" ], function( i, name ) {
629 var cssFn = jQuery.fn[ name ];
630 jQuery.fn[ name ] = function( speed, easing, callback ) {
631 return speed == null || typeof speed === "boolean" ?
632 cssFn.apply( this, arguments ) :
633 this.animate( genFx( name, true ), speed, easing, callback );
637 // Generate shortcuts for custom animations
639 slideDown: genFx( "show" ),
640 slideUp: genFx( "hide" ),
641 slideToggle: genFx( "toggle" ),
642 fadeIn: { opacity: "show" },
643 fadeOut: { opacity: "hide" },
644 fadeToggle: { opacity: "toggle" }
645 }, function( name, props ) {
646 jQuery.fn[ name ] = function( speed, easing, callback ) {
647 return this.animate( props, speed, easing, callback );
652 jQuery.fx.tick = function() {
655 timers = jQuery.timers;
659 for ( ; i < timers.length; i++ ) {
662 // Run the timer and safely remove it when done (allowing for external removal)
663 if ( !timer() && timers[ i ] === timer ) {
664 timers.splice( i--, 1 );
668 if ( !timers.length ) {
674 jQuery.fx.timer = function( timer ) {
675 jQuery.timers.push( timer );
679 jQuery.fx.interval = 13;
680 jQuery.fx.start = function() {
689 jQuery.fx.stop = function() {