From 347f86d99a0b2e4052819a660a99ade14bd0f17e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Scott=20Gonz=C3=A1lez?= Date: Wed, 10 Jun 2009 01:22:38 +0000 Subject: [PATCH] Effects core: Refactored show/hide/toggle methods. --- ui/effects.core.js | 58 ++++++++++++++++++++++++++++++---------------- 1 file changed, 38 insertions(+), 20 deletions(-) diff --git a/ui/effects.core.js b/ui/effects.core.js index e4f3dc118..8509d300e 100644 --- a/ui/effects.core.js +++ b/ui/effects.core.js @@ -131,15 +131,28 @@ $.effects = { }; -function _normalizeArguments(a, m) { +function _normalizeArguments(effect, options, speed, callback) { + // shift params for method overloading + if ($.isFunction(options)) { + callback = options; + speed = null; + options = {}; + } + if (typeof options == 'number') { + callback = speed; + speed = options; + options = {}; + } + + options = options || {}; - var o = a[1] && a[1].constructor == Object ? a[1] : {}; if(m) o.mode = m; - var speed = a[1] && a[1].constructor != Object ? a[1] : (o.duration ? o.duration : a[2]); //either comes from options.duration or the secon/third argument - speed = $.fx.off ? 0 : typeof speed === "number" ? speed : $.fx.speeds[speed] || $.fx.speeds._default; - var callback = o.callback || ( $.isFunction(a[1]) && a[1] ) || ( $.isFunction(a[2]) && a[2] ) || ( $.isFunction(a[3]) && a[3] ); + speed = speed || options.duration; + speed = $.fx.off ? 0 : typeof speed == 'number' + ? speed : $.fx.speeds[speed] || $.fx.speeds._default; - return [a[0], o, speed, callback]; - + callback = callback || options.callback; + + return [effect, options, speed, callback]; } //Extend the methods of jQuery @@ -158,29 +171,34 @@ $.fn.extend({ return $.effects[fx] ? $.effects[fx].call(this, {method: fx, options: options || {}, duration: speed, callback: callback }) : null; }, - show: function() { - if(!arguments[0] || (arguments[0].constructor == Number || (/(slow|normal|fast)/).test(arguments[0]))) + show: function(speed) { + if (!speed || typeof speed == 'number' || $.fx.speeds[speed]) { return this._show.apply(this, arguments); - else { - return this.effect.apply(this, _normalizeArguments(arguments, 'show')); + } else { + var args = _normalizeArguments.apply(this, arguments); + args[1].mode = 'show'; + return this.effect.apply(this, args); } }, - hide: function() { - if(!arguments[0] || (arguments[0].constructor == Number || (/(slow|normal|fast)/).test(arguments[0]))) + hide: function(speed) { + if (!speed || typeof speed == 'number' || $.fx.speeds[speed]) { return this._hide.apply(this, arguments); - else { - return this.effect.apply(this, _normalizeArguments(arguments, 'hide')); + } else { + var args = _normalizeArguments.apply(this, arguments); + args[1].mode = 'hide'; + return this.effect.apply(this, args); } }, - toggle: function(){ - if(!arguments[0] || - (arguments[0].constructor == Number || (/(slow|normal|fast)/).test(arguments[0])) || - ($.isFunction(arguments[0]) || typeof arguments[0] == 'boolean')) { + toggle: function(speed) { + if (!speed || typeof speed == 'number' || $.fx.speeds[speed] || + typeof speed == 'boolean' || $.isFunction(speed)) { return this.__toggle.apply(this, arguments); } else { - return this.effect.apply(this, _normalizeArguments(arguments, 'toggle')); + var args = _normalizeArguments.apply(this, arguments); + args[1].mode = 'toggle'; + return this.effect.apply(this, args); } }, -- 2.39.5