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

Commit b3b6721

Browse files
committed
fix(ngAnimate): support removing classes from SVG elements when using jQuery
Fixes a regression in ngAnimate introduced in 2f4437b, whereby SVG elements would not be able to have classes removed by ngAnimate methods when jQuery was loaded (without also including libraries which patch jQuery to support SVG elements, such as jquery-svgdom.js). This fix exports jqLiteHasClass as a private method `$$hasClass` on the `angular` global object, which enables ngAnimate to use this SVG-safe method for testing if the class is available. Closes #8872 Closes #8893
1 parent 8b5d33d commit b3b6721

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

src/AngularPublic.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,8 @@ function publishExternalAPI(angular){
140140
'getTestability': getTestability,
141141
'$$minErr': minErr,
142142
'$$csp': csp,
143-
'reloadWithDebugInfo': reloadWithDebugInfo
143+
'reloadWithDebugInfo': reloadWithDebugInfo,
144+
'$$hasClass': jqLiteHasClass
144145
});
145146

146147
angularModule = setupModuleLoader(window);

src/ngAnimate/animate.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ angular.module('ngAnimate', ['ng'])
494494

495495
var toAdd = [], toRemove = [];
496496
forEach(map, function(status, className) {
497-
var hasClass = element.hasClass(className);
497+
var hasClass = angular.$$hasClass(element[0], className);
498498
var matchingAnimation = lookup[className] || {};
499499

500500
// When addClass and removeClass is called then $animate will check to

test/ngAnimate/animateSpec.js

+12
Original file line numberDiff line numberDiff line change
@@ -4641,6 +4641,18 @@ describe("ngAnimate", function() {
46414641
expect(child.hasClass('ng-enter')).toBe(false);
46424642
expect(child.hasClass('ng-enter-active')).toBe(false);
46434643
}));
4644+
4645+
4646+
it('should properly remove classes from SVG elements', inject(function($animate, $rootScope) {
4647+
var element = jqLite('<svg width="500" height="500"><rect class="class-of-doom"></rect></svg>');
4648+
var child = element.find('rect');
4649+
$animate.removeClass(child, 'class-of-doom');
4650+
4651+
$rootScope.$digest();
4652+
expect(child.attr('class')).toBe('');
4653+
4654+
dealoc(element);
4655+
}));
46444656
});
46454657
});
46464658
});

0 commit comments

Comments
 (0)