2 rfxtypes = /toggle|show|hide/,
3 rfxnum = /^([+-]=)?([\d+-.]+)(.*)$/,
7 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
9 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
15 show: function( speed, callback ) {
16 if ( speed != null ) {
17 return this.animate( genFx("show", 3), speed, callback);
20 for ( var i = 0, l = this.length; i < l; i++ ) {
21 var old = jQuery.data(this[i], "olddisplay");
23 this[i].style.display = old || "";
25 if ( jQuery.css(this[i], "display") === "none" ) {
26 var nodeName = this[i].nodeName, display;
28 if ( elemdisplay[ nodeName ] ) {
29 display = elemdisplay[ nodeName ];
32 var elem = jQuery("<" + nodeName + " />").appendTo("body");
34 display = elem.css("display");
36 if ( display === "none" ) {
42 elemdisplay[ nodeName ] = display;
45 jQuery.data(this[i], "olddisplay", display);
49 // Set the display of the elements in a second loop
50 // to avoid the constant reflow
51 for ( var j = 0, k = this.length; j < k; j++ ) {
52 this[j].style.display = jQuery.data(this[j], "olddisplay") || "";
59 hide: function( speed, callback ) {
60 if ( speed != null ) {
61 return this.animate( genFx("hide", 3), speed, callback);
64 for ( var i = 0, l = this.length; i < l; i++ ) {
65 var old = jQuery.data(this[i], "olddisplay");
66 if ( !old && old !== "none" ) {
67 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
71 // Set the display of the elements in a second loop
72 // to avoid the constant reflow
73 for ( var j = 0, k = this.length; j < k; j++ ) {
74 this[j].style.display = "none";
81 // Save the old toggle function
82 _toggle: jQuery.fn.toggle,
84 toggle: function( fn, fn2 ) {
85 var bool = typeof fn === "boolean";
87 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
88 this._toggle.apply( this, arguments );
90 } else if ( fn == null || bool ) {
91 this.each(function() {
92 var state = bool ? fn : jQuery(this).is(":hidden");
93 jQuery(this)[ state ? "show" : "hide" ]();
97 this.animate(genFx("toggle", 3), fn, fn2);
103 fadeTo: function( speed, to, callback ) {
104 return this.filter(":hidden").css("opacity", 0).show().end()
105 .animate({opacity: to}, speed, callback);
108 animate: function( prop, speed, easing, callback ) {
109 var optall = jQuery.speed(speed, easing, callback);
111 if ( jQuery.isEmptyObject( prop ) ) {
112 return this.each( optall.complete );
115 return this[ optall.queue === false ? "each" : "queue" ](function() {
116 var opt = jQuery.extend({}, optall), p,
117 hidden = this.nodeType === 1 && jQuery(this).is(":hidden"),
121 var name = p.replace(rdashAlpha, fcamelCase);
124 prop[ name ] = prop[ p ];
129 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
130 return opt.complete.call(this);
133 if ( ( p === "height" || p === "width" ) && this.style ) {
134 // Store display property
135 opt.display = jQuery.css(this, "display");
137 // Make sure that nothing sneaks out
138 opt.overflow = this.style.overflow;
141 if ( jQuery.isArray( prop[p] ) ) {
142 // Create (if needed) and add to specialEasing
143 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
144 prop[p] = prop[p][0];
148 if ( opt.overflow != null ) {
149 this.style.overflow = "hidden";
152 opt.curAnim = jQuery.extend({}, prop);
154 jQuery.each( prop, function( name, val ) {
155 var e = new jQuery.fx( self, opt, name );
157 if ( rfxtypes.test(val) ) {
158 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
161 var parts = rfxnum.exec(val),
162 start = e.cur(true) || 0;
165 var end = parseFloat( parts[2] ),
166 unit = parts[3] || "px";
168 // We need to compute starting value
169 if ( unit !== "px" ) {
170 self.style[ name ] = (end || 1) + unit;
171 start = ((end || 1) / e.cur(true)) * start;
172 self.style[ name ] = start + unit;
175 // If a +=/-= token was provided, we're doing a relative animation
177 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
180 e.custom( start, end, unit );
183 e.custom( start, val, "" );
188 // For JS strict compliance
193 stop: function( clearQueue, gotoEnd ) {
194 var timers = jQuery.timers;
200 this.each(function() {
201 // go in reverse order so anything added to the queue during the loop is ignored
202 for ( var i = timers.length - 1; i >= 0; i-- ) {
203 if ( timers[i].elem === this ) {
205 // force the next step to be the last
214 // start the next in the queue if the last step wasn't forced
224 // Generate shortcuts for custom animations
226 slideDown: genFx("show", 1),
227 slideUp: genFx("hide", 1),
228 slideToggle: genFx("toggle", 1),
229 fadeIn: { opacity: "show" },
230 fadeOut: { opacity: "hide" }
231 }, function( name, props ) {
232 jQuery.fn[ name ] = function( speed, callback ) {
233 return this.animate( props, speed, callback );
238 speed: function( speed, easing, fn ) {
239 var opt = speed && typeof speed === "object" ? speed : {
240 complete: fn || !fn && easing ||
241 jQuery.isFunction( speed ) && speed,
243 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
246 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
247 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
250 opt.old = opt.complete;
251 opt.complete = function() {
252 if ( opt.queue !== false ) {
253 jQuery(this).dequeue();
255 if ( jQuery.isFunction( opt.old ) ) {
256 opt.old.call( this );
264 linear: function( p, n, firstNum, diff ) {
265 return firstNum + diff * p;
267 swing: function( p, n, firstNum, diff ) {
268 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
274 fx: function( elem, options, prop ) {
275 this.options = options;
279 if ( !options.orig ) {
286 jQuery.fx.prototype = {
287 // Simple function for setting a style value
289 if ( this.options.step ) {
290 this.options.step.call( this.elem, this.now, this );
293 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
295 // Set display property to block for height/width animations
296 if ( ( this.prop === "height" || this.prop === "width" ) && this.elem.style ) {
297 this.elem.style.display = "block";
301 // Get the current size
302 cur: function( force ) {
303 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
304 return this.elem[ this.prop ];
307 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
308 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
311 // Start an animation from one number to another
312 custom: function( from, to, unit ) {
313 this.startTime = now();
316 this.unit = unit || this.unit || "px";
317 this.now = this.start;
318 this.pos = this.state = 0;
321 function t( gotoEnd ) {
322 return self.step(gotoEnd);
327 if ( t() && jQuery.timers.push(t) && !timerId ) {
328 timerId = setInterval(jQuery.fx.tick, 13);
332 // Simple 'show' function
334 // Remember where we started, so that we can go back to it later
335 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
336 this.options.show = true;
338 // Begin the animation
339 // Make sure that we start at a small width/height to avoid any
341 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
343 // Start by showing the element
344 jQuery( this.elem ).show();
347 // Simple 'hide' function
349 // Remember where we started, so that we can go back to it later
350 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
351 this.options.hide = true;
353 // Begin the animation
354 this.custom(this.cur(), 0);
357 // Each step of an animation
358 step: function( gotoEnd ) {
359 var t = now(), done = true;
361 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
363 this.pos = this.state = 1;
366 this.options.curAnim[ this.prop ] = true;
368 for ( var i in this.options.curAnim ) {
369 if ( this.options.curAnim[i] !== true ) {
375 if ( this.options.display != null ) {
376 // Reset the overflow
377 this.elem.style.overflow = this.options.overflow;
380 var old = jQuery.data(this.elem, "olddisplay");
381 this.elem.style.display = old ? old : this.options.display;
383 if ( jQuery.css(this.elem, "display") === "none" ) {
384 this.elem.style.display = "block";
388 // Hide the element if the "hide" operation was done
389 if ( this.options.hide ) {
390 jQuery(this.elem).hide();
393 // Reset the properties, if the item has been hidden or shown
394 if ( this.options.hide || this.options.show ) {
395 for ( var p in this.options.curAnim ) {
396 jQuery.style(this.elem, p, this.options.orig[p]);
400 // Execute the complete function
401 this.options.complete.call( this.elem );
407 var n = t - this.startTime;
408 this.state = n / this.options.duration;
410 // Perform the easing function, defaults to swing
411 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
412 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
413 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
414 this.now = this.start + ((this.end - this.start) * this.pos);
416 // Perform the next step of the animation
424 jQuery.extend( jQuery.fx, {
426 var timers = jQuery.timers;
428 for ( var i = 0; i < timers.length; i++ ) {
429 if ( !timers[i]() ) {
430 timers.splice(i--, 1);
434 if ( !timers.length ) {
440 clearInterval( timerId );
452 opacity: function( fx ) {
453 jQuery.style(fx.elem, "opacity", fx.now);
456 _default: function( fx ) {
457 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
458 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
460 fx.elem[ fx.prop ] = fx.now;
466 if ( jQuery.expr && jQuery.expr.filters ) {
467 jQuery.expr.filters.animated = function( elem ) {
468 return jQuery.grep(jQuery.timers, function( fn ) {
469 return elem === fn.elem;
474 function genFx( type, num ) {
477 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {