jquery core: closes #2771
[jquery.git] / src / fx.js
index b35dbcd..5f3a492 100644 (file)
--- a/src/fx.js
+++ b/src/fx.js
@@ -6,9 +6,15 @@ jQuery.fn.extend({
                        }, speed, callback) :
                        
                        this.filter(":hidden").each(function(){
-                               this.style.display = this.oldblock ? this.oldblock : "";
-                               if ( jQuery.css(this,"display") == "none" )
-                                       this.style.display = "block";
+                               this.style.display = this.oldblock || "";
+                               if ( jQuery.css(this,"display") == "none" ) {
+                                       var elem = jQuery("<" + this.tagName + " />").appendTo("body");
+                                       this.style.display = elem.css("display");
+                                       // handle an edge condition where css is - div { display:none; } or similar
+                                       if (this.style.display == "none")
+                                               this.style.display = "block";
+                                       elem.remove();
+                               }
                        }).end();
        },
        
@@ -20,8 +26,6 @@ jQuery.fn.extend({
                        
                        this.filter(":visible").each(function(){
                                this.oldblock = this.oldblock || jQuery.css(this,"display");
-                               if ( this.oldblock == "none" )
-                                       this.oldblock = "block";
                                this.style.display = "none";
                        }).end();
        },
@@ -31,7 +35,7 @@ jQuery.fn.extend({
        
        toggle: function( fn, fn2 ){
                return jQuery.isFunction(fn) && jQuery.isFunction(fn2) ?
-                       this._toggle( fn, fn2 ) :
+                       this._toggle.apply( this, arguments ) :
                        fn ?
                                this.animate({
                                        height: "toggle", width: "toggle", opacity: "toggle"
@@ -69,10 +73,13 @@ jQuery.fn.extend({
                var optall = jQuery.speed(speed, easing, callback);
 
                return this[ optall.queue === false ? "each" : "queue" ](function(){
-                       var opt = jQuery.extend({}, optall);
-                       var hidden = jQuery(this).is(":hidden"), self = this;
+                       if ( this.nodeType != 1)
+                               return false;
+
+                       var opt = jQuery.extend({}, optall), p,
+                               hidden = jQuery(this).is(":hidden"), self = this;
                        
-                       for ( var p in prop ) {
+                       for ( p in prop ) {
                                if ( prop[p] == "hide" && hidden || prop[p] == "show" && !hidden )
                                        return jQuery.isFunction(opt.complete) && opt.complete.apply(this);
 
@@ -173,17 +180,16 @@ jQuery.fn.extend({
 });
 
 var queue = function( elem, type, array ) {
-       if ( !elem )
-               return;
-
-       type = type || "fx";
-
-       var q = jQuery.data( elem, type + "queue" );
-
-       if ( !q || array )
-               q = jQuery.data( elem, type + "queue", 
-                       array ? jQuery.makeArray(array) : [] );
+       if ( elem ){
+       
+               type = type || "fx";
+       
+               var q = jQuery.data( elem, type + "queue" );
+       
+               if ( !q || array )
+                       q = jQuery.data( elem, type + "queue", jQuery.makeArray(array) );
 
+       }
        return q;
 };
 
@@ -212,7 +218,7 @@ jQuery.extend({
 
                opt.duration = (opt.duration && opt.duration.constructor == Number ? 
                        opt.duration : 
-                       { slow: 600, fast: 200 }[opt.duration]) || 400;
+                       jQuery.fx.speeds[opt.duration]) || jQuery.fx.speeds.def;
        
                // Queueing
                opt.old = opt.complete;
@@ -274,7 +280,7 @@ jQuery.fx.prototype = {
 
        // Start an animation from one number to another
        custom: function(from, to, unit){
-               this.startTime = (new Date()).getTime();
+               this.startTime = now();
                this.start = from;
                this.end = to;
                this.unit = unit || this.unit || "px";
@@ -337,7 +343,7 @@ jQuery.fx.prototype = {
 
        // Each step of an animation
        step: function(gotoEnd){
-               var t = (new Date()).getTime();
+               var t = now();
 
                if ( gotoEnd || t > this.options.duration + this.startTime ) {
                        this.now = this.end;
@@ -395,20 +401,27 @@ jQuery.fx.prototype = {
 
 };
 
-jQuery.fx.step = {
-       scrollLeft: function(fx){
-               fx.elem.scrollLeft = fx.now;
-       },
-
-       scrollTop: function(fx){
-               fx.elem.scrollTop = fx.now;
+jQuery.extend( jQuery.fx, {
+       speeds:{
+               slow: 600,  
+               fast: 200,
+               def: 400 //default speed
        },
-
-       opacity: function(fx){
-               jQuery.attr(fx.elem.style, "opacity", fx.now);
-       },
-
-       _default: function(fx){
-               fx.elem.style[ fx.prop ] = fx.now + fx.unit;
+       step: {
+               scrollLeft: function(fx){
+                       fx.elem.scrollLeft = fx.now;
+               },
+       
+               scrollTop: function(fx){
+                       fx.elem.scrollTop = fx.now;
+               },
+       
+               opacity: function(fx){
+                       jQuery.attr(fx.elem.style, "opacity", fx.now);
+               },
+       
+               _default: function(fx){
+                       fx.elem.style[ fx.prop ] = fx.now + fx.unit;
+               }
        }
-};
+});