Skip to content

Commit

Permalink
Only use createElement for HTML.
Browse files Browse the repository at this point in the history
Fix #2737. The previous fix for #2722 meant that createElement was used to
create HTML elements in HTML documents, but it also meant it was used to create
SVG elements in SVG documents, which failed: createElement only inherits the
namespace in HTML documents, not in other document types.

https://www.w3.org/TR/dom/#dom-document-createelement
  • Loading branch information
mbostock committed Feb 18, 2016
1 parent b561c02 commit c36befc
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 15 deletions.
7 changes: 4 additions & 3 deletions d3.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
!function() {
var d3 = {
version: "3.5.15"
version: "3.5.16"
};
var d3_arraySlice = [].slice, d3_array = function(list) {
return d3_arraySlice.call(list);
Expand Down Expand Up @@ -620,9 +620,10 @@
return d3_selectAll(selector, this);
};
}
var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
var d3_nsPrefix = {
svg: "http://www.w3.org/2000/svg",
xhtml: "http://www.w3.org/1999/xhtml",
xhtml: d3_nsXhtml,
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
Expand Down Expand Up @@ -805,7 +806,7 @@
function d3_selection_creator(name) {
function create() {
var document = this.ownerDocument, namespace = this.namespaceURI;
return namespace && namespace !== document.documentElement.namespaceURI ? document.createElementNS(namespace, name) : document.createElement(name);
return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
}
function createNS() {
return this.ownerDocument.createElementNS(name.space, name.local);
Expand Down
10 changes: 5 additions & 5 deletions d3.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
Package.describe({
name: "d3js:d3", // http://atmospherejs.com/d3js/d3
summary: "D3 (official): A JavaScript visualization library for HTML and SVG.",
version: "3.5.15",
version: "3.5.16",
git: "https://github.com/mbostock/d3.git"
});

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "d3",
"version": "3.5.15",
"version": "3.5.16",
"description": "A JavaScript visualization library for HTML and SVG.",
"keywords": [
"dom",
Expand Down
4 changes: 3 additions & 1 deletion src/core/ns.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
var d3_nsXhtml = "http://www.w3.org/1999/xhtml";

var d3_nsPrefix = {
svg: "http://www.w3.org/2000/svg",
xhtml: "http://www.w3.org/1999/xhtml",
xhtml: d3_nsXhtml,
xlink: "http://www.w3.org/1999/xlink",
xml: "http://www.w3.org/XML/1998/namespace",
xmlns: "http://www.w3.org/2000/xmlns/"
Expand Down
6 changes: 3 additions & 3 deletions src/selection/append.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ function d3_selection_creator(name) {
function create() {
var document = this.ownerDocument,
namespace = this.namespaceURI;
return namespace && namespace !== document.documentElement.namespaceURI
? document.createElementNS(namespace, name)
: document.createElement(name);
return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml
? document.createElement(name)
: document.createElementNS(namespace, name);
}

function createNS() {
Expand Down
2 changes: 1 addition & 1 deletion src/start.js
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
!function(){
var d3 = {version: "3.5.15"}; // semver
var d3 = {version: "3.5.16"}; // semver

0 comments on commit c36befc

Please sign in to comment.