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

Commit ec90bae

Browse files
committed
chore(ngAnimate): skip adding the preparation classes when options.$$skipPreparationClasses is present
1 parent df3e9f5 commit ec90bae

File tree

2 files changed

+53
-10
lines changed

2 files changed

+53
-10
lines changed

src/ngAnimate/animateCss.js

+14-10
Original file line numberDiff line numberDiff line change
@@ -200,8 +200,8 @@
200200
* * `stagger` - A numeric time value representing the delay between successively animated elements
201201
* ({@link ngAnimate#css-staggering-animations Click here to learn how CSS-based staggering works in ngAnimate.})
202202
* * `staggerIndex` - The numeric index representing the stagger item (e.g. a value of 5 is equal to the sixth item in the stagger; therefore when a
203-
* `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`)
204-
* `applyClassesEarly` - Whether or not the classes being added or removed will be used when detecting the animation. This is set by `$animate` when enter/leave/move animations are fired to ensure that the CSS classes are resolved in time. (Note that this will prevent any transitions from occuring on the classes being added and removed.)
203+
* * `stagger` option value of `0.1` is used then there will be a stagger delay of `600ms`)
204+
* * `applyClassesEarly` - Whether or not the classes being added or removed will be used when detecting the animation. This is set by `$animate` when enter/leave/move animations are fired to ensure that the CSS classes are resolved in time. (Note that this will prevent any transitions from occuring on the classes being added and removed.)
205205
*
206206
* @return {object} an object with start and end methods and details about the animation.
207207
*
@@ -556,9 +556,9 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
556556
addRemoveClassName = '';
557557
}
558558

559-
var setupClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
560-
var fullClassName = classes + ' ' + setupClasses;
561-
var activeClasses = pendClasses(setupClasses, '-active');
559+
var preparationClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
560+
var fullClassName = classes + ' ' + preparationClasses;
561+
var activeClasses = pendClasses(preparationClasses, '-active');
562562
var hasToStyles = styles.to && Object.keys(styles.to).length > 0;
563563
var containsKeyframeAnimation = (options.keyframeStyle || '').length > 0;
564564

@@ -567,7 +567,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
567567
// unless there a is raw keyframe value that is applied to the element.
568568
if (!containsKeyframeAnimation
569569
&& !hasToStyles
570-
&& !setupClasses) {
570+
&& !preparationClasses) {
571571
return closeAndReturnNoopAnimator();
572572
}
573573

@@ -582,10 +582,12 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
582582
};
583583
} else {
584584
cacheKey = gcsHashFn(node, fullClassName);
585-
stagger = computeCachedCssStaggerStyles(node, setupClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
585+
stagger = computeCachedCssStaggerStyles(node, preparationClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
586586
}
587587

588-
$$jqLite.addClass(element, setupClasses);
588+
if (!options.$$skipPreparationClasses) {
589+
$$jqLite.addClass(element, preparationClasses);
590+
}
589591

590592
var applyOnlyDuration;
591593

@@ -731,7 +733,9 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
731733
animationClosed = true;
732734
animationPaused = false;
733735

734-
$$jqLite.removeClass(element, setupClasses);
736+
if (!options.$$skipPreparationClasses) {
737+
$$jqLite.removeClass(element, preparationClasses);
738+
}
735739
$$jqLite.removeClass(element, activeClasses);
736740

737741
blockKeyframeAnimations(node, false);
@@ -858,7 +862,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
858862
$$jqLite.addClass(element, activeClasses);
859863

860864
if (flags.recalculateTimingStyles) {
861-
fullClassName = node.className + ' ' + setupClasses;
865+
fullClassName = node.className + ' ' + preparationClasses;
862866
cacheKey = gcsHashFn(node, fullClassName);
863867

864868
timings = computeTimings(node, fullClassName, cacheKey);

test/ngAnimate/animateCssSpec.js

+39
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,45 @@ describe("ngAnimate $animateCss", function() {
16781678
$rootElement.append(element);
16791679
}));
16801680

1681+
describe("[$$skipPreparationClasses]", function() {
1682+
it('should not apply and remove the preparation classes to the element when true',
1683+
inject(function($animateCss) {
1684+
1685+
var options = {
1686+
duration: 3000,
1687+
to: fakeStyle,
1688+
event: 'event',
1689+
structural: true,
1690+
addClass: 'klass',
1691+
$$skipPreparationClasses: true
1692+
};
1693+
1694+
var animator = $animateCss(element, options);
1695+
1696+
expect(element).not.toHaveClass('klass-add');
1697+
expect(element).not.toHaveClass('ng-event');
1698+
1699+
var runner = animator.start();
1700+
triggerAnimationStartFrame();
1701+
1702+
expect(element).not.toHaveClass('klass-add');
1703+
expect(element).not.toHaveClass('ng-event');
1704+
1705+
expect(element).toHaveClass('klass-add-active');
1706+
expect(element).toHaveClass('ng-event-active');
1707+
1708+
element.addClass('klass-add ng-event');
1709+
1710+
runner.end();
1711+
1712+
expect(element).toHaveClass('klass-add');
1713+
expect(element).toHaveClass('ng-event');
1714+
1715+
expect(element).not.toHaveClass('klass-add-active');
1716+
expect(element).not.toHaveClass('ng-event-active');
1717+
}));
1718+
});
1719+
16811720
describe("[duration]", function() {
16821721
it("should be applied for a transition directly", inject(function($animateCss, $rootElement) {
16831722
var element = jqLite('<div></div>');

0 commit comments

Comments
 (0)