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 ) {
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" ),
64 old = jQuery.data( this[i], "olddisplay" );
66 if ( !old && display !== "none" ) {
67 jQuery.data( this[i], "olddisplay", display );
71 // Set the display of the elements in a second loop
72 // to avoid the constant reflow
73 for ( i = 0; i < j; i++ ) {
74 this[i].style.display = "none";
81 // Save the old toggle function
82 _toggle: jQuery.fn.toggle,
84 toggle: function( fn, fn2, callback ) {
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, callback);
103 fadeTo: function( speed, to, easing, callback ) {
104 return this.filter(":hidden").css("opacity", 0).show().end()
105 .animate({opacity: to}, speed, easing, 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 // XXX 'this' does not always have a nodeName when running the
119 var opt = jQuery.extend({}, optall), p,
120 isElement = this.nodeType === 1,
121 hidden = isElement && jQuery(this).is(":hidden"),
125 var name = jQuery.camelCase( p );
128 prop[ name ] = prop[ p ];
133 if ( prop[p] === "hide" && hidden || prop[p] === "show" && !hidden ) {
134 return opt.complete.call(this);
137 if ( isElement && ( p === "height" || p === "width" ) ) {
138 // Make sure that nothing sneaks out
139 // Record all 3 overflow attributes because IE does not
140 // change the overflow attribute when overflowX and
141 // overflowY are set to the same value
142 opt.overflow = [ this.style.overflow, this.style.overflowX, this.style.overflowY ];
144 // Set display property to inline-block for height/width
145 // animations on inline elements that are having width/height
147 if ( jQuery.css( this, "display" ) === "inline" &&
148 jQuery.css( this, "float" ) === "none" ) {
149 if ( !jQuery.support.inlineBlockNeedsLayout ) {
150 this.style.display = "inline-block";
153 var display = defaultDisplay(this.nodeName);
155 // inline-level elements accept inline-block;
156 // block-level elements need to be inline with layout
157 if ( display === "inline" ) {
158 this.style.display = "inline-block";
161 this.style.display = "inline";
168 if ( jQuery.isArray( prop[p] ) ) {
169 // Create (if needed) and add to specialEasing
170 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
171 prop[p] = prop[p][0];
175 if ( opt.overflow != null ) {
176 this.style.overflow = "hidden";
179 opt.curAnim = jQuery.extend({}, prop);
181 jQuery.each( prop, function( name, val ) {
182 var e = new jQuery.fx( self, opt, name );
184 if ( rfxtypes.test(val) ) {
185 e[ val === "toggle" ? hidden ? "show" : "hide" : val ]( prop );
188 var parts = rfxnum.exec(val),
189 start = e.cur() || 0;
192 var end = parseFloat( parts[2] ),
193 unit = parts[3] || "px";
195 // We need to compute starting value
196 if ( unit !== "px" ) {
197 jQuery.style( self, name, (end || 1) + unit);
198 start = ((end || 1) / e.cur()) * start;
199 jQuery.style( self, name, start + unit);
202 // If a +=/-= token was provided, we're doing a relative animation
204 end = ((parts[1] === "-=" ? -1 : 1) * end) + start;
207 e.custom( start, end, unit );
210 e.custom( start, val, "" );
215 // For JS strict compliance
220 stop: function( clearQueue, gotoEnd ) {
221 var timers = jQuery.timers;
227 this.each(function() {
228 // go in reverse order so anything added to the queue during the loop is ignored
229 for ( var i = timers.length - 1; i >= 0; i-- ) {
230 if ( timers[i].elem === this ) {
232 // force the next step to be the last
241 // start the next in the queue if the last step wasn't forced
251 function genFx( type, num ) {
254 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
261 // Generate shortcuts for custom animations
263 slideDown: genFx("show", 1),
264 slideUp: genFx("hide", 1),
265 slideToggle: genFx("toggle", 1),
266 fadeIn: { opacity: "show" },
267 fadeOut: { opacity: "hide" },
268 fadeToggle: { opacity: "toggle" }
269 }, function( name, props ) {
270 jQuery.fn[ name ] = function( speed, easing, callback ) {
271 return this.animate( props, speed, easing, callback );
276 speed: function( speed, easing, fn ) {
277 var opt = speed && typeof speed === "object" ? jQuery.extend({}, speed) : {
278 complete: fn || !fn && easing ||
279 jQuery.isFunction( speed ) && speed,
281 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
284 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
285 opt.duration in jQuery.fx.speeds ? jQuery.fx.speeds[opt.duration] : jQuery.fx.speeds._default;
288 opt.old = opt.complete;
289 opt.complete = function() {
290 if ( opt.queue !== false ) {
291 jQuery(this).dequeue();
293 if ( jQuery.isFunction( opt.old ) ) {
294 opt.old.call( this );
302 linear: function( p, n, firstNum, diff ) {
303 return firstNum + diff * p;
305 swing: function( p, n, firstNum, diff ) {
306 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
312 fx: function( elem, options, prop ) {
313 this.options = options;
317 if ( !options.orig ) {
324 jQuery.fx.prototype = {
325 // Simple function for setting a style value
327 if ( this.options.step ) {
328 this.options.step.call( this.elem, this.now, this );
331 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
334 // Get the current size
336 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
337 return this.elem[ this.prop ];
340 var r = parseFloat( jQuery.css( this.elem, this.prop ) );
341 return r && r > -10000 ? r : 0;
344 // Start an animation from one number to another
345 custom: function( from, to, unit ) {
349 this.startTime = jQuery.now();
352 this.unit = unit || this.unit || "px";
353 this.now = this.start;
354 this.pos = this.state = 0;
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 ) {
412 var elem = this.elem,
413 options = this.options;
415 jQuery.each( [ "", "X", "Y" ], function (index, value) {
416 elem.style[ "overflow" + value ] = options.overflow[index];
420 // Hide the element if the "hide" operation was done
421 if ( this.options.hide ) {
422 jQuery(this.elem).hide();
425 // Reset the properties, if the item has been hidden or shown
426 if ( this.options.hide || this.options.show ) {
427 for ( var p in this.options.curAnim ) {
428 jQuery.style( this.elem, p, this.options.orig[p] );
432 // Execute the complete function
433 this.options.complete.call( this.elem );
439 var n = t - this.startTime;
440 this.state = n / this.options.duration;
442 // Perform the easing function, defaults to swing
443 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
444 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
445 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
446 this.now = this.start + ((this.end - this.start) * this.pos);
448 // Perform the next step of the animation
456 jQuery.extend( jQuery.fx, {
458 var timers = jQuery.timers;
460 for ( var i = 0; i < timers.length; i++ ) {
461 if ( !timers[i]() ) {
462 timers.splice(i--, 1);
466 if ( !timers.length ) {
474 clearInterval( timerId );
486 opacity: function( fx ) {
487 jQuery.style( fx.elem, "opacity", fx.now );
490 _default: function( fx ) {
491 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
492 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
494 fx.elem[ fx.prop ] = fx.now;
500 if ( jQuery.expr && jQuery.expr.filters ) {
501 jQuery.expr.filters.animated = function( elem ) {
502 return jQuery.grep(jQuery.timers, function( fn ) {
503 return elem === fn.elem;
508 function defaultDisplay( nodeName ) {
509 if ( !elemdisplay[ nodeName ] ) {
510 var elem = jQuery("<" + nodeName + ">").appendTo("body"),
511 display = elem.css("display");
515 if ( display === "none" || display === "" ) {
519 elemdisplay[ nodeName ] = display;
522 return elemdisplay[ nodeName ];