Skip to content

Commit 669d31d

Browse files
committed
fix:(animator): Correctly handle multiple durations
In case multiple durations are specified like so: transition-duration: 0.5s, 3000ms; transition-property: left, height; The animator will pick the longest duration. Fixes angular#2373
1 parent 1d8e11d commit 669d31d

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

src/ng/animator.js

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -261,6 +261,17 @@ var $AnimatorProvider = function() {
261261
// $window.setTimeout(beginAnimation, 0); this was causing the element not to animate
262262
// keep at 1 for animation dom rerender
263263
$window.setTimeout(beginAnimation, 1);
264+
265+
function getMaxDuration(durationString){
266+
if (isUndefined(durationString)){
267+
return 0;
268+
}
269+
270+
var normalizedValues = map(durationString.split(','), function(val){
271+
return parseFloat(val);
272+
});
273+
return Math.max.apply(null, normalizedValues);
274+
}
264275

265276
function beginAnimation() {
266277
element.addClass(startClass);
@@ -276,8 +287,8 @@ var $AnimatorProvider = function() {
276287
forEach(element, function(element) {
277288
var globalStyles = $window.getComputedStyle(element) || {};
278289
duration = Math.max(
279-
parseFloat(globalStyles[w3cTransitionProp + durationKey]) ||
280-
parseFloat(globalStyles[vendorTransitionProp + durationKey]) ||
290+
getMaxDuration(globalStyles[w3cTransitionProp + durationKey]) ||
291+
getMaxDuration(globalStyles[vendorTransitionProp + durationKey]) ||
281292
0,
282293
duration);
283294
});

test/ng/animatorSpec.js

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -309,10 +309,10 @@ describe("$animator", function() {
309309
})
310310
});
311311

312-
it("should skip animations if disabled and run when enabled",
313-
inject(function($animator, $rootScope, $compile, $sniffer) {
312+
it("should skip animations if disabled and run when enabled picking the longest specified duration",
313+
inject(function($animator, $rootScope, $compile, $sniffer) {
314314
$animator.enabled(false);
315-
element = $compile(html('<div style="' + vendorPrefix + 'transition: 1s linear all">1</div>'))($rootScope);
315+
element = $compile(html('<div style="' + vendorPrefix + 'transition-duration: 1s, 2000ms, 1s; ' + vendorPrefix + 'transition-property: height, left, opacity">foo</div>'))($rootScope);
316316
var animator = $animator($rootScope, {
317317
ngAnimate : '{show: \'inline-show\'}'
318318
});
@@ -330,10 +330,11 @@ describe("$animator", function() {
330330
animator.show(element);
331331
if ($sniffer.supportsTransitions) {
332332
window.setTimeout.expect(1).process();
333-
window.setTimeout.expect(1000).process();
333+
window.setTimeout.expect(2000).process();
334334
}
335335
expect(element[0].style.display).toBe('');
336336
}));
337+
337338
});
338339

339340
it("should throw an error when an invalid ng-animate syntax is provided", inject(function($compile, $rootScope) {

0 commit comments

Comments
 (0)