Effects: Handle the .hide/show/toggle( options ) signatures from core properly. Fixes #9126 - .show()/.hide() do not support all of core's options.

This commit is contained in:
Scott González 2013-02-28 13:34:49 -05:00
parent 0cf875e5e3
commit 6f29577436
3 changed files with 73 additions and 36 deletions

View File

@ -96,6 +96,8 @@
<h2 id="qunit-userAgent"></h2> <h2 id="qunit-userAgent"></h2>
<ol id="qunit-tests"></ol> <ol id="qunit-tests"></ol>
<div id="qunit-fixture"> <div id="qunit-fixture">
<div id="elem" class="test">
</div>
<div class="hidden test"> <div class="hidden test">
<div>.</div> <div>.</div>
</div> </div>

View File

@ -16,6 +16,24 @@ var minDuration = 15,
module( "effects.core" ); module( "effects.core" );
// TODO: test all signatures of .show(), .hide(), .toggle().
// Look at core's signatures and UI's signatures.
asyncTest( ".hide() with step", function() {
expect( 1 );
var element = $( "#elem" ),
step = function() {
ok( true, "step callback invoked" );
step = $.noop;
};
element.hide({
step: function() {
step();
},
complete: start
});
});
test( "Immediate Return Conditions", function() { test( "Immediate Return Conditions", function() {
var hidden = $( "div.hidden" ), var hidden = $( "div.hidden" ),
count = 0; count = 0;

View File

@ -1106,14 +1106,29 @@ function _normalizeArguments( effect, options, speed, callback ) {
return effect; return effect;
} }
function standardSpeed( speed ) { function standardAnimationOption( option ) {
// valid standard speeds // Valid standard speeds (nothing, number, named speed)
if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) { if ( !option || typeof option === "number" || $.fx.speeds[ option ] ) {
return true; return true;
} }
// invalid strings - treat as "normal" speed // Invalid strings - treat as "normal" speed
return typeof speed === "string" && !$.effects.effect[ speed ]; if ( typeof option === "string" && !$.effects.effect[ option ] ) {
return true;
}
// Complete callback
if ( $.isFunction( option ) ) {
return true;
}
// Options hash (but not naming an effect)
if ( typeof option === "object" && !option.effect ) {
return true;
}
// Didn't match any standard API
return false;
} }
$.fn.extend({ $.fn.extend({
@ -1163,39 +1178,41 @@ $.fn.extend({
return queue === false ? this.each( run ) : this.queue( queue || "fx", run ); return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
}, },
_show: $.fn.show, show: (function( orig ) {
show: function( speed ) { return function( option ) {
if ( standardSpeed( speed ) ) { if ( standardAnimationOption( option ) ) {
return this._show.apply( this, arguments ); return orig.apply( this, arguments );
} else { } else {
var args = _normalizeArguments.apply( this, arguments ); var args = _normalizeArguments.apply( this, arguments );
args.mode = "show"; args.mode = "show";
return this.effect.call( this, args ); return this.effect.call( this, args );
} }
}, };
})( $.fn.show ),
_hide: $.fn.hide, hide: (function( orig ) {
hide: function( speed ) { return function( option ) {
if ( standardSpeed( speed ) ) { if ( standardAnimationOption( option ) ) {
return this._hide.apply( this, arguments ); return orig.apply( this, arguments );
} else { } else {
var args = _normalizeArguments.apply( this, arguments ); var args = _normalizeArguments.apply( this, arguments );
args.mode = "hide"; args.mode = "hide";
return this.effect.call( this, args ); return this.effect.call( this, args );
} }
}, };
})( $.fn.hide ),
// jQuery core overloads toggle and creates _toggle toggle: (function( orig ) {
__toggle: $.fn.toggle, return function( option ) {
toggle: function( speed ) { if ( standardAnimationOption( option ) || typeof option === "boolean" ) {
if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) { return orig.apply( this, arguments );
return this.__toggle.apply( this, arguments );
} else { } else {
var args = _normalizeArguments.apply( this, arguments ); var args = _normalizeArguments.apply( this, arguments );
args.mode = "toggle"; args.mode = "toggle";
return this.effect.call( this, args ); return this.effect.call( this, args );
} }
}, };
})( $.fn.toggle ),
// helper functions // helper functions
cssUnit: function(key) { cssUnit: function(key) {