4 rfxtypes = /^(?:toggle|show|hide)$/,
5 rfxnum = /^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,
9 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
11 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
17 show: function( speed, easing, callback ) {
20 if ( speed || speed === 0 ) {
21 return this.animate( genFx("show", 3), speed, easing, callback);
24 for ( var i = 0, j = this.length; i < j; i++ ) {
26 display = elem.style.display;
28 // Reset the inline display of this element to learn if it is
29 // being hidden by cascaded rules or not
30 if ( !jQuery._data(elem, "olddisplay") && display === "none" ) {
31 display = elem.style.display = "";
34 // Set elements which have been overridden with display: none
35 // in a stylesheet to whatever the default browser style is
36 // for such an element
37 if ( display === "" && jQuery.css( elem, "display" ) === "none" ) {
38 jQuery._data(elem, "olddisplay", defaultDisplay(elem.nodeName));
42 // Set the display of most of the elements in a second loop
43 // to avoid the constant reflow
44 for ( i = 0; i < j; i++ ) {
46 display = elem.style.display;
48 if ( display === "" || display === "none" ) {
49 elem.style.display = jQuery._data(elem, "olddisplay") || "";
57 hide: function( speed, easing, callback ) {
58 if ( speed || speed === 0 ) {
59 return this.animate( genFx("hide", 3), speed, easing, callback);
62 for ( var i = 0, j = this.length; i < j; i++ ) {
63 var display = jQuery.css( this[i], "display" );
65 if ( display !== "none" && !jQuery._data( this[i], "olddisplay" ) ) {
66 jQuery._data( this[i], "olddisplay", display );
70 // Set the display of the elements in a second loop
71 // to avoid the constant reflow
72 for ( i = 0; i < j; i++ ) {
73 this[i].style.display = "none";
80 // Save the old toggle function
81 _toggle: jQuery.fn.toggle,
83 toggle: function( fn, fn2, callback ) {
84 var bool = typeof fn === "boolean";
86 if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
87 this._toggle.apply( this, arguments );
89 } else if ( fn == null || bool ) {
90 this.each(function() {
91 var state = bool ? fn : jQuery(this).is(":hidden");
92 jQuery(this)[ state ? "show" : "hide" ]();
96 this.animate(genFx("toggle", 3), fn, fn2, callback);
102 fadeTo: function( speed, to, easing, callback ) {
103 return this.filter(":hidden").css("opacity", 0).show().end()
104 .animate({opacity: to}, speed, easing, callback);
107 animate: function( prop, speed, easing, callback ) {
108 var optall = jQuery.speed(speed, easing, callback);
110 if ( jQuery.isEmptyObject( prop ) ) {
111 return this.each( optall.complete );
114 return this[ optall.queue === false ? "each" : "queue" ](function() {
115 // XXX 'this' does not always have a nodeName when running the
118 var opt = jQuery.extend({}, optall), p,
119 isElement = this.nodeType === 1,
120 hidden = isElement && jQuery(this).is(":hidden"),
124 var name = jQuery.camelCase( p );
127 prop[ name ] = prop[ p ];
132 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
133 return opt.complete.call(this);
136 if ( isElement && ( p === "height" || p === "width" ) ) {
137 // Make sure that nothing sneaks out
138 // Record all 3 overflow attributes because IE does not
139 // change the overflow attribute when overflowX and
140 // overflowY are set to the same value
141 opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
143 // Set display property to inline-block for height/width
144 // animations on inline elements that are having width/height
146 if ( jQuery.css( this, "display" ) === "inline" &&
147 jQuery.css( this, "float" ) === "none" ) {
148 if ( !jQuery.support.inlineBlockNeedsLayout ) {
149 this.style.display = "inline-block";
152 var display = defaultDisplay(this.nodeName);
154 // inline-level elements accept inline-block;
155 // block-level elements need to be inline with layout
156 if ( display === "inline" ) {
157 this.style.display = "inline-block";
160 this.style.display = "inline";
167 if ( jQuery.isArray( prop[p] ) ) {
168 // Create (if needed) and add to specialEasing
169 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
170 prop[p] = prop[p][0];
174 if ( opt.overflow != null ) {
175 this.style.overflow = "hidden";
178 opt.curAnim = jQuery.extend({}, prop);
180 jQuery.each( prop, function( name, val ) {
181 var e = new jQuery.fx( self, opt, name );
183 if ( rfxtypes.test(val) ) {
184 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
187 var parts = rfxnum.exec(val),
188 start = e.cur() || 0;
191 var end = parseFloat( parts[2] ),
192 unit = parts[3] || "px";
194 // We need to compute starting value
195 if ( unit !== "px" ) {
196 jQuery.style( self, name, (end || 1) + unit);
197 start = ((end || 1) / e.cur()) * start;
198 jQuery.style( self, name, start + unit);
201 // If a +=/-= token was provided, we're doing a relative animation
203 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
206 e.custom( start, end, unit );
209 e.custom( start, val, "" );
214 // For JS strict compliance
219 stop: function( clearQueue, gotoEnd ) {
220 var timers = jQuery.timers;
226 this.each(function() {
227 // go in reverse order so anything added to the queue during the loop is ignored
228 for ( var i = timers.length - 1; i >= 0; i-- ) {
229 if ( timers[i].elem === this ) {
231 // force the next step to be the last
240 // start the next in the queue if the last step wasn't forced
250 function genFx( type, num ) {
253 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
260 // Generate shortcuts for custom animations
262 slideDown: genFx("show", 1),
263 slideUp: genFx("hide", 1),
264 slideToggle: genFx("toggle", 1),
265 fadeIn: { opacity: "show" },
266 fadeOut: { opacity: "hide" },
267 fadeToggle: { opacity: "toggle" }
268 }, function( name, props ) {
269 jQuery.fn[ name ] = function( speed, easing, callback ) {
270 return this.animate( props, speed, easing, callback );
275 speed: function( speed, easing, fn ) {
276 var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
277 complete: fn || !fn && easing ||
278 jQuery.isFunction( speed ) && speed,
280 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
283 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
284 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
287 opt.old = opt.complete;
288 opt.complete = function() {
289 if ( opt.queue !== false ) {
290 jQuery(this).dequeue();
292 if ( jQuery.isFunction( opt.old ) ) {
293 opt.old.call( this );
301 linear: function( p, n, firstNum, diff ) {
302 return firstNum + diff * p;
304 swing: function( p, n, firstNum, diff ) {
305 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
311 fx: function( elem, options, prop ) {
312 this.options = options;
316 if ( !options.orig ) {
323 jQuery.fx.prototype = {
324 // Simple function for setting a style value
326 if ( this.options.step ) {
327 this.options.step.call( this.elem, this.now, this );
330 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
333 // Get the current size
335 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
336 return this.elem[ this.prop ];
339 var r = parseFloat( jQuery.css( this.elem, this.prop ) );
343 // Start an animation from one number to another
344 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 function t( gotoEnd ) {
356 return self.step(gotoEnd);
361 if ( t() && jQuery.timers.push(t) && !timerId ) {
362 timerId = setInterval(fx.tick, fx.interval);
366 // Simple 'show' function
368 // Remember where we started, so that we can go back to it later
369 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
370 this.options.show = true;
372 // Begin the animation
373 // Make sure that we start at a small width/height to avoid any
375 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
377 // Start by showing the element
378 jQuery( this.elem ).show();
381 // Simple 'hide' function
383 // Remember where we started, so that we can go back to it later
384 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
385 this.options.hide = true;
387 // Begin the animation
388 this.custom(this.cur(), 0);
391 // Each step of an animation
392 step: function( gotoEnd ) {
393 var t = jQuery.now(), done = true;
395 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
397 this.pos = this.state = 1;
400 this.options.curAnim[ this.prop ] = true;
402 for ( var i in this.options.curAnim ) {
403 if ( this.options.curAnim[i] !== true ) {
409 // Reset the overflow
410 if ( this.options.overflow != null && !jQuery.support.shrinkWrapBlocks ) {
411 var elem = this.elem,
412 options = this.options;
414 jQuery.each( [ "", "X", "Y" ], function (index, value) {
415 elem.style[ "overflow" + value ] = options.overflow[index];
419 // Hide the element if the "hide" operation was done
420 if ( this.options.hide ) {
421 jQuery(this.elem).hide();
424 // Reset the properties, if the item has been hidden or shown
425 if ( this.options.hide || this.options.show ) {
426 for ( var p in this.options.curAnim ) {
427 jQuery.style( this.elem, p, this.options.orig[p] );
431 // Execute the complete function
432 this.options.complete.call( this.elem );
438 var n = t - this.startTime;
439 this.state = n / this.options.duration;
441 // Perform the easing function, defaults to swing
442 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
443 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
444 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
445 this.now = this.start + ((this.end - this.start) * this.pos);
447 // Perform the next step of the animation
455 jQuery.extend( jQuery.fx, {
457 var timers = jQuery.timers;
459 for ( var i = 0; i < timers.length; i++ ) {
460 if ( !timers[i]() ) {
461 timers.splice(i--, 1);
465 if ( !timers.length ) {
473 clearInterval( timerId );
485 opacity: function( fx ) {
486 jQuery.style( fx.elem, "opacity", fx.now );
489 _default: function( fx ) {
490 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
491 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
493 fx.elem[ fx.prop ] = fx.now;
499 if ( jQuery.expr && jQuery.expr.filters ) {
500 jQuery.expr.filters.animated = function( elem ) {
501 return jQuery.grep(jQuery.timers, function( fn ) {
502 return elem === fn.elem;
507 function defaultDisplay( nodeName ) {
508 if ( !elemdisplay[ nodeName ] ) {
509 var elem = jQuery("<" + nodeName + ">").appendTo("body"),
510 display = elem.css("display");
514 if ( display === "none" || display === "" ) {
518 elemdisplay[ nodeName ] = display;
521 return elemdisplay[ nodeName ];