Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit d34b88e

Browse files
committed
refactor($animateCss): various improvements
- since transition / animation styles are now set on the element even if the transition property is all, the condition for setting the transitionDuration can be simplified - explain why we test for cubic bezier and ease - rename a parameter
1 parent aed81cb commit d34b88e

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
lines changed

src/ngAnimate/animateCss.js

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,8 +225,8 @@ var CLOSING_TIME_BUFFER = 1.5;
225225
var DETECT_CSS_PROPERTIES = {
226226
transitionDuration: TRANSITION_DURATION_PROP,
227227
transitionDelay: TRANSITION_DELAY_PROP,
228-
transitionProperty: TRANSITION_PROP + PROPERTY_KEY,
229-
transitionTimingFunction: TRANSITION_PROP + TIMING_KEY,
228+
transitionProperty: TRANSITION_PROPERTY_PROP,
229+
transitionTimingFunction: TRANSITION_TIMING_PROP,
230230
animationDuration: ANIMATION_DURATION_PROP,
231231
animationDelay: ANIMATION_DELAY_PROP,
232232
animationIterationCount: ANIMATION_PROP + ANIMATION_ITERATION_COUNT_KEY
@@ -293,13 +293,13 @@ function truthyTimingValue(val) {
293293
return val === 0 || val != null;
294294
}
295295

296-
function getCssTransitionStyle(timings, duration) {
296+
function getCssTransitionStyle(styles, duration) {
297297
var style = TRANSITION_PROP;
298298
var value = duration + 's';
299299

300-
value += ' ' + timings[TRANSITION_TIMING_PROP];
301-
value += ' ' + timings[TRANSITION_PROPERTY_PROP];
302-
value += timings[TRANSITION_DELAY_PROP] ? ' ' + timings[TRANSITION_DELAY_PROP] + 's' : '';
300+
value += ' ' + styles[TRANSITION_TIMING_PROP];
301+
value += ' ' + styles[TRANSITION_PROPERTY_PROP];
302+
value += styles[TRANSITION_DELAY_PROP] ? ' ' + styles[TRANSITION_DELAY_PROP] + 's' : '';
303303

304304
return [style, value];
305305
}
@@ -593,8 +593,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
593593
var flags = {};
594594
flags.hasTransitions = timings.transitionDuration > 0;
595595
flags.hasAnimations = timings.animationDuration > 0;
596-
flags.applyTransitionDuration = options.duration > 0 || hasToStyles && (flags.hasTransitions
597-
|| (flags.hasAnimations && !flags.hasTransitions));
596+
flags.applyTransitionDuration = options.duration > 0 || hasToStyles && flags.hasTransitions;
598597
flags.applyAnimationDuration = options.duration && flags.hasAnimations;
599598
flags.applyTransitionDelay = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions);
600599
flags.applyAnimationDelay = truthyTimingValue(options.delay) && flags.hasAnimations;

test/ngAnimate/animateCssSpec.js

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
describe("ngAnimate $animateCss", function() {
44

5+
// Firefox transforms all transition timing function values to their cubic bezier equivalents
6+
var CUBIC_BEZIER_LINEAR_EQUIVALENT = 'cubic-bezier(0, 0, 1, 1)';
7+
var CUBIC_BEZIER_EASE_EQUIVALENT = 'cubic-bezier(0.25, 0.1, 0.25, 1)';
8+
59
beforeEach(module('ngAnimate'));
610
beforeEach(module('ngAnimateMock'));
711

@@ -710,7 +714,7 @@ describe("ngAnimate $animateCss", function() {
710714
triggerAnimationStartFrame();
711715

712716
// IE reports ease in cubic-bezier form
713-
expect(element.css('transition-timing-function')).toBeOneOf('ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)');
717+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
714718
}));
715719

716720

@@ -2033,7 +2037,7 @@ describe("ngAnimate $animateCss", function() {
20332037

20342038
var style = element.attr('style');
20352039
expect(style).toContain('3000s');
2036-
expect(element.css('transition-timing-function')).toBeOneOf('ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)');
2040+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
20372041
}));
20382042

20392043
it("should be applied to a CSS keyframe animation directly if keyframes are detected within the CSS class",
@@ -2139,7 +2143,7 @@ describe("ngAnimate $animateCss", function() {
21392143
expect(style).toMatch(/animation(?:-duration)?:\s*4s/);
21402144
expect(element.css('transition-duration')).toMatch('4s');
21412145
expect(element.css('transition-property')).toMatch('all');
2142-
expect(element.css('transition-timing-function')).toBeOneOf('linear', 'cubic-bezier(0, 0, 1, 1)');
2146+
expect(element.css('transition-timing-function')).toBeOneOf('linear', CUBIC_BEZIER_LINEAR_EQUIVALENT);
21432147
}));
21442148
});
21452149

@@ -2470,7 +2474,7 @@ describe("ngAnimate $animateCss", function() {
24702474
inject(function($animateCss, $rootElement) {
24712475

24722476
var options = {
2473-
transitionStyle: '5.5s ease-in color',
2477+
transitionStyle: '5.5s ease color',
24742478
duration: 4,
24752479
event: 'enter',
24762480
structural: true
@@ -2483,7 +2487,7 @@ describe("ngAnimate $animateCss", function() {
24832487

24842488
expect(element.css('transition-duration')).toMatch('4s');
24852489
expect(element.css('transition-property')).toMatch('color');
2486-
expect(element.css('transition-timing-function')).toBeOneOf('ease-in', 'cubic-bezier(0.42, 0, 1, 1)');
2490+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
24872491
}));
24882492

24892493
it("should give priority to the provided delay value, but only update the delay style itself",
@@ -2736,7 +2740,7 @@ describe("ngAnimate $animateCss", function() {
27362740

27372741
expect(element.css('transition-duration')).toMatch('2.5s');
27382742
expect(element.css('transition-property')).toMatch('all');
2739-
expect(element.css('transition-timing-function')).toBeOneOf('ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)');
2743+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
27402744
}));
27412745

27422746
it("should remove all inline transition styling when an animation completes",
@@ -2867,7 +2871,7 @@ describe("ngAnimate $animateCss", function() {
28672871
it("should apply a transition duration if the existing transition duration's property value is not 'all'",
28682872
inject(function($animateCss, $rootElement) {
28692873

2870-
ss.addRule('.ng-enter', 'transition: 1s cubic-bezier(0.25, 0.1, 0.25, 1) color');
2874+
ss.addRule('.ng-enter', 'transition: 1s linear color');
28712875

28722876
var emptyObject = {};
28732877
var options = {
@@ -2883,7 +2887,7 @@ describe("ngAnimate $animateCss", function() {
28832887

28842888
expect(element.css('transition-duration')).toMatch('1s');
28852889
expect(element.css('transition-property')).toMatch('color');
2886-
expect(element.css('transition-timing-function')).toBe('cubic-bezier(0.25, 0.1, 0.25, 1)');
2890+
expect(element.css('transition-timing-function')).toBeOneOf('linear', CUBIC_BEZIER_LINEAR_EQUIVALENT);
28872891
}));
28882892

28892893
it("should apply a transition duration and an animation duration if duration + styles options are provided for a matching keyframe animation",

0 commit comments

Comments
 (0)