Skip to content

Commit 5b489de

Browse files
committed
Added full support for easing in all shorthand effects methods (hide, show, toggle, fadeTo, slideUp, etc.).
Previously, these methods could only be used with two of the three (speed, easing, callback) arguments, or, in the case of fadeTo, 3 of the 4 (speed, opacity, easing, callback) arguments. Added three more sets of tests to the series of "Chain" tests. Fixes #7014
1 parent bca5765 commit 5b489de

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

src/effects.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@ var elemdisplay = {},
1414
];
1515

1616
jQuery.fn.extend({
17-
show: function( speed, callback ) {
17+
show: function( speed, easing, callback ) {
1818
if ( speed || speed === 0) {
19-
return this.animate( genFx("show", 3), speed, callback);
19+
return this.animate( genFx("show", 3), speed, easing, callback);
2020

2121
} else {
2222
for ( var i = 0, l = this.length; i < l; i++ ) {
@@ -58,9 +58,9 @@ jQuery.fn.extend({
5858
}
5959
},
6060

61-
hide: function( speed, callback ) {
61+
hide: function( speed, easing, callback ) {
6262
if ( speed || speed === 0 ) {
63-
return this.animate( genFx("hide", 3), speed, callback);
63+
return this.animate( genFx("hide", 3), speed, easing, callback);
6464

6565
} else {
6666
for ( var i = 0, l = this.length; i < l; i++ ) {
@@ -83,7 +83,7 @@ jQuery.fn.extend({
8383
// Save the old toggle function
8484
_toggle: jQuery.fn.toggle,
8585

86-
toggle: function( fn, fn2 ) {
86+
toggle: function( fn, fn2, callback ) {
8787
var bool = typeof fn === "boolean";
8888

8989
if ( jQuery.isFunction(fn) && jQuery.isFunction(fn2) ) {
@@ -96,15 +96,15 @@ jQuery.fn.extend({
9696
});
9797

9898
} else {
99-
this.animate(genFx("toggle", 3), fn, fn2);
99+
this.animate(genFx("toggle", 3), fn, fn2, callback);
100100
}
101101

102102
return this;
103103
},
104104

105-
fadeTo: function( speed, to, callback ) {
105+
fadeTo: function( speed, to, easing, callback ) {
106106
return this.filter(":hidden").css("opacity", 0).show().end()
107-
.animate({opacity: to}, speed, callback);
107+
.animate({opacity: to}, speed, easing, callback);
108108
},
109109

110110
animate: function( prop, speed, easing, callback ) {
@@ -241,8 +241,8 @@ jQuery.each({
241241
fadeIn: { opacity: "show" },
242242
fadeOut: { opacity: "hide" }
243243
}, function( name, props ) {
244-
jQuery.fn[ name ] = function( speed, callback ) {
245-
return this.animate( props, speed, callback );
244+
jQuery.fn[ name ] = function( speed, easing, callback ) {
245+
return this.animate( props, speed, easing, callback );
246246
};
247247
});
248248

test/index.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,8 @@ <h2 id="qunit-userAgent"></h2>
245245

246246
<div id="slidetogglein" class='chain test'>slideToggleIn<div>slideToggleIn</div></div>
247247
<div id="slidetoggleout" class='chain test out'>slideToggleOut<div>slideToggleOut</div></div>
248+
249+
<div id="fadeto" class='chain test'>fadeTo<div>fadeTo</div></div>
248250
</div>
249251

250252
<div id="fx-tests"></div>

test/unit/effects.js

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,20 +560,28 @@ test("Chain hide show", function() {
560560
test("Chain show hide", function() {
561561
jQuery('#hide div').saveState().show('fast').hide('fast',jQuery.checkState);
562562
});
563+
test("Chain show hide with easing and callback", function() {
564+
jQuery('#hide div').saveState().show('fast').hide('fast','linear',jQuery.checkState);
565+
});
563566

564567
test("Chain toggle in", function() {
565568
jQuery('#togglein div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
566569
});
567570
test("Chain toggle out", function() {
568571
jQuery('#toggleout div').saveState().toggle('fast').toggle('fast',jQuery.checkState);
569572
});
570-
573+
test("Chain toggle out with easing and callback", function() {
574+
jQuery('#toggleout div').saveState().toggle('fast').toggle('fast','linear',jQuery.checkState);
575+
});
571576
test("Chain slideDown slideUp", function() {
572577
jQuery('#slidedown div').saveState().slideDown('fast').slideUp('fast',jQuery.checkState);
573578
});
574579
test("Chain slideUp slideDown", function() {
575580
jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast',jQuery.checkState);
576581
});
582+
test("Chain slideUp slideDown with easing and callback", function() {
583+
jQuery('#slideup div').saveState().slideUp('fast').slideDown('fast','linear',jQuery.checkState);
584+
});
577585

578586
test("Chain slideToggle in", function() {
579587
jQuery('#slidetogglein div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
@@ -582,6 +590,10 @@ test("Chain slideToggle out", function() {
582590
jQuery('#slidetoggleout div').saveState().slideToggle('fast').slideToggle('fast',jQuery.checkState);
583591
});
584592

593+
test("Chain fadeTo 0.5 1.0 with easing and callback)", function() {
594+
jQuery('#fadeto div').saveState().fadeTo('fast',0.5).fadeTo('fast',1.0,'linear',jQuery.checkState);
595+
});
596+
585597
jQuery.makeTest = function( text ){
586598
var elem = jQuery("<div></div>")
587599
.attr("id", "test" + jQuery.makeTest.id++)

0 commit comments

Comments
 (0)