Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Add SVG support to IE #3

Open
wants to merge 2 commits into from

3 participants

@ForbesLindesay

You have to do a little extra work to get and set the .className attribute of SVG elements. This does that extra work

@stephenmathieson

ie and the class attribute don't play well. are you sure this works?

It worked for me

@TooTallNate TooTallNate commented on the diff
@@ -131,3 +131,14 @@ ClassList.prototype.has = function(name){
? this.list.contains(name)
: !! ~index(this.array(), name);
};
+
+ClassList.prototype.getClassName = function(){
+ return (this.el.className instanceof SVGAnimatedString ? this.el.className.baseVal : this.el.className);
@TooTallNate Owner

What about if SVGAnimatedString is undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 16, 2012
  1. @ForbesLindesay

    Fix for SVGs in IE

    ForbesLindesay authored
  2. @ForbesLindesay

    Fix set-class-name

    ForbesLindesay authored
This page is out of date. Refresh to see the latest.
Showing with 14 additions and 3 deletions.
  1. +14 −3 index.js
View
17 index.js
@@ -54,7 +54,7 @@ ClassList.prototype.add = function(name){
var arr = this.array();
var i = index(arr, name);
if (!~i) arr.push(name);
- this.el.className = arr.join(' ');
+ this.setClassName(arr.join(' '));
return this;
};
@@ -77,7 +77,7 @@ ClassList.prototype.remove = function(name){
var arr = this.array();
var i = index(arr, name);
if (~i) arr.splice(i, 1);
- this.el.className = arr.join(' ');
+ this.setClassName(arr.join(' '));
return this;
};
@@ -113,7 +113,7 @@ ClassList.prototype.toggle = function(name){
*/
ClassList.prototype.array = function(){
- var arr = this.el.className.split(re);
+ var arr = this.getClassName().split(re);
if ('' === arr[0]) arr.pop();
return arr;
};
@@ -131,3 +131,14 @@ ClassList.prototype.has = function(name){
? this.list.contains(name)
: !! ~index(this.array(), name);
};
+
+ClassList.prototype.getClassName = function(){
+ return (this.el.className instanceof SVGAnimatedString ? this.el.className.baseVal : this.el.className);
@TooTallNate Owner

What about if SVGAnimatedString is undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
+};
+ClassList.prototype.setClassName = function(value){
+ if (this.el.className instanceof SVGAnimatedString) {
+ this.el.setAttribute("class", value);
+ } else {
+ this.el.className = value;
+ }
+};
Something went wrong with that request. Please try again.