Commit fe803629 authored by Jason Davies's avatar Jason Davies
Browse files

Minor optimisation and Chrome bug workaround.

There appears to be a bug in Chrome causing the whole tab to crash when
setting svgNode.className.baseVal = "" for a newly-created element
without a non-empty class name:

  https://code.google.com/p/chromium/issues/detail?id=138552

This fix is a minor optimisation: if the current class is empty then
removing a class should be a no-op.  It also conveniently works around
the Chrome bug.
parent 544addb4
......@@ -1670,9 +1670,11 @@ function d3_selection_classed(name, value) {
var c = this.className,
cb = c.baseVal != null,
cv = cb ? c.baseVal : c;
cv = d3_collapse(cv.replace(re, " "));
if (cb) c.baseVal = cv;
else this.className = cv;
if (cv.length) {
cv = d3_collapse(cv.replace(re, " "));
if (cb) c.baseVal = cv;
else this.className = cv;
}
}
function classedFunction() {
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -27,7 +27,8 @@
},
"devDependencies": {
"uglify-js": "1.2.3",
"vows": "0.6.x"
"vows": "0.6.x",
"canvas": "0.12.1"
},
"scripts": {
"test": "./node_modules/vows/bin/vows"
......
......@@ -41,9 +41,11 @@ function d3_selection_classed(name, value) {
var c = this.className,
cb = c.baseVal != null,
cv = cb ? c.baseVal : c;
cv = d3_collapse(cv.replace(re, " "));
if (cb) c.baseVal = cv;
else this.className = cv;
if (cv.length) {
cv = d3_collapse(cv.replace(re, " "));
if (cb) c.baseVal = cv;
else this.className = cv;
}
}
function classedFunction() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment