wait for animations to be done

This commit is contained in:
Mads Rasmussen
2018-09-04 09:41:26 +02:00
parent b72fc95d1f
commit 3bc7f0a124

View File

@@ -455,13 +455,28 @@ In the following example you see how to run some custom logic before a step goes
function waitForPendingRerequests() {
var deferred = $q.defer();
var timer = window.setInterval(function(){
var requestsReady = false;
var animationsDone = false;
// check for pending requests both in angular and on the document
if($http.pendingRequests.length === 0 && document.readyState === "complete") {
requestsReady = true;
}
// check for animations. ng-enter and ng-leave are default angular animations.
// Also check for infinite editors animating
if(document.querySelectorAll(".ng-enter, .ng-leave, .umb-editor--animating").length === 0) {
animationsDone = true;
}
if(requestsReady && animationsDone) {
$timeout(function(){
deferred.resolve();
clearInterval(timer);
});
}
}, 50);
return deferred.promise;
}