aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorgnarf <gnarf@gnarf.net>2011-03-02 19:30:27 -0600
committergnarf <gnarf@gnarf.net>2011-03-02 19:30:27 -0600
commit2ad1cf331988e9a301dcd7474783eb58fcbc3c6d (patch)
treec199f0797d57a555c7bce25f5bd10279d859ed31
parent58b730f7c7a2fa848eeab12c5b26736a102ed1a4 (diff)
downloadjquery-ui-2ad1cf331988e9a301dcd7474783eb58fcbc3c6d.tar.gz
jquery-ui-2ad1cf331988e9a301dcd7474783eb58fcbc3c6d.zip
Starting to clean up the internal API for animations
-rw-r--r--ui/jquery.effects.blind.js20
-rw-r--r--ui/jquery.effects.core.js64
2 files changed, 41 insertions, 43 deletions
diff --git a/ui/jquery.effects.blind.js b/ui/jquery.effects.blind.js
index f1b823533..4ebba4071 100644
--- a/ui/jquery.effects.blind.js
+++ b/ui/jquery.effects.blind.js
@@ -17,17 +17,17 @@ $.effects.blind = function(o) {
return this.queue(function() {
// Create element
- var el = $(this), props = ['position','top','bottom','left','right'];
-
- // Set options
- var mode = $.effects.setMode(el, o.options.mode || 'hide'); // Set Mode
- var direction = o.options.direction || 'vertical'; // Default direction
+ var el = $(this),
+ props = ['position','top','bottom','left','right'],
+ mode = $.effects.setMode( el, o.mode || 'hide' ),
+ direction = o.direction || 'vertical',
+ ref = (direction == 'vertical') ? 'height' : 'width',
+ wrapper, distance; // Default direction
// Adjust
$.effects.save(el, props); el.show(); // Save & Show
- var wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
- var ref = (direction == 'vertical') ? 'height' : 'width';
- var distance = (direction == 'vertical') ? wrapper.height() : wrapper.width();
+ wrapper = $.effects.createWrapper(el).css({overflow:'hidden'}); // Create Wrapper
+ distance = wrapper[ direction == 'vertical' ? "height" : "width" ]();
if(mode == 'show') wrapper.css(ref, 0); // Shift
// Animation
@@ -35,10 +35,10 @@ $.effects.blind = function(o) {
animation[ref] = mode == 'show' ? distance : 0;
// Animate
- wrapper.animate(animation, o.duration, o.options.easing, function() {
+ wrapper.animate(animation, o.duration, o.easing, function() {
if(mode == 'hide') el.hide(); // Hide
$.effects.restore(el, props); $.effects.removeWrapper(el); // Restore
- if(o.callback) o.callback.apply(el[0], arguments); // Callback
+ if(o.complete) o.complete.apply(el[0], arguments); // Callback
el.dequeue();
});
diff --git a/ui/jquery.effects.core.js b/ui/jquery.effects.core.js
index a97ca040d..84e730889 100644
--- a/ui/jquery.effects.core.js
+++ b/ui/jquery.effects.core.js
@@ -410,39 +410,43 @@ $.extend($.effects, {
}
});
+// return an effect options object for the given parameters:
+function _normalizeArguments( effect, options, speed, callback ) {
+ var effectObj = {
+ effect: effect
+ };
-function _normalizeArguments(effect, options, speed, callback) {
- // shift params for method overloading
- if (typeof effect == 'object') {
- callback = options;
- speed = null;
- options = effect;
- effect = options.effect;
+ // passed an effect options object:
+ if ( $.isPlainObject( effect ) ) {
+ return effect;
}
- if ($.isFunction(options)) {
+
+ if ( $.isFunction(options) ) {
callback = options;
speed = null;
options = {};
}
- if (typeof options == 'number' || $.fx.speeds[options]) {
+ if (typeof options == 'number' || $.fx.speeds[options]) {
callback = speed;
speed = options;
options = {};
}
- if ($.isFunction(speed)) {
+ if ( $.isFunction(speed) ) {
callback = speed;
speed = null;
}
- options = options || {};
-
+ if ( options ) {
+ $.extend( effectObj, options );
+ }
+
speed = speed || options.duration;
- speed = $.fx.off ? 0 : typeof speed == 'number'
+ effectObj.duration = $.fx.off ? 0 : typeof speed == 'number'
? speed : speed in $.fx.speeds ? $.fx.speeds[speed] : $.fx.speeds._default;
- callback = callback || options.complete;
+ effectObj.complete = callback || options.complete;
- return [effect, options, speed, callback];
+ return effectObj;
}
function standardSpeed( speed ) {
@@ -462,29 +466,23 @@ function standardSpeed( speed ) {
$.fn.extend({
effect: function(effect, options, speed, callback) {
var args = _normalizeArguments.apply(this, arguments),
- // TODO: make effects take actual parameters instead of a hash
- args2 = {
- options: args[1],
- duration: args[2],
- callback: args[3]
- },
- mode = args2.options.mode,
- effectMethod = $.effects[effect];
+ mode = args.mode,
+ effectMethod = $.effects[args.effect];
if ( $.fx.off || !effectMethod ) {
// delegate to the original method (e.g., .show()) if possible
if ( mode ) {
- return this[ mode ]( args2.duration, args2.callback );
+ return this[ mode ]( args.duration, args.callback );
} else {
return this.each(function() {
- if ( args2.callback ) {
- args2.callback.call( this );
+ if ( args.callback ) {
+ args.callback.call( this );
}
});
}
}
- return effectMethod.call(this, args2);
+ return effectMethod.call(this, args);
},
_show: $.fn.show,
@@ -493,8 +491,8 @@ $.fn.extend({
return this._show.apply(this, arguments);
} else {
var args = _normalizeArguments.apply(this, arguments);
- args[1].mode = 'show';
- return this.effect.apply(this, args);
+ args.mode = 'show';
+ return this.effect.call(this, args);
}
},
@@ -504,8 +502,8 @@ $.fn.extend({
return this._hide.apply(this, arguments);
} else {
var args = _normalizeArguments.apply(this, arguments);
- args[1].mode = 'hide';
- return this.effect.apply(this, args);
+ args.mode = 'hide';
+ return this.effect.call(this, args);
}
},
@@ -516,8 +514,8 @@ $.fn.extend({
return this.__toggle.apply(this, arguments);
} else {
var args = _normalizeArguments.apply(this, arguments);
- args[1].mode = 'toggle';
- return this.effect.apply(this, args);
+ args.mode = 'toggle';
+ return this.effect.call(this, args);
}
},