Skip to content
This repository has been archived by the owner on Sep 10, 2019. It is now read-only.

Animation hard timeouts #274

Merged
merged 3 commits into from
Dec 10, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 32 additions & 9 deletions js/angular/common/common.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ angular.module('foundation.common.animations')
var scope = element.scope();
if(scope.vars && scope.vars.animationIn) {

var animationIn = scope.vars.animationIn;
var animationIn = scope.vars.animationIn;
var animationOut = scope.vars.animationOut || '';
var initial = 'ng-enter';
var initial = 'ng-enter';
var activate = 'ng-enter-active';
var timedOut = true;

//reset possible failed animations and bugs
element.parent().addClass(parentStyle);
Expand All @@ -31,12 +32,23 @@ angular.module('foundation.common.animations')
element[0].style.transitionDuration = '';
element.addClass(activate);

element.one(events.join(' '), function() {
//cleanup
var finishAnimation = function() {
element.parent().removeClass(parentStyle);
element.removeClass(activate + ' ' + initial + ' ' + animationIn + ' ' + animationOut);
timedOut = false;
done();
}

element.one(events.join(' '), function() {
finishAnimation();
});

setTimeout(function() {
if (timedOut) {
finishAnimation();
}
}, 3000);

} else {
done();
}
Expand All @@ -49,10 +61,11 @@ angular.module('foundation.common.animations')
var scope = element.scope();

if(scope.vars && scope.vars.animationOut) {
var animationIn = scope.vars.animationIn || '';
var animationIn = scope.vars.animationIn || '';
var animationOut = scope.vars.animationOut;
var initial = 'ng-leave';
var initial = 'ng-leave';
var activate = 'ng-leave-active';
var timedOut = true;

element.removeClass(activate + ' ' + initial + ' ' + animationIn + ' ' + animationOut);
element[0].style.transitionDuration = 0;
Expand All @@ -66,13 +79,23 @@ angular.module('foundation.common.animations')
element[0].style.transitionDuration = '';
element.addClass(activate);

element.one(events.join(' '), function() {
//cleanup
element.removeClass(activate + ' ' + initial + ' ' + animationIn + ' ' + animationOut);
var finishAnimation = function() {
element.parent().removeClass(parentStyle);
element.removeClass(activate + ' ' + initial + ' ' + animationIn + ' ' + animationOut);
timedOut = false;
done();
}

element.one(events.join(' '), function() {
finishAnimation();
});

setTimeout(function() {
if (timedOut) {
finishAnimation();
}
}, 3000);

} else {
done();
}
Expand Down
18 changes: 15 additions & 3 deletions js/angular/common/common.services.js
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ angular.module('foundation.common.services')
var activeGenericClass = 'is-active';
var events = ['webkitAnimationEnd', 'mozAnimationEnd', 'MSAnimationEnd', 'oanimationend', 'animationend',
'webkitTransitionEnd', 'otransitionend', 'transitionend'];
var timedOut = true;

var reflow = function() {
return element[0].offsetWidth;
Expand All @@ -84,6 +85,13 @@ angular.module('foundation.common.services')
var initClass = activation ? initClasses[0] : initClasses[1];
var activeClass = activation ? activeClasses[0] : activeClasses[1];

var finishAnimation = function() {
reset(); //reset all classes
element.removeClass(!activation ? activeGenericClass : ''); //if not active, remove active class
reflow();
timedOut = false;
};

//stop animation
reset();
element.addClass(animationClass);
Expand All @@ -98,10 +106,14 @@ angular.module('foundation.common.services')
element.addClass(activeClass);

element.one(events.join(' '), function() {
reset(); //reset all classes
element.removeClass(!activation ? activeGenericClass : ''); //if not active, remove active class
reflow();
finishAnimation();
});

setTimeout(function() {
if(timedOut) {
finishAnimation();
}
}, 3000);
};

animate(futureState ? animationIn : animationOut, futureState);
Expand Down