Skip to content

Commit

Permalink
Added support for slideToggle to take an optional state parameter
Browse files Browse the repository at this point in the history
By adding the state parameter, slideToggle can now be called in
the following ways:

    slideToggle();
    slideToggle(speed);
    slideToggle(state);
    slideToggle(callback);
    slideToggle(speed,callback);
    slideToggle(state,callback);
    slideToggle(speed,state,callback);

If `state` is `true` then `slideDown` is called.
If `state` is `false` then `slideUp` is called.
If `state` is not a boolean, then the original `slideToggle`
is called. (It was moved to `_slideToggle`)
  • Loading branch information
Doug Neiner authored and Doug Neiner committed Mar 7, 2010
1 parent 0a307b3 commit bfbb04c
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion src/effects.js
Expand Up @@ -235,7 +235,7 @@ function genFx( type, num ) {
jQuery.each({
slideDown: genFx("show", 1),
slideUp: genFx("hide", 1),
slideToggle: genFx("toggle", 1),
'_slideToggle': genFx("toggle", 1),
fadeIn: { opacity: "show" },
fadeOut: { opacity: "hide" }
}, function( name, props ) {
Expand All @@ -244,6 +244,23 @@ jQuery.each({
};
});

jQuery.fn.slideToggle = function( speed, state, callback ) {
if( typeof speed === "boolean" ){
callback = state;
state = speed;
speed = undefined;
}
if( jQuery.isFunction(state) ){
callback = state;
state = undefined;
}
if( typeof state === "boolean" ){
return this[ state ? "slideDown" : "slideUp"](speed, callback);
} else {
return this._slideToggle( speed, callback );
}
};

jQuery.extend({
speed: function( speed, easing, fn ) {
var opt = speed && typeof speed === "object" ? speed : {
Expand Down

0 comments on commit bfbb04c

Please sign in to comment.