From 58b811eeea0e6b88e9dce930762047a407faa88a Mon Sep 17 00:00:00 2001 From: Pietro Giorgianni Date: Mon, 27 May 2013 17:30:05 +0200 Subject: [PATCH 1/3] Fix: SVG on some Webkit versions (notably: iOS) don't have attribute classList. --- src/lib/dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/lib/dom.js b/src/lib/dom.js index 59f582d..71e12ac 100644 --- a/src/lib/dom.js +++ b/src/lib/dom.js @@ -54,7 +54,7 @@ goog.scope(function() { * @return {boolean} True if the element has that class. */ dom.hasClass = function(el, className) { - return el.classList.contains(className); + return el.classList && el.classList.contains(className); }; /** From e79beee5356497c7b5abe967bb99490c1f91adce Mon Sep 17 00:00:00 2001 From: Andrea Campi Date: Wed, 5 Jun 2013 23:10:12 +0200 Subject: [PATCH 2/3] Test that DOM className helpers work correctly with SVGs. --- test/dom.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/test/dom.js b/test/dom.js index cb0dc5b..a03a0c5 100644 --- a/test/dom.js +++ b/test/dom.js @@ -25,6 +25,23 @@ $(function() { ok(!treesaver.dom.hasClass(div, 'test'), 'hasClass: Removed class'); }); + test('className helpers on SVG', function () { + var svg = document.createElement('svg'); + + equals(treesaver.dom.classes(svg).length, 0, 'classes: Unset className'); + + treesaver.dom.addClass(svg, 'test'); + + equals(treesaver.dom.classes(svg).length, 1, 'classes: Single class'); + ok(treesaver.dom.hasClass(svg, 'test'), 'hasClass: Single class'); + ok(!treesaver.dom.hasClass(svg, 'bogus'), 'hasClass: Single class failure'); + + treesaver.dom.removeClass(svg, 'test'); + + equals(treesaver.dom.classes(svg).length, 0, 'classes: Removed class'); + ok(!treesaver.dom.hasClass(svg, 'test'), 'hasClass: Removed class'); + }); + test('hasAttr', function () { var div = document.createElement('div'), attr = document.createAttribute('width'); From 904b17f635086f5da7fabd7c8c82c1403e64fe33 Mon Sep 17 00:00:00 2001 From: Pietro Giorgianni Date: Thu, 6 Jun 2013 16:36:57 +0200 Subject: [PATCH 3/3] Fix SVG creation in tests. SVG elements must be created via document.createElementNS, with the correct namespace ( http://www.w3.org/2000/svg ); if created with document.createElement, they are not SVG nodes but Unknown Element nodes (i.e. their prototype is HTMLUnknownElementPrototype instead of SVGSVGElementPrototype). --- test/dom.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/dom.js b/test/dom.js index a03a0c5..3fcf499 100644 --- a/test/dom.js +++ b/test/dom.js @@ -26,7 +26,7 @@ $(function() { }); test('className helpers on SVG', function () { - var svg = document.createElement('svg'); + var svg = document.createElementNS('http://www.w3.org/2000/svg', 'svg'); equals(treesaver.dom.classes(svg).length, 0, 'classes: Unset className');