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

Commit 9470080

Browse files
committed
fix($animate): only apply the fallback property if any transition animations are detected
1 parent aba0fe6 commit 9470080

File tree

3 files changed

+56
-4
lines changed

3 files changed

+56
-4
lines changed

css/angular.css

+2-2
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,5 @@ ng\:form {
1818
* animations. The clip (!ie) and zoom (ie) CSS properties are used
1919
* since they trigger a transition without making the browser
2020
* animate anything and they're both highly underused CSS properties */
21-
.ng-animate { clip:rect(1px, auto, auto, 0); -ms-zoom:1.0001; }
22-
.ng-animate-active { clip:rect(0, auto, auto, 0); -ms-zoom:1; }
21+
.ng-animate-start { clip:rect(0, auto, auto, 0); -ms-zoom:1.0001; }
22+
.ng-animate-active { clip:rect(-1px, auto, auto, 0); -ms-zoom:1; }

src/ngAnimate/animate.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -815,6 +815,8 @@ angular.module('ngAnimate', ['ng'])
815815
var ANIMATION_ITERATION_COUNT_KEY = 'IterationCount';
816816
var NG_ANIMATE_PARENT_KEY = '$$ngAnimateKey';
817817
var NG_ANIMATE_CSS_DATA_KEY = '$$ngAnimateCSS3Data';
818+
var NG_ANIMATE_FALLBACK_CLASS_NAME = 'ng-animate-start';
819+
var NG_ANIMATE_FALLBACK_ACTIVE_CLASS_NAME = 'ng-animate-active';
818820

819821
var lookupCache = {};
820822
var parentCounter = 0;
@@ -954,11 +956,13 @@ angular.module('ngAnimate', ['ng'])
954956
var node = element[0];
955957
//temporarily disable the transition so that the enter styles
956958
//don't animate twice (this is here to avoid a bug in Chrome/FF).
959+
var activeClassName = '';
957960
if(timings.transitionDuration > 0) {
961+
element.addClass(NG_ANIMATE_FALLBACK_CLASS_NAME);
962+
activeClassName += NG_ANIMATE_FALLBACK_ACTIVE_CLASS_NAME + ' ';
958963
node.style[TRANSITION_PROP + PROPERTY_KEY] = 'none';
959964
}
960965

961-
var activeClassName = 'ng-animate-active ';
962966
forEach(className.split(' '), function(klass, i) {
963967
activeClassName += (i > 0 ? ' ' : '') + klass + '-active';
964968
});
@@ -1118,6 +1122,7 @@ angular.module('ngAnimate', ['ng'])
11181122

11191123
function animateClose(element, className) {
11201124
element.removeClass(className);
1125+
element.removeClass(NG_ANIMATE_FALLBACK_CLASS_NAME);
11211126
element.removeData(NG_ANIMATE_CSS_DATA_KEY);
11221127
}
11231128

test/ngAnimate/animateSpec.js

+48-1
Original file line numberDiff line numberDiff line change
@@ -814,7 +814,7 @@ describe("ngAnimate", function() {
814814
$timeout.flush();
815815

816816
expect(child.attr('style') || '').not.toContain('transition-property');
817-
expect(child.hasClass('ng-animate')).toBe(true);
817+
expect(child.hasClass('ng-animate-start')).toBe(true);
818818
expect(child.hasClass('ng-animate-active')).toBe(true);
819819

820820
browserTrigger(child,'transitionend', { timeStamp: Date.now() + 1000, elapsedTime: 1000 });
@@ -845,6 +845,53 @@ describe("ngAnimate", function() {
845845
expect(child2.hasClass('ng-animate-active')).toBe(false);
846846
}));
847847

848+
it("should not apply the fallback classes if no animations are going on or if CSS animations are going on",
849+
inject(function($compile, $rootScope, $animate, $sniffer, $timeout) {
850+
851+
if (!$sniffer.animations) return;
852+
853+
ss.addRule('.transitions', '-webkit-transition:1s linear all;' +
854+
'transition:1s linear all');
855+
856+
ss.addRule('.keyframes', '-webkit-animation:my_animation 1s;' +
857+
'animation:my_animation 1s');
858+
859+
var element = $compile('<div class="transitions">...</div>')($rootScope);
860+
$rootElement.append(element);
861+
jqLite($document[0].body).append($rootElement);
862+
863+
$animate.enabled(false);
864+
865+
$animate.addClass(element, 'klass');
866+
867+
expect(element.hasClass('ng-animate-start')).toBe(false);
868+
869+
element.removeClass('klass');
870+
871+
$animate.enabled(true);
872+
873+
$animate.addClass(element, 'klass');
874+
875+
$timeout.flush();
876+
877+
expect(element.hasClass('ng-animate-start')).toBe(true);
878+
expect(element.hasClass('ng-animate-active')).toBe(true);
879+
880+
browserTrigger(element,'transitionend', { timeStamp: Date.now() + 1000, elapsedTime: 1 });
881+
882+
expect(element.hasClass('ng-animate-start')).toBe(false);
883+
expect(element.hasClass('ng-animate-active')).toBe(false);
884+
885+
element.attr('class', 'keyframes');
886+
887+
$animate.addClass(element, 'klass2');
888+
889+
$timeout.flush();
890+
891+
expect(element.hasClass('ng-animate-start')).toBe(false);
892+
expect(element.hasClass('ng-animate-active')).toBe(false);
893+
}));
894+
848895
it("should skip transitions if disabled and run when enabled",
849896
inject(function($animate, $rootScope, $compile, $sniffer, $timeout) {
850897

0 commit comments

Comments
 (0)