Skip to content

Commit 8891893

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

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
*
@@ -552,14 +552,14 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
552552
addRemoveClassName = '';
553553
}
554554

555-
var setupClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
556-
var fullClassName = classes + ' ' + setupClasses;
557-
var activeClasses = pendClasses(setupClasses, '-active');
555+
var preparationClasses = [structuralClassName, addRemoveClassName].join(' ').trim();
556+
var fullClassName = classes + ' ' + preparationClasses;
557+
var activeClasses = pendClasses(preparationClasses, '-active');
558558
var hasToStyles = styles.to && Object.keys(styles.to).length > 0;
559559

560560
// there is no way we can trigger an animation since no styles and
561561
// no classes are being applied which would then trigger a transition
562-
if (!hasToStyles && !setupClasses) {
562+
if (!hasToStyles && !preparationClasses) {
563563
return closeAndReturnNoopAnimator();
564564
}
565565

@@ -574,10 +574,12 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
574574
};
575575
} else {
576576
cacheKey = gcsHashFn(node, fullClassName);
577-
stagger = computeCachedCssStaggerStyles(node, setupClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
577+
stagger = computeCachedCssStaggerStyles(node, preparationClasses, cacheKey, DETECT_STAGGER_CSS_PROPERTIES);
578578
}
579579

580-
$$jqLite.addClass(element, setupClasses);
580+
if (!options.$$skipPreparationClasses) {
581+
$$jqLite.addClass(element, preparationClasses);
582+
}
581583

582584
var applyOnlyDuration;
583585

@@ -723,7 +725,9 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
723725
animationClosed = true;
724726
animationPaused = false;
725727

726-
$$jqLite.removeClass(element, setupClasses);
728+
if (!options.$$skipPreparationClasses) {
729+
$$jqLite.removeClass(element, preparationClasses);
730+
}
727731
$$jqLite.removeClass(element, activeClasses);
728732

729733
blockKeyframeAnimations(node, false);
@@ -846,7 +850,7 @@ var $AnimateCssProvider = ['$animateProvider', function($animateProvider) {
846850
$$jqLite.addClass(element, activeClasses);
847851

848852
if (flags.recalculateTimingStyles) {
849-
fullClassName = node.className + ' ' + setupClasses;
853+
fullClassName = node.className + ' ' + preparationClasses;
850854
cacheKey = gcsHashFn(node, fullClassName);
851855

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

test/ngAnimate/animateCssSpec.js

+39
Original file line numberDiff line numberDiff line change
@@ -1641,6 +1641,45 @@ describe("ngAnimate $animateCss", function() {
16411641
$rootElement.append(element);
16421642
}));
16431643

1644+
describe("[$$skipPreparationClasses]", function() {
1645+
it('should not apply and remove the preparation classes to the element when true',
1646+
inject(function($animateCss) {
1647+
1648+
var options = {
1649+
duration: 3000,
1650+
to: fakeStyle,
1651+
event: 'event',
1652+
structural: true,
1653+
addClass: 'klass',
1654+
$$skipPreparationClasses: true
1655+
};
1656+
1657+
var animator = $animateCss(element, options);
1658+
1659+
expect(element).not.toHaveClass('klass-add');
1660+
expect(element).not.toHaveClass('ng-event');
1661+
1662+
var runner = animator.start();
1663+
triggerAnimationStartFrame();
1664+
1665+
expect(element).not.toHaveClass('klass-add');
1666+
expect(element).not.toHaveClass('ng-event');
1667+
1668+
expect(element).toHaveClass('klass-add-active');
1669+
expect(element).toHaveClass('ng-event-active');
1670+
1671+
element.addClass('klass-add ng-event');
1672+
1673+
runner.end();
1674+
1675+
expect(element).toHaveClass('klass-add');
1676+
expect(element).toHaveClass('ng-event');
1677+
1678+
expect(element).not.toHaveClass('klass-add-active');
1679+
expect(element).not.toHaveClass('ng-event-active');
1680+
}));
1681+
});
1682+
16441683
describe("[duration]", function() {
16451684
it("should be applied for a transition directly", inject(function($animateCss, $rootElement) {
16461685
var element = jqLite('<div></div>');

0 commit comments

Comments
 (0)