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

Commit 505c11a

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 f1fda8f commit 505c11a

File tree

2 files changed

+19
-16
lines changed

2 files changed

+19
-16
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
}
@@ -595,8 +595,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
595595
var flags = {};
596596
flags.hasTransitions = timings.transitionDuration > 0;
597597
flags.hasAnimations = timings.animationDuration > 0;
598-
flags.applyTransitionDuration = options.duration > 0 || hasToStyles && (flags.hasTransitions
599-
|| (flags.hasAnimations && !flags.hasTransitions));
598+
flags.applyTransitionDuration = options.duration > 0 || hasToStyles && flags.hasTransitions;
600599
flags.applyAnimationDuration = options.duration && flags.hasAnimations;
601600
flags.applyTransitionDelay = truthyTimingValue(options.delay) && (flags.applyTransitionDuration || flags.hasTransitions);
602601
flags.applyAnimationDelay = truthyTimingValue(options.delay) && flags.hasAnimations;

test/ngAnimate/animateCssSpec.js

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

@@ -2132,7 +2136,7 @@ describe("ngAnimate $animateCss", function() {
21322136

21332137
var style = element.attr('style');
21342138
expect(style).toContain('3000s');
2135-
expect(element.css('transition-timing-function')).toBeOneOf('ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)');
2139+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
21362140
}));
21372141

21382142
it("should be applied to a CSS keyframe animation directly if keyframes are detected within the CSS class",
@@ -2238,7 +2242,7 @@ describe("ngAnimate $animateCss", function() {
22382242
expect(style).toMatch(/animation(?:-duration)?:\s*4s/);
22392243
expect(element.css('transition-duration')).toMatch('4s');
22402244
expect(element.css('transition-property')).toMatch('all');
2241-
expect(element.css('transition-timing-function')).toBeOneOf('linear', 'cubic-bezier(0, 0, 1, 1)');
2245+
expect(element.css('transition-timing-function')).toBeOneOf('linear', CUBIC_BEZIER_LINEAR_EQUIVALENT);
22422246
}));
22432247
});
22442248

@@ -2569,7 +2573,7 @@ describe("ngAnimate $animateCss", function() {
25692573
inject(function($animateCss, $rootElement) {
25702574

25712575
var options = {
2572-
transitionStyle: '5.5s ease-in color',
2576+
transitionStyle: '5.5s ease color',
25732577
duration: 4,
25742578
event: 'enter',
25752579
structural: true
@@ -2582,7 +2586,7 @@ describe("ngAnimate $animateCss", function() {
25822586

25832587
expect(element.css('transition-duration')).toMatch('4s');
25842588
expect(element.css('transition-property')).toMatch('color');
2585-
expect(element.css('transition-timing-function')).toBeOneOf('ease-in', 'cubic-bezier(0.42, 0, 1, 1)');
2589+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
25862590
}));
25872591

25882592
it("should give priority to the provided delay value, but only update the delay style itself",
@@ -2835,7 +2839,7 @@ describe("ngAnimate $animateCss", function() {
28352839

28362840
expect(element.css('transition-duration')).toMatch('2.5s');
28372841
expect(element.css('transition-property')).toMatch('all');
2838-
expect(element.css('transition-timing-function')).toBeOneOf('ease', 'cubic-bezier(0.25, 0.1, 0.25, 1)');
2842+
expect(element.css('transition-timing-function')).toBeOneOf('ease', CUBIC_BEZIER_EASE_EQUIVALENT);
28392843
}));
28402844

28412845
it("should remove all inline transition styling when an animation completes",
@@ -2966,7 +2970,7 @@ describe("ngAnimate $animateCss", function() {
29662970
it("should apply a transition duration if the existing transition duration's property value is not 'all'",
29672971
inject(function($animateCss, $rootElement) {
29682972

2969-
ss.addRule('.ng-enter', 'transition: 1s cubic-bezier(0.25, 0.1, 0.25, 1) color');
2973+
ss.addRule('.ng-enter', 'transition: 1s linear color');
29702974

29712975
var emptyObject = {};
29722976
var options = {
@@ -2982,7 +2986,7 @@ describe("ngAnimate $animateCss", function() {
29822986

29832987
expect(element.css('transition-duration')).toMatch('1s');
29842988
expect(element.css('transition-property')).toMatch('color');
2985-
expect(element.css('transition-timing-function')).toBe('cubic-bezier(0.25, 0.1, 0.25, 1)');
2989+
expect(element.css('transition-timing-function')).toBeOneOf('linear', CUBIC_BEZIER_LINEAR_EQUIVALENT);
29862990
}));
29872991

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