Added some memory leak protection.
[jquery.git] / fx / fx.js
index 71764c0..44633ab 100644 (file)
--- a/fx/fx.js
+++ b/fx/fx.js
@@ -20,7 +20,7 @@ jQuery.fn.extend({
                }, speed, callback) : this._show();
        },
        
-       // We're overwriting the old hide method
+       // Overwrite the old hide method
        _hide: jQuery.fn.hide,
        
        /**
@@ -204,12 +204,12 @@ jQuery.extend({
        
                // Figure out the maximum number to run to
                z.max = function(){
-                       return z.el["orig"+prop] || z.cur();
+                       return parseFloat( jQuery.css(z.el,prop) );
                };
        
                // Get the current size
                z.cur = function(){
-                       return parseFloat( jQuery.css(z.el,prop) );
+                       return parseFloat( jQuery.curCSS(z.el,prop) ) || z.max();
                };
        
                // Start an animation from one number to another
@@ -225,21 +225,29 @@ jQuery.extend({
        
                // Simple 'show' function
                z.show = function(){
-                       y.display = "block";
-                       z.o.auto = true;
+                       if ( !z.el.orig ) z.el.orig = {};
+
+                       // Remember where we started, so that we can go back to it later
+                       z.el.orig[prop] = this.cur();
+
+                       if ( !y[prop] ) z.o.auto = true;
                        z.custom(0,z.max());
+                       y.display = "block";
                };
        
                // Simple 'hide' function
                z.hide = function(){
+                       if ( !z.el.orig ) z.el.orig = {};
+
                        // Remember where we started, so that we can go back to it later
-                       z.el["orig"+prop] = this.cur();
-       
+                       z.el.orig[prop] = this.cur();
+
+                       z.o.hide = true;        
                        // Begin the animation
                        z.custom(z.cur(),0);
                };
        
-               // IE has trouble with opacity if it doesn't have layout
+               // IE has trouble with opacity if it does not have layout
                if ( jQuery.browser.msie && !z.el.currentStyle.hasLayout )
                        y.zoom = 1;
        
@@ -263,24 +271,27 @@ jQuery.extend({
        
                                // Reset the overflow
                                y.overflow = z.oldOverflow;
-       
+
                                // If the element was shown, and not using a custom number,
                                // set its height and/or width to auto
                                if ( (prop == "height" || prop == "width") && z.o.auto )
                                        jQuery.setAuto( z.el, prop );
-       
+
                                // If a callback was provided, execute it
                                if( z.o.complete && z.o.complete.constructor == Function ) {
        
                                        // Yes, this is a weird place for this, but it needs to be executed
                                        // only once per cluster of effects.
                                        // If the element is, effectively, hidden - hide it
-                                       if ( y.height == "0px" || y.width == "0px" )
-                                               y.display = "none";
+                                       if ( z.o.hide ) y.display = "none";
        
                                        // Execute the complete function
                                        z.o.complete.apply( z.el );
                                }
+
+                               // Reset the property, if the item has been hidden
+                               if ( z.o.hide )
+                                       y[ prop ] = z.el.orig[ prop ].constructor == Number && prop != "opacity" ? z.el.orig[prop] + "px" : z.el.orig[prop];
                        } else {
                                // Figure out where in the animation we are and set the number
                                var p = (t - this.startTime) / z.o.duration;