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

Commit 0a63adc

Browse files
matskomhevery
authored andcommitted
fix(ngAnimate): ensure that delays are always considered before an animation closes
Closes #4028
1 parent acc2fb8 commit 0a63adc

File tree

2 files changed

+95
-45
lines changed

2 files changed

+95
-45
lines changed

src/ngAnimate/animate.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -560,6 +560,7 @@ angular.module('ngAnimate', ['ng'])
560560

561561
var durationKey = 'Duration',
562562
propertyKey = 'Property',
563+
delayKey = 'Delay',
563564
animationIterationCountKey = 'IterationCount',
564565
ELEMENT_NODE = 1;
565566

@@ -593,6 +594,12 @@ angular.module('ngAnimate', ['ng'])
593594
if (element.nodeType == ELEMENT_NODE) {
594595
var elementStyles = $window.getComputedStyle(element) || {};
595596

597+
var transitionDelay = Math.max(parseMaxTime(elementStyles[w3cTransitionProp + delayKey]),
598+
parseMaxTime(elementStyles[vendorTransitionProp + delayKey]));
599+
600+
var animationDelay = Math.max(parseMaxTime(elementStyles[w3cAnimationProp + delayKey]),
601+
parseMaxTime(elementStyles[vendorAnimationProp + delayKey]));
602+
596603
var transitionDuration = Math.max(parseMaxTime(elementStyles[w3cTransitionProp + durationKey]),
597604
parseMaxTime(elementStyles[vendorTransitionProp + durationKey]));
598605

@@ -605,17 +612,18 @@ angular.module('ngAnimate', ['ng'])
605612
1);
606613
}
607614

608-
transitionTime = Math.max(transitionDuration, transitionTime);
609-
animationTime = Math.max(animationDuration, animationTime);
615+
transitionTime = Math.max(transitionDelay + transitionDuration, transitionTime);
616+
animationTime = Math.max(animationDelay + animationDuration, animationTime);
610617
}
611618
});
612619

613620
/* there is no point in performing a reflow if the animation
614621
timeout is empty (this would cause a flicker bug normally
615622
in the page */
616-
var totalTime = Math.max(transitionTime,animationTime);
617-
if(totalTime > 0) {
618-
var node = element[0];
623+
var maxTime = Math.max(transitionTime,animationTime) * 1000;
624+
if(maxTime > 0) {
625+
var node = element[0],
626+
startTime = Date.now();
619627

620628
//temporarily disable the transition so that the enter styles
621629
//don't animate twice (this is here to avoid a bug in Chrome/FF).
@@ -659,7 +667,14 @@ angular.module('ngAnimate', ['ng'])
659667
}
660668

661669
function onAnimationProgress(event) {
662-
(event.elapsedTime || (event.originalEvent && event.originalEvent.elapsedTime)) >= totalTime && done();
670+
event.stopPropagation();
671+
var ev = event.originalEvent || event;
672+
/* $manualTimeStamp is a mocked timeStamp value which is set
673+
* within browserTrigger(). This is only here so that tests can
674+
* mock animations properly. Real events fallback to event.timeStamp. */
675+
if((ev.$manualTimeStamp || ev.timeStamp) - startTime >= maxTime) {
676+
done();
677+
}
663678
}
664679

665680
function parseMaxTime(str) {

0 commit comments

Comments
 (0)