X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Ffx.js;h=d76dbdbaeffaa5dbfc4cd84e3da445f68a8641ab;hb=17b1e407d101c5c7f91db633df3a80cd9b4466ae;hp=9bfe99962a3220606587e1dd9cc5c4ec602b9556;hpb=2ccd2cb36be6169afee3bd6e82ba3539f432c73f;p=jquery.git diff --git a/src/fx.js b/src/fx.js index 9bfe999..d76dbdb 100644 --- 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); @@ -146,30 +153,43 @@ jQuery.fn.extend({ }); }, - stop: function(){ + stop: function(clearQueue, gotoEnd){ var timers = jQuery.timers; - return this.each(function(){ - for ( var i = 0; i < timers.length; i++ ) - if ( timers[i].elem == this ) - timers.splice(i--, 1); - }).dequeue(); + if (clearQueue) + this.queue([]); + + this.each(function(){ + // go in reverse order so anything added to the queue during the loop is ignored + for ( var i = timers.length - 1; i >= 0; i-- ) + if ( timers[i].elem == this ) { + if (gotoEnd) + // force the next step to be the last + timers[i](true); + timers.splice(i, 1); + } + }); + + // start the next in the queue if the last step wasn't forced + if (!gotoEnd) + this.dequeue(); + + return this; } }); 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; }; @@ -198,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]) || 400; // Queueing opt.old = opt.complete; @@ -260,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"; @@ -269,8 +289,8 @@ jQuery.fx.prototype = { this.update(); var self = this; - function t(){ - return self.step(); + function t(gotoEnd){ + return self.step(gotoEnd); } t.elem = this.elem; @@ -322,10 +342,10 @@ jQuery.fx.prototype = { }, // Each step of an animation - step: function(){ - var t = (new Date()).getTime(); + step: function(gotoEnd){ + var t = now(); - if ( t > this.options.duration + this.startTime ) { + if ( gotoEnd || t > this.options.duration + this.startTime ) { this.now = this.end; this.pos = this.state = 1; this.update(); @@ -381,20 +401,26 @@ jQuery.fx.prototype = { }; -jQuery.fx.step = { - scrollLeft: function(fx){ - fx.elem.scrollLeft = fx.now; +jQuery.extend( jQuery.fx, { + speeds:{ + slow: 600, + fast: 200 }, - - 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; + 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; + } } -}; +});