5 [ "height", "marginTop", "marginBottom", "paddingTop", "paddingBottom" ],
7 [ "width", "marginLeft", "marginRight", "paddingLeft", "paddingRight" ],
12 function genFx( type, num ){
14 jQuery.each( fxAttrs.concat.apply([], fxAttrs.slice(0,num)), function(){
21 show: function( speed, callback ) {
22 if ( speed != null ) {
23 return this.animate( genFx("show", 3), speed, callback);
25 for ( var i = 0, l = this.length; i < l; i++ ){
26 var old = jQuery.data(this[i], "olddisplay");
28 this[i].style.display = old || "";
30 if ( jQuery.css(this[i], "display") === "none" ) {
31 var nodeName = this[i].nodeName, display;
33 if ( elemdisplay[ nodeName ] ) {
34 display = elemdisplay[ nodeName ];
36 var elem = jQuery("<" + nodeName + " />").appendTo("body");
38 display = elem.css("display");
39 if ( display === "none" ) {
44 elemdisplay[ nodeName ] = display;
47 jQuery.data(this[i], "olddisplay", display);
51 // Set the display of the elements in a second loop
52 // to avoid the constant reflow
53 for ( var i = 0, l = this.length; i < l; i++ ){
54 this[i].style.display = jQuery.data(this[i], "olddisplay") || "";
61 hide: function( speed, callback ) {
62 if ( speed != null ) {
63 return this.animate( genFx("hide", 3), speed, callback);
65 for ( var i = 0, l = this.length; i < l; i++ ){
66 var old = jQuery.data(this[i], "olddisplay");
67 if ( !old && old !== "none" ){
68 jQuery.data(this[i], "olddisplay", jQuery.css(this[i], "display"));
72 // Set the display of the elements in a second loop
73 // to avoid the constant reflow
74 for ( var i = 0, l = this.length; i < l; i++ ){
75 this[i].style.display = "none";
82 // Save the old toggle function
83 _toggle: jQuery.fn.toggle,
85 toggle: function( fn, fn2 ){
86 var bool = typeof fn === "boolean";
88 return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
89 this._toggle.apply( this, arguments ) :
92 var state = bool ? fn : jQuery(this).is(":hidden");
93 jQuery(this)[ state ? "show" : "hide" ]();
95 this.animate(genFx("toggle", 3), fn, fn2);
98 fadeTo: function(speed,to,callback){
99 return this.filter(":hidden").css('opacity', 0).show().end()
100 .animate({opacity: to}, speed, callback);
103 animate: function( prop, speed, easing, callback ) {
104 var optall = jQuery.speed(speed, easing, callback);
106 return this[ optall.queue === false ? "each" : "queue" ](function(){
108 var opt = jQuery.extend({}, optall), p,
109 hidden = this.nodeType == 1 && jQuery(this).is(":hidden"),
113 var name = p.replace(rdashAlpha, fcamelCase);
116 prop[ name ] = prop[ p ];
121 if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden ) {
122 return opt.complete.call(this);
124 if ( ( p == "height" || p == "width" ) && this.style ) {
125 // Store display property
126 opt.display = jQuery.css(this, "display");
128 // Make sure that nothing sneaks out
129 opt.overflow = this.style.overflow;
131 if ( jQuery.isArray( prop[p] ) ) {
132 // Create (if needed) and add to specialEasing
133 (opt.specialEasing = opt.specialEasing || {})[p] = prop[p][1];
134 prop[p] = prop[p][0];
138 if ( opt.overflow != null ) {
139 this.style.overflow = "hidden";
141 opt.curAnim = jQuery.extend({}, prop);
143 jQuery.each( prop, function(name, val){
144 var e = new jQuery.fx( self, opt, name );
146 if ( /toggle|show|hide/.test(val) ) {
147 e[ val == "toggle" ? hidden ? "show" : "hide" : val ]( prop );
149 var parts = /^([+-]=)?([\d+-.]+)(.*)$/.exec(val),
150 start = e.cur(true) || 0;
153 var end = parseFloat(parts[2]),
154 unit = parts[3] || "px";
156 // We need to compute starting value
157 if ( unit != "px" ) {
158 self.style[ name ] = (end || 1) + unit;
159 start = ((end || 1) / e.cur(true)) * start;
160 self.style[ name ] = start + unit;
163 // If a +=/-= token was provided, we're doing a relative animation
165 end = ((parts[1] == "-=" ? -1 : 1) * end) + start;
167 e.custom( start, end, unit );
169 e.custom( start, val, "" );
174 if ( jQuery.isEmptyObject( prop ) ) {
175 return optall.complete.call(this);
178 // For JS strict compliance
183 stop: function(clearQueue, gotoEnd){
184 var timers = jQuery.timers;
189 this.each(function(){
190 // go in reverse order so anything added to the queue during the loop is ignored
191 for ( var i = timers.length - 1; i >= 0; i-- ) {
192 if ( timers[i].elem == this ) {
194 // force the next step to be the last
202 // start the next in the queue if the last step wasn't forced
211 // Generate shortcuts for custom animations
213 slideDown: genFx("show", 1),
214 slideUp: genFx("hide", 1),
215 slideToggle: genFx("toggle", 1),
216 fadeIn: { opacity: "show" },
217 fadeOut: { opacity: "hide" }
218 }, function( name, props ){
219 jQuery.fn[ name ] = function( speed, callback ){
220 return this.animate( props, speed, callback );
226 speed: function(speed, easing, fn) {
227 var opt = speed && typeof speed === "object" ? speed : {
228 complete: fn || !fn && easing ||
229 jQuery.isFunction( speed ) && speed,
231 easing: fn && easing || easing && !jQuery.isFunction(easing) && easing
234 opt.duration = jQuery.fx.off ? 0 : typeof opt.duration === "number" ? opt.duration :
235 jQuery.fx.speeds[opt.duration] || jQuery.fx.speeds._default;
238 opt.old = opt.complete;
239 opt.complete = function(){
240 if ( opt.queue !== false ) {
241 jQuery(this).dequeue();
243 if ( jQuery.isFunction( opt.old ) ) {
244 opt.old.call( this );
252 linear: function( p, n, firstNum, diff ) {
253 return firstNum + diff * p;
255 swing: function( p, n, firstNum, diff ) {
256 return ((-Math.cos(p*Math.PI)/2) + 0.5) * diff + firstNum;
262 fx: function( elem, options, prop ){
263 this.options = options;
267 if ( !options.orig ) {
274 jQuery.fx.prototype = {
276 // Simple function for setting a style value
278 if ( this.options.step ) {
279 this.options.step.call( this.elem, this.now, this );
281 (jQuery.fx.step[this.prop] || jQuery.fx.step._default)( this );
283 // Set display property to block for height/width animations
284 if ( ( this.prop == "height" || this.prop == "width" ) && this.elem.style ) {
285 this.elem.style.display = "block";
289 // Get the current size
290 cur: function(force){
291 if ( this.elem[this.prop] != null && (!this.elem.style || this.elem.style[this.prop] == null) ) {
292 return this.elem[ this.prop ];
294 var r = parseFloat(jQuery.css(this.elem, this.prop, force));
295 return r && r > -10000 ? r : parseFloat(jQuery.curCSS(this.elem, this.prop)) || 0;
298 // Start an animation from one number to another
299 custom: function(from, to, unit){
300 this.startTime = now();
303 this.unit = unit || this.unit || "px";
304 this.now = this.start;
305 this.pos = this.state = 0;
309 return self.step(gotoEnd);
314 if ( t() && jQuery.timers.push(t) && !timerId ) {
315 timerId = setInterval(jQuery.fx.tick, 13);
319 // Simple 'show' function
321 // Remember where we started, so that we can go back to it later
322 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
323 this.options.show = true;
325 // Begin the animation
326 // Make sure that we start at a small width/height to avoid any
328 this.custom(this.prop == "width" || this.prop == "height" ? 1 : 0, this.cur());
330 // Start by showing the element
331 jQuery(this.elem).show();
334 // Simple 'hide' function
336 // Remember where we started, so that we can go back to it later
337 this.options.orig[this.prop] = jQuery.style( this.elem, this.prop );
338 this.options.hide = true;
340 // Begin the animation
341 this.custom(this.cur(), 0);
344 // Each step of an animation
345 step: function(gotoEnd){
348 if ( gotoEnd || t >= this.options.duration + this.startTime ) {
350 this.pos = this.state = 1;
353 this.options.curAnim[ this.prop ] = true;
356 for ( var i in this.options.curAnim ) {
357 if ( this.options.curAnim[i] !== true ) {
362 if ( this.options.display != null ) {
363 // Reset the overflow
364 this.elem.style.overflow = this.options.overflow;
367 var old = jQuery.data(this.elem, "olddisplay");
368 this.elem.style.display = old ? old : this.options.display;
370 if ( jQuery.css(this.elem, "display") == "none" ) {
371 this.elem.style.display = "block";
375 // Hide the element if the "hide" operation was done
376 if ( this.options.hide ) {
377 jQuery(this.elem).hide();
379 // Reset the properties, if the item has been hidden or shown
380 if ( this.options.hide || this.options.show ){
381 for ( var p in this.options.curAnim ) {
382 jQuery.style(this.elem, p, this.options.orig[p]);
385 // Execute the complete function
386 this.options.complete.call( this.elem );
391 var n = t - this.startTime;
392 this.state = n / this.options.duration;
394 // Perform the easing function, defaults to swing
395 var specialEasing = this.options.specialEasing && this.options.specialEasing[this.prop];
396 var defaultEasing = this.options.easing || (jQuery.easing.swing ? "swing" : "linear");
397 this.pos = jQuery.easing[specialEasing || defaultEasing](this.state, n, 0, 1, this.options.duration);
398 this.now = this.start + ((this.end - this.start) * this.pos);
400 // Perform the next step of the animation
409 jQuery.extend( jQuery.fx, {
412 var timers = jQuery.timers;
414 for ( var i = 0; i < timers.length; i++ ) {
415 if ( !timers[i]() ) {
416 timers.splice(i--, 1);
419 if ( !timers.length ) {
425 clearInterval( timerId );
438 opacity: function(fx){
439 jQuery.style(fx.elem, "opacity", fx.now);
442 _default: function(fx){
443 if ( fx.elem.style && fx.elem.style[ fx.prop ] != null ) {
444 fx.elem.style[ fx.prop ] = (fx.prop === "width" || fx.prop === "height" ? Math.max(0, fx.now) : fx.now) + fx.unit;
446 fx.elem[ fx.prop ] = fx.now;
452 if ( jQuery.expr && jQuery.expr.filters ) {
453 jQuery.expr.filters.animated = function(elem){
454 return jQuery.grep(jQuery.timers, function(fn){
455 return elem === fn.elem;