Skip to content

Commit 2f7c1b8

Browse files
committed
fix(ngAnimate): support removing classes from SVG elements when using jQuery
Without this CL, ngShowHide will not work without the use of monkeypatched fixes for jQuery such as https://github.com/kbwood/svg 's jquery-svgdom.js script. Closes angular#8872
1 parent ce25ac8 commit 2f7c1b8

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

src/ngAnimate/animate.js

+7-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 = nodeHasClass(element[0], className);
498498
var matchingAnimation = lookup[className] || {};
499499

500500
// When addClass and removeClass is called then $animate will check to
@@ -1869,3 +1869,9 @@ angular.module('ngAnimate', ['ng'])
18691869
}
18701870
}]);
18711871
}]);
1872+
1873+
function nodeHasClass(element, selector) {
1874+
if (!element.getAttribute) return false;
1875+
return ((" " + (element.getAttribute('class') || '') + " ").replace(/[\n\t]/g, " ").
1876+
indexOf( " " + selector + " " ) > -1);
1877+
}

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)