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

Commit d3b7424

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 d3b7424

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

src/ngAnimate/animateCss.js

+7-8
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

+8-5
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

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

5+
// IE sets a transition timing function value of "ease" as its cubic bezier equivalent
6+
var CUBIC_BEZIER_EASE_EQUIVALENT = 'cubic-bezier(0.25, 0.1, 0.25, 1)';
7+
58
beforeEach(module('ngAnimate'));
69
beforeEach(module('ngAnimateMock'));
710

@@ -710,7 +713,7 @@ describe("ngAnimate $animateCss", function() {
710713
triggerAnimationStartFrame();
711714

712715
// 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)');
716+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
714717
}));
715718

716719

@@ -2033,7 +2036,7 @@ describe("ngAnimate $animateCss", function() {
20332036

20342037
var style = element.attr('style');
20352038
expect(style).toContain('3000s');
2036-
expect(element.css('transition-timing-function')).toBeOneOf('ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)');
2039+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
20372040
}));
20382041

20392042
it("should be applied to a CSS keyframe animation directly if keyframes are detected within the CSS class",
@@ -2736,7 +2739,7 @@ describe("ngAnimate $animateCss", function() {
27362739

27372740
expect(element.css('transition-duration')).toMatch('2.5s');
27382741
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)');
2742+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
27402743
}));
27412744

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

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

28722875
var emptyObject = {};
28732876
var options = {
@@ -2883,7 +2886,7 @@ describe("ngAnimate $animateCss", function() {
28832886

28842887
expect(element.css('transition-duration')).toMatch('1s');
28852888
expect(element.css('transition-property')).toMatch('color');
2886-
expect(element.css('transition-timing-function')).toBe('cubic-bezier(0.25, 0.1, 0.25, 1)');
2889+
expect(element.css('transition-timing-function')).toBe('linear');
28872890
}));
28882891

28892892
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)