Permalink
Browse files

Effects: set default easing using jQuery.easing._default

Fixes gh-2219
Close gh-2218
  • Loading branch information...
timmywil committed May 5, 2015
1 parent 436f0ae commit 5f2ea402582c7b8f4773771e1529d60587f3435e
Showing with 42 additions and 18 deletions.
  1. +4 −1 src/effects.js
  2. +3 −2 src/effects/Tween.js
  3. +35 −15 test/unit/effects.js
View
@@ -289,7 +289,10 @@ function Animation( elem, properties, options ) {
animation = deferred.promise({
elem: elem,
props: jQuery.extend( {}, properties ),
- opts: jQuery.extend( true, { specialEasing: {} }, options ),
+ opts: jQuery.extend( true, {
+ specialEasing: {},
+ easing: jQuery.easing._default
+ }, options ),
originalProperties: properties,
originalOptions: options,
startTime: fxNow || createFxNow(),
View
@@ -13,7 +13,7 @@ Tween.prototype = {
init: function( elem, options, prop, end, easing, unit ) {
this.elem = elem;
this.prop = prop;
- this.easing = easing || "swing";
+ this.easing = easing || jQuery.easing._default;
this.options = options;
this.start = this.now = this.cur();
this.end = end;
@@ -105,7 +105,8 @@ jQuery.easing = {
},
swing: function( p ) {
return 0.5 - Math.cos( p * Math.PI ) / 2;
- }
+ },
+ _default: "swing"
};
jQuery.fx = Tween.prototype.init;
View
@@ -1178,45 +1178,45 @@ test("animate with per-property easing", function(){
test("animate with CSS shorthand properties", function(){
expect(11);
- var _default_count = 0,
- _special_count = 0,
+ var easeAnimation_count = 0,
+ easeProperty_count = 0,
propsBasic = { "padding": "10 20 30" },
- propsSpecial = { "padding": [ "1 2 3", "_special" ] };
+ propsSpecial = { "padding": [ "1 2 3", "propertyScope" ] };
- jQuery.easing._default = function(p) {
+ jQuery.easing.animationScope = function(p) {
if ( p >= 1 ) {
- _default_count++;
+ easeAnimation_count++;
}
return p;
};
- jQuery.easing._special = function(p) {
+ jQuery.easing.propertyScope = function(p) {
if ( p >= 1 ) {
- _special_count++;
+ easeProperty_count++;
}
return p;
};
jQuery("#foo")
- .animate( propsBasic, 200, "_default", function() {
+ .animate( propsBasic, 200, "animationScope", function() {
equal( this.style.paddingTop, "10px", "padding-top was animated" );
equal( this.style.paddingLeft, "20px", "padding-left was animated" );
equal( this.style.paddingRight, "20px", "padding-right was animated" );
equal( this.style.paddingBottom, "30px", "padding-bottom was animated" );
- equal( _default_count, 4, "per-animation default easing called for each property" );
- _default_count = 0;
+ equal( easeAnimation_count, 4, "per-animation default easing called for each property" );
+ easeAnimation_count = 0;
})
- .animate( propsSpecial, 200, "_default", function() {
+ .animate( propsSpecial, 200, "animationScope", function() {
equal( this.style.paddingTop, "1px", "padding-top was animated again" );
equal( this.style.paddingLeft, "2px", "padding-left was animated again" );
equal( this.style.paddingRight, "2px", "padding-right was animated again" );
equal( this.style.paddingBottom, "3px", "padding-bottom was animated again" );
- equal( _default_count, 0, "per-animation default easing not called" );
- equal( _special_count, 4, "special easing called for each property" );
+ equal( easeAnimation_count, 0, "per-animation default easing not called" );
+ equal( easeProperty_count, 4, "special easing called for each property" );
jQuery(this).css("padding", "0");
- delete jQuery.easing._default;
- delete jQuery.easing._special;
+ delete jQuery.easing.animationScope;
+ delete jQuery.easing.propertyScope;
});
this.clock.tick( 400 );
});
@@ -2212,5 +2212,25 @@ test( "Animation should go to its end state if document.hidden = true", 1, funct
}
});
+test( "jQuery.easing._default (#2218)", 2, function() {
+ jQuery( "#foo" )
+ .animate({ width: "5px" }, {
+ duration: 5,
+ start: function( anim ) {
+ equal( anim.opts.easing, jQuery.easing._default,
+ "anim.opts.easing should be equal to jQuery.easing._default when the easing argument is not given" );
+ }
+ })
+ .animate({ height: "5px" }, {
+ duration: 5,
+ easing: "linear",
+ start: function( anim ) {
+ equal( anim.opts.easing, "linear",
+ "anim.opts.easing should be equal to the easing argument" );
+ }
+ })
+ .stop();
+ this.clock.tick( 25 );
+});
})();

8 comments on commit 5f2ea40

@mr21

This comment has been minimized.

Show comment
Hide comment
@mr21

mr21 May 5, 2015

Contributor

Hi @timmywil, why my commit does not appears (in the commits list) like the others?

Contributor

mr21 replied May 5, 2015

Hi @timmywil, why my commit does not appears (in the commits list) like the others?

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 5, 2015

Member

Hey @mr21, I do apologize. We've had this mistake happen before, but this time was my fault. I should have set author when squashing the commits.

Member

timmywil replied May 5, 2015

Hey @mr21, I do apologize. We've had this mistake happen before, but this time was my fault. I should have set author when squashing the commits.

@mgol

This comment has been minimized.

Show comment
Hide comment
@mgol

mgol May 5, 2015

Member

@timmywil Do you download patches? I have this in my ~/.gitconfig:

[alias]
    pr = "!f() { git fetch -f origin refs/pull/$1/head:pr/$1; } ; f"

and then if I invoke:

git pr 42

then PR 42 to the origin remote (here the jquery/jquery repo) gets checked out to the pr/42 branch with all commits as in the branch with correct author etc. I don't need to remember then to correct the author because it's already set as it should when squashing.

Member

mgol replied May 5, 2015

@timmywil Do you download patches? I have this in my ~/.gitconfig:

[alias]
    pr = "!f() { git fetch -f origin refs/pull/$1/head:pr/$1; } ; f"

and then if I invoke:

git pr 42

then PR 42 to the origin remote (here the jquery/jquery repo) gets checked out to the pr/42 branch with all commits as in the branch with correct author etc. I don't need to remember then to correct the author because it's already set as it should when squashing.

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 5, 2015

Member

@mzgol I do actually use that same alias (except for upstream, of course). A merge --ff-only will preserve the author (which I will do if there was already only one commit), but a merge --squash will not because it is you authoring the squash commit.

Member

timmywil replied May 5, 2015

@mzgol I do actually use that same alias (except for upstream, of course). A merge --ff-only will preserve the author (which I will do if there was already only one commit), but a merge --squash will not because it is you authoring the squash commit.

@mgol

This comment has been minimized.

Show comment
Hide comment
@mgol

mgol May 5, 2015

Member
Member

mgol replied May 5, 2015

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 5, 2015

Member

Yea, I never thought about rebase -i. I'm going to do that from now on.

Member

timmywil replied May 5, 2015

Yea, I never thought about rebase -i. I'm going to do that from now on.

@mr21

This comment has been minimized.

Show comment
Hide comment
@mr21

mr21 May 5, 2015

Contributor

@timmywil, I though it was possible to edit it with amend or something.
Nevermind, I forgive you ^^

Contributor

mr21 replied May 5, 2015

@timmywil, I though it was possible to edit it with amend or something.
Nevermind, I forgive you ^^

@timmywil

This comment has been minimized.

Show comment
Hide comment
@timmywil

timmywil May 5, 2015

Member

@mr21 It is, but we'd have to force push. Unfortunately, it's too late now. I'm sorry again. I'm a jackass.

Member

timmywil replied May 5, 2015

@mr21 It is, but we'd have to force push. Unfortunately, it's too late now. I'm sorry again. I'm a jackass.

Please sign in to comment.