diff options
author | Ariel Flesler <aflesler@gmail.com> | 2008-04-29 23:34:50 +0000 |
---|---|---|
committer | Ariel Flesler <aflesler@gmail.com> | 2008-04-29 23:34:50 +0000 |
commit | 17b1e407d101c5c7f91db633df3a80cd9b4466ae (patch) | |
tree | 7ba61683c0de076aa7cc4e438e43d3847bbea1e4 /src/fx.js | |
parent | ea44348fdb8d039dd74684cdafc6c73430f297b3 (diff) | |
download | jquery-17b1e407d101c5c7f91db633df3a80cd9b4466ae.tar.gz jquery-17b1e407d101c5c7f91db633df3a80cd9b4466ae.zip |
mainly made the code shorter:
- removed some needless if's
- replace multiple "var x" for one, comma separated declaration.
- added a local fn called now() for the (new Date)s
- fixed the indentation of a block, and a typo in a comment.
- used fn instead of prototype where possible
- jquery fx: exposed the speeds hash as jQuery.fx.speeds.
Also fixed (again) line endings
Diffstat (limited to 'src/fx.js')
-rw-r--r-- | src/fx.js | 66 |
1 files changed, 36 insertions, 30 deletions
@@ -76,10 +76,10 @@ jQuery.fn.extend({ if ( this.nodeType != 1) return false; - var opt = jQuery.extend({}, optall); - var hidden = jQuery(this).is(":hidden"), self = this; + 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); @@ -180,16 +180,16 @@ jQuery.fn.extend({ }); var queue = function( elem, type, array ) { - if ( !elem ) - return undefined; - - type = type || "fx"; - - var q = jQuery.data( elem, type + "queue" ); - - if ( !q || array ) - q = jQuery.data( elem, type + "queue", 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; }; @@ -218,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; @@ -280,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"; @@ -343,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; @@ -401,20 +401,26 @@ jQuery.fx.prototype = { }; -jQuery.fx.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); +jQuery.extend( jQuery.fx, { + speeds:{ + slow: 600, + fast: 200 }, - - _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; + } } -}; +}); |