diff options
| author | Matias Niemelä | 2013-10-23 15:14:27 -0400 |
|---|---|---|
| committer | Matias Niemelä | 2013-10-24 17:35:57 -0400 |
| commit | 76b628bcb3511210d312ed667e5c14d908a9fed1 (patch) | |
| tree | 69e221332893277ce8e1b085c08378a0fe7e357b /src/ngAnimate/animate.js | |
| parent | 46d396df72aab0678eddc3d4aac02c4ba95ceef4 (diff) | |
| download | angular.js-76b628bcb3511210d312ed667e5c14d908a9fed1.tar.bz2 | |
fix($animate): skip unnecessary addClass/removeClass animations
Skip addClass animations if the element already contains the class that is being
added to element. Also skip removeClass animations if the element does not contain
the class that is being removed.
Closes #4401
Closes #2332
Diffstat (limited to 'src/ngAnimate/animate.js')
| -rw-r--r-- | src/ngAnimate/animate.js | 10 |
1 files changed, 10 insertions, 0 deletions
diff --git a/src/ngAnimate/animate.js b/src/ngAnimate/animate.js index 3c9ea9a9..838e210f 100644 --- a/src/ngAnimate/animate.js +++ b/src/ngAnimate/animate.js @@ -541,6 +541,16 @@ angular.module('ngAnimate', ['ng']) (ngAnimateState.done || noop)(); } + //There is no point in perform a class-based animation if the element already contains + //(on addClass) or doesn't contain (on removeClass) the className being animated. + //The reason why this is being called after the previous animations are cancelled + //is so that the CSS classes present on the element can be properly examined. + if((event == 'addClass' && element.hasClass(className)) || + (event == 'removeClass' && !element.hasClass(className))) { + onComplete && onComplete(); + return; + } + element.data(NG_ANIMATE_STATE, { running:true, structural:!isClassBased, |
