4 rfxtypes = /^(?:toggle|show|hide)$/,
5 rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
9 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
11 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
16 requestAnimationFrame = window.webkitRequestAnimationFrame ||
17 window.mozRequestAnimationFrame ||
18 window.oRequestAnimationFrame;
20 function clearFxNow() {
24 function createFxNow() {
25 setTimeout( clearFxNow, 0 );
26 return ( fxNow = jQuery.now() );
30 show: function( speed, easing, callback ) {
33 if ( speed || speed === 0 ) {
34 return this.animate( genFx("show", 3), speed, easing, callback);
37 for ( var i = 0, j = this.length; i < j; i++ ) {
39 display = elem.style.display;
41 // Reset the inline display of this element to learn if it is
42 // being hidden by cascaded rules or not
43 if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
44 display = elem.style.display = "";
47 // Set elements which have been overridden with display: none
48 // in a stylesheet to whatever the default browser style is
49 // for such an element
50 if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
51 jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
55 // Set the display of most of the elements in a second loop
56 // to avoid the constant reflow
57 for ( i = 0; i < j; i++ ) {
59 display = elem.style.display;
61 if ( display === "" || display === "none" ) {
62 elem.style.display = jQuery._data(elem, "olddisplay") || "";
70 hide: function( speed, easing, callback ) {
71 if ( speed || speed === 0 ) {
72 return this.animate( genFx("hide", 3), speed, easing, callback);
75 for ( var i = 0, j = this.length; i < j; i++ ) {
76 var display = jQuery.css( this[i], "display" );
78 if ( display !== "none" && !jQuery._data( this[i], "olddisplay" ) ) {
79 jQuery._data( this[i], "olddisplay", display );
83 // Set the display of the elements in a second loop
84 // to avoid the constant reflow
85 for ( i = 0; i < j; i++ ) {
86 this[i].style.display = "none";
93 // Save the old toggle function
94 _toggle: jQuery.fn.toggle,
96 toggle: function( fn, fn2, callback ) {
97 var bool = typeof fn === "boolean";
99 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
100 this._toggle.apply( this, arguments );
102 } else if ( fn == null || bool ) {
103 this.each(function() {
104 var state = bool ? fn : jQuery(this).is(":hidden");
105 jQuery(this)[ state ? "show" : "hide" ]();
109 this.animate(genFx("toggle", 3), fn, fn2, callback);
115 fadeTo: function( speed, to, easing, callback ) {
116 return this.filter(":hidden").css("opacity", 0).show().end()
117 .animate({opacity: to}, speed, easing, callback);
120 animate: function( prop, speed, easing, callback ) {
121 var optall = jQuery.speed(speed, easing, callback);
123 if ( jQuery.isEmptyObject( prop ) ) {
124 return this.each( optall.complete, [ false ] );
127 return this[ optall.queue === false ? "each" : "queue" ](function() {
128 // XXX 'this' does not always have a nodeName when running the
131 if ( optall.queue === false ) {
132 jQuery._mark( this );
135 var opt = jQuery.extend({}, optall), p,
136 isElement = this.nodeType === 1,
137 hidden = isElement && jQuery(this).is(":hidden"),
141 var name = jQuery.camelCase( p );
144 prop[ name ] = prop[ p ];
149 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
150 return opt.complete.call(this);
153 if ( isElement && ( p === "height" || p === "width" ) ) {
154 // Make sure that nothing sneaks out
155 // Record all 3 overflow attributes because IE does not
156 // change the overflow attribute when overflowX and
157 // overflowY are set to the same value
158 opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
160 // Set display property to inline-block for height/width
161 // animations on inline elements that are having width/height
163 if ( jQuery.css( this, "display" ) === "inline" &&
164 jQuery.css( this, "float" ) === "none" ) {
165 if ( !jQuery.support.inlineBlockNeedsLayout ) {
166 this.style.display = "inline-block";
169 var display = defaultDisplay(this.nodeName);
171 // inline-level elements accept inline-block;
172 // block-level elements need to be inline with layout
173 if ( display === "inline" ) {
174 this.style.display = "inline-block";
177 this.style.display = "inline";
184 if ( jQuery.isArray( prop[p] ) ) {
185 // Create (if needed) and add to specialEasing
186 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
187 prop[p] = prop[p][0];
191 if ( opt.overflow != null ) {
192 this.style.overflow = "hidden";
195 opt.curAnim = jQuery.extend({}, prop);
197 jQuery.each( prop, function( name, val ) {
198 var e = new jQuery.fx( self, opt, name );
200 if ( rfxtypes.test(val) ) {
201 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
204 var parts = rfxnum.exec(val),
208 var end = parseFloat( parts[2] ),
209 unit = parts[3] || ( jQuery.cssNumber[ name ] ? "" : "px" );
211 // We need to compute starting value
212 if ( unit !== "px" ) {
213 jQuery.style( self, name, (end || 1) + unit);
214 start = ((end || 1) / e.cur()) * start;
215 jQuery.style( self, name, start + unit);
218 // If a +=/-= token was provided, we're doing a relative animation
220 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
223 e.custom( start, end, unit );
226 e.custom( start, val, "" );
231 // For JS strict compliance
236 stop: function( clearQueue, gotoEnd ) {
237 var timers = jQuery.timers;
243 this.each(function() {
244 // clear marker counters if we know they won't be
246 jQuery._unmark( true, this );
248 // go in reverse order so anything added to the queue during the loop is ignored
249 for ( var i = timers.length - 1; i >= 0; i-- ) {
250 if ( timers[i].elem === this ) {
252 // force the next step to be the last
261 // start the next in the queue if the last step wasn't forced
271 function genFx( type, num ) {
274 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
281 // Generate shortcuts for custom animations
283 slideDown: genFx("show", 1),
284 slideUp: genFx("hide", 1),
285 slideToggle: genFx("toggle", 1),
286 fadeIn: { opacity: "show" },
287 fadeOut: { opacity: "hide" },
288 fadeToggle: { opacity: "toggle" }
289 }, function( name, props ) {
290 jQuery.fn[ name ] = function( speed, easing, callback ) {
291 return this.animate( props, speed, easing, callback );
296 speed: function( speed, easing, fn ) {
297 var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
298 complete: fn || !fn && easing ||
299 jQuery.isFunction( speed ) && speed,
301 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
304 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
305 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
308 opt.old = opt.complete;
309 opt.complete = function( noUnmark ) {
310 if ( opt.queue !== false ) {
311 jQuery.dequeue( this );
312 } else if ( noUnmark !== false ) {
313 jQuery._unmark( this );
316 if ( jQuery.isFunction( opt.old ) ) {
317 opt.old.call( this );
325 linear: function( p, n, firstNum, diff ) {
326 return firstNum + diff * p;
328 swing: function( p, n, firstNum, diff ) {
329 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
335 fx: function( elem, options, prop ) {
336 this.options = options;
340 if ( !options.orig ) {
347 jQuery.fx.prototype = {
348 // Simple function for setting a style value
350 if ( this.options.step ) {
351 this.options.step.call( this.elem, this.now, this );
354 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
357 // Get the current size
359 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
360 return this.elem[ this.prop ];
364 r = jQuery.css( this.elem, this.prop );
365 // Empty strings, null, undefined and "auto" are converted to 0,
366 // complex values such as "rotate(1rad)" are returned as is,
367 // simple values such as "10px" are parsed to Float.
368 return isNaN( parsed = parseFloat( r ) ) ? !r || r === "auto" ? 0 : r : parsed;
371 // Start an animation from one number to another
372 custom: function( from, to, unit ) {
377 this.startTime = fxNow || createFxNow();
380 this.unit = unit || this.unit || ( jQuery.cssNumber[ this.prop ] ? "" : "px" );
381 this.now = this.start;
382 this.pos = this.state = 0;
384 function t( gotoEnd ) {
385 return self.step(gotoEnd);
390 if ( t() && jQuery.timers.push(t) && !timerId ) {
391 // Use requestAnimationFrame instead of setInterval if available
392 if ( requestAnimationFrame ) {
395 // When timerId gets set to null at any point, this stops
397 requestAnimationFrame( raf );
401 requestAnimationFrame( raf );
403 timerId = setInterval( fx.tick, fx.interval );
408 // Simple 'show' function
410 // Remember where we started, so that we can go back to it later
411 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
412 this.options.show = true;
414 // Begin the animation
415 // Make sure that we start at a small width/height to avoid any
417 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
419 // Start by showing the element
420 jQuery( this.elem ).show();
423 // Simple 'hide' function
425 // Remember where we started, so that we can go back to it later
426 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
427 this.options.hide = true;
429 // Begin the animation
430 this.custom(this.cur(), 0);
433 // Each step of an animation
434 step: function( gotoEnd ) {
435 var t = fxNow || createFxNow(),
438 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
440 this.pos = this.state = 1;
443 this.options.curAnim[ this.prop ] = true;
445 for ( var i in this.options.curAnim ) {
446 if ( this.options.curAnim[i] !== true ) {
452 // Reset the overflow
453 if ( this.options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
454 var elem = this.elem,
455 options = this.options;
457 jQuery.each( [ "", "X", "Y" ], function (index, value) {
458 elem.style[ "overflow" + value ] = options.overflow[index];
462 // Hide the element if the "hide" operation was done
463 if ( this.options.hide ) {
464 jQuery(this.elem).hide();
467 // Reset the properties, if the item has been hidden or shown
468 if ( this.options.hide || this.options.show ) {
469 for ( var p in this.options.curAnim ) {
470 jQuery.style( this.elem, p, this.options.orig[p] );
474 // Execute the complete function
475 this.options.complete.call( this.elem );
481 var n = t - this.startTime;
482 this.state = n / this.options.duration;
484 // Perform the easing function, defaults to swing
485 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
486 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
487 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
488 this.now = this.start + ((this.end - this.start) * this.pos);
490 // Perform the next step of the animation
498 jQuery.extend( jQuery.fx, {
500 var timers = jQuery.timers;
502 for ( var i = 0; i < timers.length; i++ ) {
503 if ( !timers[i]() ) {
504 timers.splice(i--, 1);
508 if ( !timers.length ) {
516 clearInterval( timerId );
528 opacity: function( fx ) {
529 jQuery.style( fx.elem, "opacity", fx.now );
532 _default: function( fx ) {
533 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
534 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
536 fx.elem[ fx.prop ] = fx.now;
542 if ( jQuery.expr && jQuery.expr.filters ) {
543 jQuery.expr.filters.animated = function( elem ) {
544 return jQuery.grep(jQuery.timers, function( fn ) {
545 return elem === fn.elem;
550 function defaultDisplay( nodeName ) {
552 if ( !elemdisplay[ nodeName ] ) {
554 var elem = jQuery( "<" + nodeName + ">" ).appendTo( "body" ),
555 display = elem.css( "display" );
559 if ( display === "none" || display === "" ) {
561 var iframe = defaultDisplay.iframe,
562 iframeDoc = defaultDisplay.iframeDoc;
564 // No iframe to use yet, so create it
565 if ( !defaultDisplay.iframe ) {
567 iframe = document.createElement( "iframe" );
568 iframe.width = iframe.height = 0;
570 document.body.appendChild( iframe );
572 iframeDoc = ( iframe.contentWindow || iframe.contentDocument ).document;
573 iframeDoc.write("<!doctype><html><body></body></html>");
575 // Cache iframe element
576 defaultDisplay.iframe = iframe;
577 defaultDisplay.iframeDoc = iframeDoc;
580 // Reuse previous iframe
581 document.body.appendChild( iframe );
585 elem = iframeDoc.createElement( nodeName );
587 iframeDoc.body.appendChild( elem );
589 display = jQuery( elem ).css( "display" );
591 iframe.parentNode.removeChild( iframe );
594 // Store the correct default display
595 elemdisplay[ nodeName ] = display;
598 return elemdisplay[ nodeName ];
601 defaultDisplay.iframe = null;
602 defaultDisplay.iframeDoc = null;