4 rfxtypes = /^(?:toggle|show|hide)$/,
5 rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/,
9 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
11 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
17 show: function( speed, easing, callback ) {
18 if ( speed || speed === 0) {
19 return this.animate( genFx("show", 3), speed, easing, callback);
22 for ( var i = 0, l = this.length; i < l; i++ ) {
23 var old = jQuery.data(this[i], "olddisplay");
25 this[i].style.display = old || "";
27 if ( jQuery.css( this[i], "display" ) === "none" ) {
28 var nodeName = this[i].nodeName, display;
30 if ( elemdisplay[ nodeName ] ) {
31 display = elemdisplay[ nodeName ];
34 var elem = jQuery("<" + nodeName + ">").appendTo("body");
36 display = elem.css("display");
38 if ( display === "none" ) {
44 elemdisplay[ nodeName ] = display;
47 jQuery.data(this[i], "olddisplay", display);
51 // Set the display of the elements in a second loop
52 // to avoid the constant reflow
53 for ( var j = 0, k = this.length; j < k; j++ ) {
54 this[j].style.display = jQuery.data(this[j], "olddisplay") || "";
61 hide: function( speed, easing, callback ) {
62 if ( speed || speed === 0 ) {
63 return this.animate( genFx("hide", 3), speed, easing, callback);
66 for ( var i = 0, l = this.length; i < l; i++ ) {
67 var old = jQuery.data(this[i], "olddisplay");
68 if ( !old && old !== "none" ) {
69 jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) );
73 // Set the display of the elements in a second loop
74 // to avoid the constant reflow
75 for ( var j = 0, k = this.length; j < k; j++ ) {
76 this[j].style.display = "none";
83 // Save the old toggle function
84 _toggle: jQuery.fn.toggle,
86 toggle: function( fn, fn2, callback ) {
87 var bool = typeof fn === "boolean";
89 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
90 this._toggle.apply( this, arguments );
92 } else if ( fn == null || bool ) {
93 this.each(function() {
94 var state = bool ? fn : jQuery(this).is(":hidden");
95 jQuery(this)[ state ? "show" : "hide" ]();
99 this.animate(genFx("toggle", 3), fn, fn2, callback);
105 fadeTo: function( speed, to, easing, callback ) {
106 return this.filter(":hidden").css("opacity", 0).show().end()
107 .animate({opacity: to}, speed, easing, callback);
110 animate: function( prop, speed, easing, callback ) {
111 var optall = jQuery.speed(speed, easing, callback);
113 if ( jQuery.isEmptyObject( prop ) ) {
114 return this.each( optall.complete );
117 return this[ optall.queue === false ? "each" : "queue" ](function() {
118 var opt = jQuery.extend({}, optall), p,
119 hidden = this.nodeType === 1 && jQuery(this).is(":hidden"),
123 var name = jQuery.camelCase( p );
126 prop[ name ] = prop[ p ];
131 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
132 return opt.complete.call(this);
135 if ( ( p === "height" || p === "width" ) && this.style ) {
136 // Store display property
137 opt.display = this.style.display;
139 // Make sure that nothing sneaks out
140 opt.overflow = this.style.overflow;
143 if ( jQuery.isArray( prop[p] ) ) {
144 // Create (if needed) and add to specialEasing
145 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
146 prop[p] = prop[p][0];
150 if ( opt.overflow != null ) {
151 this.style.overflow = "hidden";
154 opt.curAnim = jQuery.extend({}, prop);
156 jQuery.each( prop, function( name, val ) {
157 var e = new jQuery.fx( self, opt, name );
159 if ( rfxtypes.test(val) ) {
160 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
163 var parts = rfxnum.exec(val),
164 start = e.cur(true) || 0;
167 var end = parseFloat( parts[2] ),
168 unit = parts[3] || "px";
170 // We need to compute starting value
171 if ( unit !== "px" ) {
172 self.style[ name ] = (end || 1) + unit;
173 start = ((end || 1) / e.cur(true)) * start;
174 self.style[ name ] = start + unit;
177 // If a +=/-= token was provided, we're doing a relative animation
179 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
182 e.custom( start, end, unit );
185 e.custom( start, val, "" );
190 // For JS strict compliance
195 stop: function( clearQueue, gotoEnd ) {
196 var timers = jQuery.timers;
202 this.each(function() {
203 // go in reverse order so anything added to the queue during the loop is ignored
204 for ( var i = timers.length - 1; i >= 0; i-- ) {
205 if ( timers[i].elem === this ) {
207 // force the next step to be the last
216 // start the next in the queue if the last step wasn't forced
226 function genFx( type, num ) {
229 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
236 // Generate shortcuts for custom animations
238 slideDown: genFx("show", 1),
239 slideUp: genFx("hide", 1),
240 slideToggle: genFx("toggle", 1),
241 fadeIn: { opacity: "show" },
242 fadeOut: { opacity: "hide" }
243 }, function( name, props ) {
244 jQuery.fn[ name ] = function( speed, easing, callback ) {
245 return this.animate( props, speed, easing, callback );
250 speed: function( speed, easing, fn ) {
251 var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
252 complete: fn || !fn && easing ||
253 jQuery.isFunction( speed ) && speed,
255 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
258 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
259 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
262 opt.old = opt.complete;
263 opt.complete = function() {
264 if ( opt.queue !== false ) {
265 jQuery(this).dequeue();
267 if ( jQuery.isFunction( opt.old ) ) {
268 opt.old.call( this );
276 linear: function( p, n, firstNum, diff ) {
277 return firstNum + diff * p;
279 swing: function( p, n, firstNum, diff ) {
280 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
286 fx: function( elem, options, prop ) {
287 this.options = options;
291 if ( !options.orig ) {
298 jQuery.fx.prototype = {
299 // Simple function for setting a style value
301 if ( this.options.step ) {
302 this.options.step.call( this.elem, this.now, this );
305 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
307 // Set display property to block for height/width animations
308 if ( ( this.prop === "height" || this.prop === "width" ) && this.elem.style ) {
309 this.elem.style.display = "block";
313 // Get the current size
315 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
316 return this.elem[ this.prop ];
319 var r = parseFloat( jQuery.css( this.elem, this.prop ) );
320 return r && r > -10000 ? r : 0;
323 // Start an animation from one number to another
324 custom: function( from, to, unit ) {
325 this.startTime = jQuery.now();
328 this.unit = unit || this.unit || "px";
329 this.now = this.start;
330 this.pos = this.state = 0;
332 var self = this, fx = jQuery.fx;
333 function t( gotoEnd ) {
334 return self.step(gotoEnd);
339 if ( t() && jQuery.timers.push(t) && !timerId ) {
340 timerId = setInterval(fx.tick, fx.interval);
344 // Simple 'show' function
346 // Remember where we started, so that we can go back to it later
347 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
348 this.options.show = true;
350 // Begin the animation
351 // Make sure that we start at a small width/height to avoid any
353 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
355 // Start by showing the element
356 jQuery( this.elem ).show();
359 // Simple 'hide' function
361 // Remember where we started, so that we can go back to it later
362 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
363 this.options.hide = true;
365 // Begin the animation
366 this.custom(this.cur(), 0);
369 // Each step of an animation
370 step: function( gotoEnd ) {
371 var t = jQuery.now(), done = true;
373 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
375 this.pos = this.state = 1;
378 this.options.curAnim[ this.prop ] = true;
380 for ( var i in this.options.curAnim ) {
381 if ( this.options.curAnim[i] !== true ) {
387 if ( this.options.display != null ) {
388 // Reset the overflow
389 this.elem.style.overflow = this.options.overflow;
392 var old = jQuery.data(this.elem, "olddisplay");
393 this.elem.style.display = old ? old : this.options.display;
395 if ( jQuery.css( this.elem, "display" ) === "none" ) {
396 this.elem.style.display = "block";
400 // Hide the element if the "hide" operation was done
401 if ( this.options.hide ) {
402 jQuery(this.elem).hide();
405 // Reset the properties, if the item has been hidden or shown
406 if ( this.options.hide || this.options.show ) {
407 for ( var p in this.options.curAnim ) {
408 jQuery.style( this.elem, p, this.options.orig[p] );
412 // Execute the complete function
413 this.options.complete.call( this.elem );
419 var n = t - this.startTime;
420 this.state = n / this.options.duration;
422 // Perform the easing function, defaults to swing
423 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
424 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
425 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
426 this.now = this.start + ((this.end - this.start) * this.pos);
428 // Perform the next step of the animation
436 jQuery.extend( jQuery.fx, {
438 var timers = jQuery.timers;
440 for ( var i = 0; i < timers.length; i++ ) {
441 if ( !timers[i]() ) {
442 timers.splice(i--, 1);
446 if ( !timers.length ) {
454 clearInterval( timerId );
466 opacity: function( fx ) {
467 jQuery.style( fx.elem, "opacity", fx.now );
470 _default: function( fx ) {
471 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
472 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
474 fx.elem[ fx.prop ] = fx.now;
480 if ( jQuery.expr && jQuery.expr.filters ) {
481 jQuery.expr.filters.animated = function( elem ) {
482 return jQuery.grep(jQuery.timers, function( fn ) {
483 return elem === fn.elem;