Skip to content

Commit b7f9e62

Browse files
committed
Effects: set default easing using jQuery.easing._default
Fixes gh-2219 Close gh-2218
1 parent d693391 commit b7f9e62

File tree

3 files changed

+42
-18
lines changed

3 files changed

+42
-18
lines changed

src/effects.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,10 @@ function Animation( elem, properties, options ) {
286286
animation = deferred.promise({
287287
elem: elem,
288288
props: jQuery.extend( {}, properties ),
289-
opts: jQuery.extend( true, { specialEasing: {} }, options ),
289+
opts: jQuery.extend( true, {
290+
specialEasing: {},
291+
easing: jQuery.easing._default
292+
}, options ),
290293
originalProperties: properties,
291294
originalOptions: options,
292295
startTime: fxNow || createFxNow(),

src/effects/Tween.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Tween.prototype = {
1313
init: function( elem, options, prop, end, easing, unit ) {
1414
this.elem = elem;
1515
this.prop = prop;
16-
this.easing = easing || "swing";
16+
this.easing = easing || jQuery.easing._default;
1717
this.options = options;
1818
this.start = this.now = this.cur();
1919
this.end = end;
@@ -105,7 +105,8 @@ jQuery.easing = {
105105
},
106106
swing: function( p ) {
107107
return 0.5 - Math.cos( p * Math.PI ) / 2;
108-
}
108+
},
109+
_default: "swing"
109110
};
110111

111112
jQuery.fx = Tween.prototype.init;

test/unit/effects.js

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1191,45 +1191,45 @@ test("animate with per-property easing", function(){
11911191
test("animate with CSS shorthand properties", function(){
11921192
expect(11);
11931193

1194-
var _default_count = 0,
1195-
_special_count = 0,
1194+
var easeAnimation_count = 0,
1195+
easeProperty_count = 0,
11961196
propsBasic = { "padding": "10 20 30" },
1197-
propsSpecial = { "padding": [ "1 2 3", "_special" ] };
1197+
propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] };
11981198

1199-
jQuery.easing._default = function(p) {
1199+
jQuery.easing.animationScope = function(p) {
12001200
if ( p >= 1 ) {
1201-
_default_count++;
1201+
easeAnimation_count++;
12021202
}
12031203
return p;
12041204
};
12051205

1206-
jQuery.easing._special = function(p) {
1206+
jQuery.easing.propertyScope = function(p) {
12071207
if ( p >= 1 ) {
1208-
_special_count++;
1208+
easeProperty_count++;
12091209
}
12101210
return p;
12111211
};
12121212

12131213
jQuery("#foo")
1214-
.animate( propsBasic, 200, "_default", function() {
1214+
.animate( propsBasic, 200, "animationScope", function() {
12151215
equal( this.style.paddingTop, "10px", "padding-top was animated" );
12161216
equal( this.style.paddingLeft, "20px", "padding-left was animated" );
12171217
equal( this.style.paddingRight, "20px", "padding-right was animated" );
12181218
equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
1219-
equal( _default_count, 4, "per-animation default easing called for each property" );
1220-
_default_count = 0;
1219+
equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
1220+
easeAnimation_count = 0;
12211221
})
1222-
.animate( propsSpecial, 200, "_default", function() {
1222+
.animate( propsSpecial, 200, "animationScope", function() {
12231223
equal( this.style.paddingTop, "1px", "padding-top was animated again" );
12241224
equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
12251225
equal( this.style.paddingRight, "2px", "padding-right was animated again" );
12261226
equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
1227-
equal( _default_count, 0, "per-animation default easing not called" );
1228-
equal( _special_count, 4, "special easing called for each property" );
1227+
equal( easeAnimation_count, 0, "per-animation default easing not called" );
1228+
equal( easeProperty_count, 4, "special easing called for each property" );
12291229

12301230
jQuery(this).css("padding", "0");
1231-
delete jQuery.easing._default;
1232-
delete jQuery.easing._special;
1231+
delete jQuery.easing.animationScope;
1232+
delete jQuery.easing.propertyScope;
12331233
});
12341234
this.clock.tick( 400 );
12351235
});
@@ -2227,5 +2227,25 @@ test( "Animation should go to its end state if document.hidden = true", 1, funct
22272227
}
22282228
});
22292229

2230+
test( "jQuery.easing._default (#2218)", 2, function() {
2231+
jQuery( "#foo" )
2232+
.animate({ width: "5px" }, {
2233+
duration: 5,
2234+
start: function( anim ) {
2235+
equal( anim.opts.easing, jQuery.easing._default,
2236+
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
2237+
}
2238+
})
2239+
.animate({ height: "5px" }, {
2240+
duration: 5,
2241+
easing: "linear",
2242+
start: function( anim ) {
2243+
equal( anim.opts.easing, "linear",
2244+
"anim.opts.easing should be equal to the easing argument" );
2245+
}
2246+
})
2247+
.stop();
2248+
this.clock.tick( 25 );
2249+
});
22302250

22312251
})();

0 commit comments

Comments
 (0)