From c785267eb8780d8b7658ef93ebb5ebddd566294d Mon Sep 17 00:00:00 2001 From: Brian Ford Date: Mon, 23 Sep 2013 17:29:51 -0700 Subject: fix(jqLite): use get/setAttribute so that jqLite works on SVG nodes jqLite previously used `elt.className` to add and remove classes from a DOM Node, but because the className property is not writable on SVG elements, it doesn't work with them. This patch replaces accesses to `className` with `get/setAttribute`. `classList` was also considered as a solution, but because only IE10+ supports it, we have to wait. :'( The JqLiteAddClass/JQLiteRemoveClass methods are now also used directly by $animate to work around the jQuery not being able to handle class modifications on SVG elements. Closes #3858 --- test/jqLiteSpec.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/jqLiteSpec.js') diff --git a/test/jqLiteSpec.js b/test/jqLiteSpec.js index 79c0d0c6..e6e3a2ac 100644 --- a/test/jqLiteSpec.js +++ b/test/jqLiteSpec.js @@ -479,6 +479,20 @@ describe('jqLite', function() { describe('class', function() { + it('should properly do with SVG elements', function() { + // this is a jqLite & SVG only test (jquery doesn't behave this way right now, which is a bug) + if (!window.SVGElement || !_jqLiteMode) return; + var svg = jqLite(''); + var rect = svg.children(); + + expect(rect.hasClass('foo-class')).toBe(false); + rect.addClass('foo-class'); + expect(rect.hasClass('foo-class')).toBe(true); + rect.removeClass('foo-class'); + expect(rect.hasClass('foo-class')).toBe(false); + }); + + describe('hasClass', function() { it('should check class', function() { var selector = jqLite([a, b]); -- cgit v1.2.3