4 rfxtypes = /^(?:toggle|show|hide)$/,
5 rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/,
9 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
11 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
16 function defaultDisplay(nodeName) {
17 if ( !elemdisplay[ nodeName ] ) {
18 var elem = jQuery("<" + nodeName + ">").appendTo("body"),
19 display = elem.css("display");
23 if ( display === "none" || display === "" ) {
27 elemdisplay[ nodeName ] = display;
30 return elemdisplay[ nodeName ];
34 show: function( speed, easing, callback ) {
35 if ( speed || speed === 0 ) {
36 return this.animate( genFx("show", 3), speed, easing, callback);
38 for ( var i = 0, j = this.length; i < j; i++ ) {
39 // Reset the inline display of this element to learn if it is
40 // being hidden by cascaded rules or not
41 if ( !jQuery.data(this[i], "olddisplay") && this[i].style.display === "none" ) {
42 this[i].style.display = "";
45 // Set elements which have been overridden with display: none
46 // in a stylesheet to whatever the default browser style is
47 // for such an element
48 if ( jQuery.css( this[i], "display" ) === "none" && this[i].style.display === "" ) {
49 jQuery.data(this[i], "olddisplay", defaultDisplay(this[i].nodeName));
53 // Set the display of most of the elements in a second loop
54 // to avoid the constant reflow
55 for ( i = 0; i < j; i++ ) {
56 this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
63 hide: function( speed, easing, callback ) {
64 if ( speed || speed === 0 ) {
65 return this.animate( genFx("hide", 3), speed, easing, callback);
68 for ( var i = 0, j = this.length; i < j; i++ ) {
69 var old = jQuery.data(this[i], "olddisplay");
71 jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) );
75 // Set the display of the elements in a second loop
76 // to avoid the constant reflow
77 for ( i = 0; i < j; i++ ) {
78 this[i].style.display = "none";
85 // Save the old toggle function
86 _toggle: jQuery.fn.toggle,
88 toggle: function( fn, fn2, callback ) {
89 var bool = typeof fn === "boolean";
91 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
92 this._toggle.apply( this, arguments );
94 } else if ( fn == null || bool ) {
95 this.each(function() {
96 var state = bool ? fn : jQuery(this).is(":hidden");
97 jQuery(this)[ state ? "show" : "hide" ]();
101 this.animate(genFx("toggle", 3), fn, fn2, callback);
107 fadeTo: function( speed, to, easing, callback ) {
108 return this.filter(":hidden").css("opacity", 0).show().end()
109 .animate({opacity: to}, speed, easing, callback);
112 animate: function( prop, speed, easing, callback ) {
113 var optall = jQuery.speed(speed, easing, callback);
115 if ( jQuery.isEmptyObject( prop ) ) {
116 return this.each( optall.complete );
119 return this[ optall.queue === false ? "each" : "queue" ](function() {
120 // XXX ‘this’ does not always have a nodeName when running the
123 var opt = jQuery.extend({}, optall), p,
124 isElement = this.nodeType === 1,
125 hidden = isElement && jQuery(this).is(":hidden"),
129 var name = jQuery.camelCase( p );
132 prop[ name ] = prop[ p ];
137 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
138 return opt.complete.call(this);
141 if ( isElement && ( p === "height" || p === "width" ) ) {
142 // Make sure that nothing sneaks out
143 // Record all 3 overflow attributes because IE does not
144 // change the overflow attribute when overflowX and
145 // overflowY are set to the same value
146 opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
148 // Set display property to inline-block for height/width
149 // animations on inline elements that are having width/height
151 if ( jQuery.css( this, "display" ) === "inline" &&
152 jQuery.css( this, "float" ) === "none" ) {
153 if ( !jQuery.support.inlineBlockNeedsLayout ) {
154 this.style.display = "inline-block";
156 var display = defaultDisplay(this.nodeName);
158 // inline-level elements accept inline-block;
159 // block-level elements need to be inline with layout
160 if ( display === "inline" ) {
161 this.style.display = "inline-block";
164 this.style.display = "inline";
171 if ( jQuery.isArray( prop[p] ) ) {
172 // Create (if needed) and add to specialEasing
173 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
174 prop[p] = prop[p][0];
178 if ( opt.overflow != null || (jQuery.support.shrinkWrapBlocks && isElement) ) {
179 this.style.overflow = "hidden";
182 opt.curAnim = jQuery.extend({}, prop);
184 jQuery.each( prop, function( name, val ) {
185 var e = new jQuery.fx( self, opt, name );
187 if ( rfxtypes.test(val) ) {
188 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
191 var parts = rfxnum.exec(val),
192 start = e.cur(true) || 0;
195 var end = parseFloat( parts[2] ),
196 unit = parts[3] || "px";
198 // We need to compute starting value
199 if ( unit !== "px" ) {
200 self.style[ name ] = (end || 1) + unit;
201 start = ((end || 1) / e.cur(true)) * start;
202 self.style[ name ] = start + unit;
205 // If a +=/-= token was provided, we're doing a relative animation
207 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
210 e.custom( start, end, unit );
213 e.custom( start, val, "" );
218 // For JS strict compliance
223 stop: function( clearQueue, gotoEnd ) {
224 var timers = jQuery.timers;
230 this.each(function() {
231 // go in reverse order so anything added to the queue during the loop is ignored
232 for ( var i = timers.length - 1; i >= 0; i-- ) {
233 if ( timers[i].elem === this ) {
235 // force the next step to be the last
244 // start the next in the queue if the last step wasn't forced
254 function genFx( type, num ) {
257 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
264 // Generate shortcuts for custom animations
266 slideDown: genFx("show", 1),
267 slideUp: genFx("hide", 1),
268 slideToggle: genFx("toggle", 1),
269 fadeIn: { opacity: "show" },
270 fadeOut: { opacity: "hide" }
271 }, function( name, props ) {
272 jQuery.fn[ name ] = function( speed, easing, callback ) {
273 return this.animate( props, speed, easing, callback );
278 speed: function( speed, easing, fn ) {
279 var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
280 complete: fn || !fn && easing ||
281 jQuery.isFunction( speed ) && speed,
283 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
286 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
287 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
290 opt.old = opt.complete;
291 opt.complete = function() {
292 if ( opt.queue !== false ) {
293 jQuery(this).dequeue();
295 if ( jQuery.isFunction( opt.old ) ) {
296 opt.old.call( this );
304 linear: function( p, n, firstNum, diff ) {
305 return firstNum + diff * p;
307 swing: function( p, n, firstNum, diff ) {
308 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
314 fx: function( elem, options, prop ) {
315 this.options = options;
319 if ( !options.orig ) {
326 jQuery.fx.prototype = {
327 // Simple function for setting a style value
329 if ( this.options.step ) {
330 this.options.step.call( this.elem, this.now, this );
333 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
336 // Get the current size
338 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
339 return this.elem[ this.prop ];
342 var r = parseFloat( jQuery.css( this.elem, this.prop ) );
343 return r && r > -10000 ? r : 0;
346 // Start an animation from one number to another
347 custom: function( from, to, unit ) {
348 this.startTime = jQuery.now();
351 this.unit = unit || this.unit || "px";
352 this.now = this.start;
353 this.pos = this.state = 0;
355 var self = this, fx = jQuery.fx;
356 function t( gotoEnd ) {
357 return self.step(gotoEnd);
362 if ( t() && jQuery.timers.push(t) && !timerId ) {
363 timerId = setInterval(fx.tick, fx.interval);
367 // Simple 'show' function
369 // Remember where we started, so that we can go back to it later
370 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
371 this.options.show = true;
373 // Begin the animation
374 // Make sure that we start at a small width/height to avoid any
376 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
378 // Start by showing the element
379 jQuery( this.elem ).show();
382 // Simple 'hide' function
384 // Remember where we started, so that we can go back to it later
385 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
386 this.options.hide = true;
388 // Begin the animation
389 this.custom(this.cur(), 0);
392 // Each step of an animation
393 step: function( gotoEnd ) {
394 var t = jQuery.now(), done = true;
396 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
398 this.pos = this.state = 1;
401 this.options.curAnim[ this.prop ] = true;
403 for ( var i in this.options.curAnim ) {
404 if ( this.options.curAnim[i] !== true ) {
410 // Reset the overflow
411 if ( this.options.overflow != null && (!jQuery.support.shrinkWrapBlocks || !jQuery.css( this.elem, "hasLayout" )) ) {
412 this.elem.style.overflow = this.options.overflow[0];
413 this.elem.style.overflowX = this.options.overflow[1];
414 this.elem.style.overflowY = this.options.overflow[2];
417 // Hide the element if the "hide" operation was done
418 if ( this.options.hide ) {
419 jQuery(this.elem).hide();
422 // Reset the properties, if the item has been hidden or shown
423 if ( this.options.hide || this.options.show ) {
424 for ( var p in this.options.curAnim ) {
425 jQuery.style( this.elem, p, this.options.orig[p] );
429 // Execute the complete function
430 this.options.complete.call( this.elem );
436 var n = t - this.startTime;
437 this.state = n / this.options.duration;
439 // Perform the easing function, defaults to swing
440 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
441 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
442 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
443 this.now = this.start + ((this.end - this.start) * this.pos);
445 // Perform the next step of the animation
453 jQuery.extend( jQuery.fx, {
455 var timers = jQuery.timers;
457 for ( var i = 0; i < timers.length; i++ ) {
458 if ( !timers[i]() ) {
459 timers.splice(i--, 1);
463 if ( !timers.length ) {
471 clearInterval( timerId );
483 opacity: function( fx ) {
484 jQuery.style( fx.elem, "opacity", fx.now );
487 _default: function( fx ) {
488 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
489 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
491 fx.elem[ fx.prop ] = fx.now;
497 if ( jQuery.expr && jQuery.expr.filters ) {
498 jQuery.expr.filters.animated = function( elem ) {
499 return jQuery.grep(jQuery.timers, function( fn ) {
500 return elem === fn.elem;