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 || speed === 0) {
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 || speed === 0 ) {
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 function genFx( type, num ) {
227 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function() {
234 // Generate shortcuts for custom animations
236 slideDown: genFx("show", 1),
237 slideUp: genFx("hide", 1),
238 slideToggle: genFx("toggle", 1),
239 fadeIn: { opacity: "show" },
240 fadeOut: { opacity: "hide" }
241 }, function( name, props ) {
242 jQuery.fn[ name ] = function( speed, callback ) {
243 return this.animate( props, speed, callback );
248 speed: function( speed, easing, fn ) {
249 var opt = speed && typeof speed === "object" ? speed : {
250 complete: fn || !fn && easing ||
251 jQuery.isFunction( speed ) && speed,
253 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
256 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
257 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
260 opt.old = opt.complete;
261 opt.complete = function() {
262 if ( opt.queue !== false ) {
263 jQuery(this).dequeue();
265 if ( jQuery.isFunction( opt.old ) ) {
266 opt.old.call( this );
274 linear: function( p, n, firstNum, diff ) {
275 return firstNum + diff * p;
277 swing: function( p, n, firstNum, diff ) {
278 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
284 fx: function( elem, options, prop ) {
285 this.options = options;
289 if ( !options.orig ) {
296 jQuery.fx.prototype = {
297 // Simple function for setting a style value
299 if ( this.options.step ) {
300 this.options.step.call( this.elem, this.now, this );
303 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
305 // Set display property to block for height/width animations
306 if ( ( this.prop === "height" || this.prop === "width" ) && this.elem.style ) {
307 this.elem.style.display = "block";
311 // Get the current size
312 cur: function( force ) {
313 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
314 return this.elem[ this.prop ];
317 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
318 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
321 // Start an animation from one number to another
322 custom: function( from, to, unit ) {
323 this.startTime = now();
326 this.unit = unit || this.unit || "px";
327 this.now = this.start;
328 this.pos = this.state = 0;
331 function t( gotoEnd ) {
332 return self.step(gotoEnd);
337 if ( t() && jQuery.timers.push(t) && !timerId ) {
338 timerId = setInterval(jQuery.fx.tick, 13);
342 // Simple 'show' function
344 // Remember where we started, so that we can go back to it later
345 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
346 this.options.show = true;
348 // Begin the animation
349 // Make sure that we start at a small width/height to avoid any
351 this.custom(this.prop === "width" || this.prop === "height" ? 1 : 0, this.cur());
353 // Start by showing the element
354 jQuery( this.elem ).show();
357 // Simple 'hide' function
359 // Remember where we started, so that we can go back to it later
360 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
361 this.options.hide = true;
363 // Begin the animation
364 this.custom(this.cur(), 0);
367 // Each step of an animation
368 step: function( gotoEnd ) {
369 var t = now(), done = true;
371 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
373 this.pos = this.state = 1;
376 this.options.curAnim[ this.prop ] = true;
378 for ( var i in this.options.curAnim ) {
379 if ( this.options.curAnim[i] !== true ) {
385 if ( this.options.display != null ) {
386 // Reset the overflow
387 this.elem.style.overflow = this.options.overflow;
390 var old = jQuery.data(this.elem, "olddisplay");
391 this.elem.style.display = old ? old : this.options.display;
393 if ( jQuery.css(this.elem, "display") === "none" ) {
394 this.elem.style.display = "block";
398 // Hide the element if the "hide" operation was done
399 if ( this.options.hide ) {
400 jQuery(this.elem).hide();
403 // Reset the properties, if the item has been hidden or shown
404 if ( this.options.hide || this.options.show ) {
405 for ( var p in this.options.curAnim ) {
406 jQuery.style(this.elem, p, this.options.orig[p]);
410 // Execute the complete function
411 this.options.complete.call( this.elem );
417 var n = t - this.startTime;
418 this.state = n / this.options.duration;
420 // Perform the easing function, defaults to swing
421 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
422 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
423 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
424 this.now = this.start + ((this.end - this.start) * this.pos);
426 // Perform the next step of the animation
434 jQuery.extend( jQuery.fx, {
436 var timers = jQuery.timers;
438 for ( var i = 0; i < timers.length; i++ ) {
439 if ( !timers[i]() ) {
440 timers.splice(i--, 1);
444 if ( !timers.length ) {
450 clearInterval( timerId );
462 opacity: function( fx ) {
463 jQuery.style(fx.elem, "opacity", fx.now);
466 _default: function( fx ) {
467 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
468 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
470 fx.elem[ fx.prop ] = fx.now;
476 if ( jQuery.expr && jQuery.expr.filters ) {
477 jQuery.expr.filters.animated = function( elem ) {
478 return jQuery.grep(jQuery.timers, function( fn ) {
479 return elem === fn.elem;