2 fxHeight = [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
3 fxWidth = [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
4 fxOpacity = [ "opacity" ];
6 function genFx( type, width, height, extra ){
8 jQuery.each(width.concat( height || [], extra || []), function(){
15 show: function(speed,callback){
17 return this.animate( genFx("show", fxHeight, fxWidth, fxOpacity), speed, callback);
19 for ( var i = 0, l = this.length; i < l; i++ ){
20 var old = jQuery.data(this[i], "olddisplay");
22 this[i].style.display = old || "";
24 if ( jQuery.css(this[i], "display") === "none" ) {
25 var tagName = this[i].tagName, display;
27 if ( elemdisplay[ tagName ] ) {
28 display = elemdisplay[ tagName ];
30 var elem = jQuery("<" + tagName + " />").appendTo("body");
32 display = elem.css("display");
33 if ( display === "none" )
38 elemdisplay[ tagName ] = display;
41 this[i].style.display = jQuery.data(this[i], "olddisplay", display);
49 hide: function(speed,callback){
51 return this.animate( genFx("hide", fxHeight, fxWidth, fxOpacity), speed, callback);
53 for ( var i = 0, l = this.length; i < l; i++ ){
54 var old = jQuery.data(this[i], "olddisplay");
55 if ( !old && old !== "none" )
56 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
57 this[i].style.display = "none";
63 // Save the old toggle function
64 _toggle: jQuery.fn.toggle,
66 toggle: function( fn, fn2 ){
67 var bool = typeof fn === "boolean";
69 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
70 this._toggle.apply( this, arguments ) :
73 var state = bool ? fn : jQuery(this).is(":hidden");
74 jQuery(this)[ state ? "show" : "hide" ]();
76 this.animate(genFx("toggle", fxHeight, fxWidth, fxOpacity), fn, fn2);
79 fadeTo: function(speed,to,callback){
80 return this.animate({opacity: to}, speed, callback);
83 animate: function( prop, speed, easing, callback ) {
84 var optall = jQuery.speed(speed, easing, callback);
86 return this[ optall.queue === false ? "each" : "queue" ](function(){
88 var opt = jQuery.extend({}, optall), p,
89 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
93 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
94 return opt.complete.call(this);
96 if ( ( p == "height" || p == "width" ) && this.style ) {
97 // Store display property
98 opt.display = jQuery.css(this, "display");
100 // Make sure that nothing sneaks out
101 opt.overflow = this.style.overflow;
105 if ( opt.overflow != null )
106 this.style.overflow = "hidden";
108 opt.curAnim = jQuery.extend({}, prop);
110 jQuery.each( prop, function(name, val){
111 var e = new jQuery.fx( self, opt, name );
113 if ( /toggle|show|hide/.test(val) )
114 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
116 var parts = val.toString().match(/^([+-]=)?([\d+-.]+)(.*)$/),
117 start = e.cur(true) || 0;
120 var end = parseFloat(parts[2]),
121 unit = parts[3] || "px";
123 // We need to compute starting value
124 if ( unit != "px" ) {
125 self.style[ name ] = (end || 1) + unit;
126 start = ((end || 1) / e.cur(true)) * start;
127 self.style[ name ] = start + unit;
130 // If a +=/-= token was provided, we're doing a relative animation
132 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
134 e.custom( start, end, unit );
136 e.custom( start, val, "" );
140 // For JS strict compliance
145 stop: function(clearQueue, gotoEnd){
146 var timers = jQuery.timers;
151 this.each(function(){
152 // go in reverse order so anything added to the queue during the loop is ignored
153 for ( var i = timers.length - 1; i >= 0; i-- )
154 if ( timers[i].elem == this ) {
156 // force the next step to be the last
162 // start the next in the queue if the last step wasn't forced
171 // Generate shortcuts for custom animations
173 slideDown: genFx("show", fxHeight),
174 slideUp: genFx("hide", fxHeight),
175 slideToggle: genFx("toggle", fxHeight),
176 fadeIn: { opacity: "show" },
177 fadeOut: { opacity: "hide" }
178 }, function( name, props ){
179 jQuery.fn[ name ] = function( speed, callback ){
180 return this.animate( props, speed, callback );
186 speed: function(speed, easing, fn) {
187 var opt = typeof speed === "object" ? speed : {
188 complete: fn || !fn && easing ||
189 jQuery.isFunction( speed ) && speed,
191 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
194 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
195 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
198 opt.old = opt.complete;
199 opt.complete = function(){
200 if ( opt.queue !== false )
201 jQuery(this).dequeue();
202 if ( jQuery.isFunction( opt.old ) )
203 opt.old.call( this );
210 linear: function( p, n, firstNum, diff ) {
211 return firstNum + diff * p;
213 swing: function( p, n, firstNum, diff ) {
214 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
221 fx: function( elem, options, prop ){
222 this.options = options;
232 jQuery.fx.prototype = {
234 // Simple function for setting a style value
236 if ( this.options.step )
237 this.options.step.call( this.elem, this.now, this );
239 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
241 // Set display property to block for height/width animations
242 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style )
243 this.elem.style.display = "block";
246 // Get the current size
247 cur: function(force){
248 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) )
249 return this.elem[ this.prop ];
251 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
252 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
255 // Start an animation from one number to another
256 custom: function(from, to, unit){
257 this.startTime = now();
260 this.unit = unit || this.unit || "px";
261 this.now = this.start;
262 this.pos = this.state = 0;
266 return self.step(gotoEnd);
271 jQuery.timers.push(t);
273 if ( t() && jQuery.timerId == null ) {
274 jQuery.timerId = setInterval(function(){
275 var timers = jQuery.timers;
277 for ( var i = 0; i < timers.length; i++ )
279 timers.splice(i--, 1);
281 if ( !timers.length ) {
282 clearInterval( jQuery.timerId );
283 jQuery.timerId = null;
289 // Simple 'show' function
291 // Remember where we started, so that we can go back to it later
292 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
293 this.options.show = true;
295 // Begin the animation
296 // Make sure that we start at a small width/height to avoid any
298 this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur());
300 // Start by showing the element
301 jQuery(this.elem).show();
304 // Simple 'hide' function
306 // Remember where we started, so that we can go back to it later
307 this.options.orig[this.prop] = jQuery.attr( this.elem.style, this.prop );
308 this.options.hide = true;
310 // Begin the animation
311 this.custom(this.cur(), 0);
314 // Each step of an animation
315 step: function(gotoEnd){
318 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
320 this.pos = this.state = 1;
323 this.options.curAnim[ this.prop ] = true;
326 for ( var i in this.options.curAnim )
327 if ( this.options.curAnim[i] !== true )
331 if ( this.options.display != null ) {
332 // Reset the overflow
333 this.elem.style.overflow = this.options.overflow;
336 this.elem.style.display = this.options.display;
337 if ( jQuery.css(this.elem, "display") == "none" )
338 this.elem.style.display = "block";
341 // Hide the element if the "hide" operation was done
342 if ( this.options.hide )
343 jQuery(this.elem).hide();
345 // Reset the properties, if the item has been hidden or shown
346 if ( this.options.hide || this.options.show )
347 for ( var p in this.options.curAnim )
348 jQuery.attr(this.elem.style, p, this.options.orig[p]);
352 // Execute the complete function
353 this.options.complete.call( this.elem );
357 var n = t - this.startTime;
358 this.state = n / this.options.duration;
360 // Perform the easing function, defaults to swing
361 this.pos = jQuery.easing[this.options.easing || (jQuery.easing.swing ? "swing" : "linear")](this.state, n, 0, 1, this.options.duration);
362 this.now = this.start + ((this.end - this.start) * this.pos);
364 // Perform the next step of the animation
373 jQuery.extend( jQuery.fx, {
382 opacity: function(fx){
383 jQuery.attr(fx.elem.style, "opacity", fx.now);
386 _default: function(fx){
387 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null )
388 fx.elem.style[ fx.prop ] = fx.now + fx.unit;
390 fx.elem[ fx.prop ] = fx.now;