Skip to content

Commit 6f29577

Browse files
committed
Effects: Handle the .hide/show/toggle( options ) signatures from core properly. Fixes #9126 - .show()/.hide() do not support all of core's options.
1 parent 0cf875e commit 6f29577

File tree

3 files changed

+73
-36
lines changed

3 files changed

+73
-36
lines changed

tests/unit/effects/effects.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ <h2 id="qunit-banner"></h2>
9696
<h2 id="qunit-userAgent"></h2>
9797
<ol id="qunit-tests"></ol>
9898
<div id="qunit-fixture">
99+
<div id="elem" class="test">
100+
</div>
99101
<div class="hidden test">
100102
<div>.</div>
101103
</div>

tests/unit/effects/effects_core.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,24 @@ var minDuration = 15,
1616

1717
module( "effects.core" );
1818

19+
// TODO: test all signatures of .show(), .hide(), .toggle().
20+
// Look at core's signatures and UI's signatures.
21+
asyncTest( ".hide() with step", function() {
22+
expect( 1 );
23+
var element = $( "#elem" ),
24+
step = function() {
25+
ok( true, "step callback invoked" );
26+
step = $.noop;
27+
};
28+
29+
element.hide({
30+
step: function() {
31+
step();
32+
},
33+
complete: start
34+
});
35+
});
36+
1937
test( "Immediate Return Conditions", function() {
2038
var hidden = $( "div.hidden" ),
2139
count = 0;

ui/jquery.ui.effect.js

Lines changed: 53 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1106,14 +1106,29 @@ function _normalizeArguments( effect, options, speed, callback ) {
11061106
return effect;
11071107
}
11081108

1109-
function standardSpeed( speed ) {
1110-
// valid standard speeds
1111-
if ( !speed || typeof speed === "number" || $.fx.speeds[ speed ] ) {
1109+
function standardAnimationOption( option ) {
1110+
// Valid standard speeds (nothing, number, named speed)
1111+
if ( !option || typeof option === "number" || $.fx.speeds[ option ] ) {
11121112
return true;
11131113
}
11141114

1115-
// invalid strings - treat as "normal" speed
1116-
return typeof speed === "string" && !$.effects.effect[ speed ];
1115+
// Invalid strings - treat as "normal" speed
1116+
if ( typeof option === "string" && !$.effects.effect[ option ] ) {
1117+
return true;
1118+
}
1119+
1120+
// Complete callback
1121+
if ( $.isFunction( option ) ) {
1122+
return true;
1123+
}
1124+
1125+
// Options hash (but not naming an effect)
1126+
if ( typeof option === "object" && !option.effect ) {
1127+
return true;
1128+
}
1129+
1130+
// Didn't match any standard API
1131+
return false;
11171132
}
11181133

11191134
$.fn.extend({
@@ -1163,39 +1178,41 @@ $.fn.extend({
11631178
return queue === false ? this.each( run ) : this.queue( queue || "fx", run );
11641179
},
11651180

1166-
_show: $.fn.show,
1167-
show: function( speed ) {
1168-
if ( standardSpeed( speed ) ) {
1169-
return this._show.apply( this, arguments );
1170-
} else {
1171-
var args = _normalizeArguments.apply( this, arguments );
1172-
args.mode = "show";
1173-
return this.effect.call( this, args );
1174-
}
1175-
},
1181+
show: (function( orig ) {
1182+
return function( option ) {
1183+
if ( standardAnimationOption( option ) ) {
1184+
return orig.apply( this, arguments );
1185+
} else {
1186+
var args = _normalizeArguments.apply( this, arguments );
1187+
args.mode = "show";
1188+
return this.effect.call( this, args );
1189+
}
1190+
};
1191+
})( $.fn.show ),
11761192

1177-
_hide: $.fn.hide,
1178-
hide: function( speed ) {
1179-
if ( standardSpeed( speed ) ) {
1180-
return this._hide.apply( this, arguments );
1181-
} else {
1182-
var args = _normalizeArguments.apply( this, arguments );
1183-
args.mode = "hide";
1184-
return this.effect.call( this, args );
1185-
}
1186-
},
1193+
hide: (function( orig ) {
1194+
return function( option ) {
1195+
if ( standardAnimationOption( option ) ) {
1196+
return orig.apply( this, arguments );
1197+
} else {
1198+
var args = _normalizeArguments.apply( this, arguments );
1199+
args.mode = "hide";
1200+
return this.effect.call( this, args );
1201+
}
1202+
};
1203+
})( $.fn.hide ),
11871204

1188-
// jQuery core overloads toggle and creates _toggle
1189-
__toggle: $.fn.toggle,
1190-
toggle: function( speed ) {
1191-
if ( standardSpeed( speed ) || typeof speed === "boolean" || $.isFunction( speed ) ) {
1192-
return this.__toggle.apply( this, arguments );
1193-
} else {
1194-
var args = _normalizeArguments.apply( this, arguments );
1195-
args.mode = "toggle";
1196-
return this.effect.call( this, args );
1197-
}
1198-
},
1205+
toggle: (function( orig ) {
1206+
return function( option ) {
1207+
if ( standardAnimationOption( option ) || typeof option === "boolean" ) {
1208+
return orig.apply( this, arguments );
1209+
} else {
1210+
var args = _normalizeArguments.apply( this, arguments );
1211+
args.mode = "toggle";
1212+
return this.effect.call( this, args );
1213+
}
1214+
};
1215+
})( $.fn.toggle ),
11991216

12001217
// helper functions
12011218
cssUnit: function(key) {

0 commit comments

Comments
 (0)