4 rfxtypes = /toggle|show|hide/,
5 rfxnum = /^([+\-]=)?([\d+.\-]+)(.*)$/,
6 rdashAlpha = /-([a-z])/ig,
10 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
12 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
17 fcamelCase = function( all, letter ) {
18 return letter.toUpperCase();
22 show: function( speed, callback ) {
23 if ( speed || speed === 0) {
24 return this.animate( genFx("show", 3), speed, callback);
27 for ( var i = 0, l = this.length; i < l; i++ ) {
28 var old = jQuery.data(this[i], "olddisplay");
30 this[i].style.display = old || "";
32 if ( jQuery.css( this[i], "display" ) === "none" ) {
33 var nodeName = this[i].nodeName, display;
35 if ( elemdisplay[ nodeName ] ) {
36 display = elemdisplay[ nodeName ];
39 var elem = jQuery("<" + nodeName + " />").appendTo("body");
41 display = elem.css("display");
43 if ( display === "none" ) {
49 elemdisplay[ nodeName ] = display;
52 jQuery.data(this[i], "olddisplay", display);
56 // Set the display of the elements in a second loop
57 // to avoid the constant reflow
58 for ( var j = 0, k = this.length; j < k; j++ ) {
59 this[j].style.display = jQuery.data(this[j], "olddisplay") || "";
66 hide: function( speed, callback ) {
67 if ( speed || speed === 0 ) {
68 return this.animate( genFx("hide", 3), speed, callback);
71 for ( var i = 0, l = this.length; i < l; i++ ) {
72 var old = jQuery.data(this[i], "olddisplay");
73 if ( !old && old !== "none" ) {
74 jQuery.data( this[i], "olddisplay", jQuery.css( this[i], "display" ) );
78 // Set the display of the elements in a second loop
79 // to avoid the constant reflow
80 for ( var j = 0, k = this.length; j < k; j++ ) {
81 this[j].style.display = "none";
88 // Save the old toggle function
89 _toggle: jQuery.fn.toggle,
91 toggle: function( fn, fn2 ) {
92 var bool = typeof fn === "boolean";
94 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
95 this._toggle.apply( this, arguments );
97 } else if ( fn == null || bool ) {
98 this.each(function() {
99 var state = bool ? fn : jQuery(this).is(":hidden");
100 jQuery(this)[ state ? "show" : "hide" ]();
104 this.animate(genFx("toggle", 3), fn, fn2);
110 fadeTo: function( speed, to, callback ) {
111 return this.filter(":hidden").css("opacity", 0).show().end()
112 .animate({opacity: to}, speed, callback);
115 animate: function( prop, speed, easing, callback ) {
116 var optall = jQuery.speed(speed, easing, callback);
118 if ( jQuery.isEmptyObject( prop ) ) {
119 return this.each( optall.complete );
122 return this[ optall.queue === false ? "each" : "queue" ](function() {
123 var opt = jQuery.extend({}, optall), p,
124 hidden = this.nodeType === 1 && jQuery(this).is(":hidden"),
128 var name = p.replace(rdashAlpha, fcamelCase);
131 prop[ name ] = prop[ p ];
136 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
137 return opt.complete.call(this);
140 if ( ( p === "height" || p === "width" ) && this.style ) {
141 // Store display property
142 opt.display = this.style.display;
144 // Make sure that nothing sneaks out
145 opt.overflow = this.style.overflow;
148 if ( jQuery.isArray( prop[p] ) ) {
149 // Create (if needed) and add to specialEasing
150 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
151 prop[p] = prop[p][0];
155 if ( opt.overflow != null ) {
156 this.style.overflow = "hidden";
159 opt.curAnim = jQuery.extend({}, prop);
161 jQuery.each( prop, function( name, val ) {
162 var e = new jQuery.fx( self, opt, name );
164 if ( rfxtypes.test(val) ) {
165 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
168 var parts = rfxnum.exec(val),
169 start = e.cur(true) || 0;
172 var end = parseFloat( parts[2] ),
173 unit = parts[3] || "px";
175 // We need to compute starting value
176 if ( unit !== "px" ) {
177 self.style[ name ] = (end || 1) + unit;
178 start = ((end || 1) / e.cur(true)) * start;
179 self.style[ name ] = start + unit;
182 // If a +=/-= token was provided, we're doing a relative animation
184 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
187 e.custom( start, end, unit );
190 e.custom( start, val, "" );
195 // For JS strict compliance
200 stop: function( clearQueue, gotoEnd ) {
201 var timers = jQuery.timers;
207 this.each(function() {
208 // go in reverse order so anything added to the queue during the loop is ignored
209 for ( var i = timers.length - 1; i >= 0; i-- ) {
210 if ( timers[i].elem === this ) {
212 // force the next step to be the last
221 // start the next in the queue if the last step wasn't forced
231 function genFx( type, num ) {
234 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
241 // Generate shortcuts for custom animations
243 slideDown: genFx("show", 1),
244 slideUp: genFx("hide", 1),
245 slideToggle: genFx("toggle", 1),
246 fadeIn: { opacity: "show" },
247 fadeOut: { opacity: "hide" }
248 }, function( name, props ) {
249 jQuery.fn[ name ] = function( speed, callback ) {
250 return this.animate( props, speed, callback );
255 speed: function( speed, easing, fn ) {
256 var opt = speed && typeof speed === "object" ? speed : {
257 complete: fn || !fn && easing ||
258 jQuery.isFunction( speed ) && speed,
260 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
263 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
264 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
267 opt.old = opt.complete;
268 opt.complete = function() {
269 if ( opt.queue !== false ) {
270 jQuery(this).dequeue();
272 if ( jQuery.isFunction( opt.old ) ) {
273 opt.old.call( this );
281 linear: function( p, n, firstNum, diff ) {
282 return firstNum + diff * p;
284 swing: function( p, n, firstNum, diff ) {
285 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
291 fx: function( elem, options, prop ) {
292 this.options = options;
296 if ( !options.orig ) {
303 jQuery.fx.prototype = {
304 // Simple function for setting a style value
306 if ( this.options.step ) {
307 this.options.step.call( this.elem, this.now, this );
310 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
312 // Set display property to block for height/width animations
313 if ( ( this.prop === "height" || this.prop === "width" ) && this.elem.style ) {
314 this.elem.style.display = "block";
318 // Get the current size
320 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
321 return this.elem[ this.prop ];
324 var r = jQuery.css( this.elem, this.prop );
325 return r && r > -10000 ? r : 0;
328 // Start an animation from one number to another
329 custom: function( from, to, unit ) {
330 this.startTime = jQuery.now();
333 this.unit = unit || this.unit || "px";
334 this.now = this.start;
335 this.pos = this.state = 0;
338 function t( gotoEnd ) {
339 return self.step(gotoEnd);
344 if ( t() && jQuery.timers.push(t) && !timerId ) {
345 timerId = setInterval(jQuery.fx.tick, 13);
349 // Simple 'show' function
351 // Remember where we started, so that we can go back to it later
352 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
353 this.options.show = true;
355 // Begin the animation
356 // Make sure that we start at a small width/height to avoid any
358 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
360 // Start by showing the element
361 jQuery( this.elem ).show();
364 // Simple 'hide' function
366 // Remember where we started, so that we can go back to it later
367 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
368 this.options.hide = true;
370 // Begin the animation
371 this.custom(this.cur(), 0);
374 // Each step of an animation
375 step: function( gotoEnd ) {
376 var t = jQuery.now(), done = true;
378 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
380 this.pos = this.state = 1;
383 this.options.curAnim[ this.prop ] = true;
385 for ( var i in this.options.curAnim ) {
386 if ( this.options.curAnim[i] !== true ) {
392 if ( this.options.display != null ) {
393 // Reset the overflow
394 this.elem.style.overflow = this.options.overflow;
397 var old = jQuery.data(this.elem, "olddisplay");
398 this.elem.style.display = old ? old : this.options.display;
400 if ( jQuery.css( this.elem, "display" ) === "none" ) {
401 this.elem.style.display = "block";
405 // Hide the element if the "hide" operation was done
406 if ( this.options.hide ) {
407 jQuery(this.elem).hide();
410 // Reset the properties, if the item has been hidden or shown
411 if ( this.options.hide || this.options.show ) {
412 for ( var p in this.options.curAnim ) {
413 jQuery.style( this.elem, p, this.options.orig[p] );
417 // Execute the complete function
418 this.options.complete.call( this.elem );
424 var n = t - this.startTime;
425 this.state = n / this.options.duration;
427 // Perform the easing function, defaults to swing
428 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
429 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
430 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
431 this.now = this.start + ((this.end - this.start) * this.pos);
433 // Perform the next step of the animation
441 jQuery.extend( jQuery.fx, {
443 var timers = jQuery.timers;
445 for ( var i = 0; i < timers.length; i++ ) {
446 if ( !timers[i]() ) {
447 timers.splice(i--, 1);
451 if ( !timers.length ) {
457 clearInterval( timerId );
469 opacity: function( fx ) {
470 jQuery.style( fx.elem, "opacity", fx.now );
473 _default: function( fx ) {
474 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
475 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
477 fx.elem[ fx.prop ] = fx.now;
483 if ( jQuery.expr && jQuery.expr.filters ) {
484 jQuery.expr.filters.animated = function( elem ) {
485 return jQuery.grep(jQuery.timers, function( fn ) {
486 return elem === fn.elem;