Skip to content

Commit 5f2ea40

Browse files
committed
Effects: set default easing using jQuery.easing._default
Fixes gh-2219 Close gh-2218
1 parent 436f0ae commit 5f2ea40

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
@@ -289,7 +289,10 @@ function Animation( elem, properties, options ) {
289289
animation = deferred.promise({
290290
elem: elem,
291291
props: jQuery.extend( {}, properties ),
292-
opts: jQuery.extend( true, { specialEasing: {} }, options ),
292+
opts: jQuery.extend( true, {
293+
specialEasing: {},
294+
easing: jQuery.easing._default
295+
}, options ),
293296
originalProperties: properties,
294297
originalOptions: options,
295298
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
@@ -1178,45 +1178,45 @@ test("animate with per-property easing", function(){
11781178
test("animate with CSS shorthand properties", function(){
11791179
expect(11);
11801180

1181-
var _default_count = 0,
1182-
_special_count = 0,
1181+
var easeAnimation_count = 0,
1182+
easeProperty_count = 0,
11831183
propsBasic = { "padding": "10 20 30" },
1184-
propsSpecial = { "padding": [ "1 2 3", "_special" ] };
1184+
propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] };
11851185

1186-
jQuery.easing._default = function(p) {
1186+
jQuery.easing.animationScope = function(p) {
11871187
if ( p >= 1 ) {
1188-
_default_count++;
1188+
easeAnimation_count++;
11891189
}
11901190
return p;
11911191
};
11921192

1193-
jQuery.easing._special = function(p) {
1193+
jQuery.easing.propertyScope = function(p) {
11941194
if ( p >= 1 ) {
1195-
_special_count++;
1195+
easeProperty_count++;
11961196
}
11971197
return p;
11981198
};
11991199

12001200
jQuery("#foo")
1201-
.animate( propsBasic, 200, "_default", function() {
1201+
.animate( propsBasic, 200, "animationScope", function() {
12021202
equal( this.style.paddingTop, "10px", "padding-top was animated" );
12031203
equal( this.style.paddingLeft, "20px", "padding-left was animated" );
12041204
equal( this.style.paddingRight, "20px", "padding-right was animated" );
12051205
equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
1206-
equal( _default_count, 4, "per-animation default easing called for each property" );
1207-
_default_count = 0;
1206+
equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
1207+
easeAnimation_count = 0;
12081208
})
1209-
.animate( propsSpecial, 200, "_default", function() {
1209+
.animate( propsSpecial, 200, "animationScope", function() {
12101210
equal( this.style.paddingTop, "1px", "padding-top was animated again" );
12111211
equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
12121212
equal( this.style.paddingRight, "2px", "padding-right was animated again" );
12131213
equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
1214-
equal( _default_count, 0, "per-animation default easing not called" );
1215-
equal( _special_count, 4, "special easing called for each property" );
1214+
equal( easeAnimation_count, 0, "per-animation default easing not called" );
1215+
equal( easeProperty_count, 4, "special easing called for each property" );
12161216

12171217
jQuery(this).css("padding", "0");
1218-
delete jQuery.easing._default;
1219-
delete jQuery.easing._special;
1218+
delete jQuery.easing.animationScope;
1219+
delete jQuery.easing.propertyScope;
12201220
});
12211221
this.clock.tick( 400 );
12221222
});
@@ -2212,5 +2212,25 @@ test( "Animation should go to its end state if document.hidden = true", 1, funct
22122212
}
22132213
});
22142214

2215+
test( "jQuery.easing._default (#2218)", 2, function() {
2216+
jQuery( "#foo" )
2217+
.animate({ width: "5px" }, {
2218+
duration: 5,
2219+
start: function( anim ) {
2220+
equal( anim.opts.easing, jQuery.easing._default,
2221+
"anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
2222+
}
2223+
})
2224+
.animate({ height: "5px" }, {
2225+
duration: 5,
2226+
easing: "linear",
2227+
start: function( anim ) {
2228+
equal( anim.opts.easing, "linear",
2229+
"anim.opts.easing should be equal to the easing argument" );
2230+
}
2231+
})
2232+
.stop();
2233+
this.clock.tick( 25 );
2234+
});
22152235

22162236
})();

0 commit comments

Comments
 (0)