Skip to content

Commit c36befc

Browse files
committed
Only use createElement for HTML.
Fix d3#2737. The previous fix for d3#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
1 parent b561c02 commit c36befc

File tree

7 files changed

+18
-15
lines changed

7 files changed

+18
-15
lines changed

d3.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
!function() {
22
var d3 = {
3-
version: "3.5.15"
3+
version: "3.5.16"
44
};
55
var d3_arraySlice = [].slice, d3_array = function(list) {
66
return d3_arraySlice.call(list);
@@ -620,9 +620,10 @@
620620
return d3_selectAll(selector, this);
621621
};
622622
}
623+
var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
623624
var d3_nsPrefix = {
624625
svg: "http://www.w3.org/2000/svg",
625-
xhtml: "http://www.w3.org/1999/xhtml",
626+
xhtml: d3_nsXhtml,
626627
xlink: "http://www.w3.org/1999/xlink",
627628
xml: "http://www.w3.org/XML/1998/namespace",
628629
xmlns: "http://www.w3.org/2000/xmlns/"
@@ -805,7 +806,7 @@
805806
function d3_selection_creator(name) {
806807
function create() {
807808
var document = this.ownerDocument, namespace = this.namespaceURI;
808-
return namespace && namespace !== document.documentElement.namespaceURI ? document.createElementNS(namespace, name) : document.createElement(name);
809+
return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml ? document.createElement(name) : document.createElementNS(namespace, name);
809810
}
810811
function createNS() {
811812
return this.ownerDocument.createElementNS(name.space, name.local);

d3.min.js

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
Package.describe({
44
name: "d3js:d3", // http://atmospherejs.com/d3js/d3
55
summary: "D3 (official): A JavaScript visualization library for HTML and SVG.",
6-
version: "3.5.15",
6+
version: "3.5.16",
77
git: "https://github.com/mbostock/d3.git"
88
});
99

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "d3",
3-
"version": "3.5.15",
3+
"version": "3.5.16",
44
"description": "A JavaScript visualization library for HTML and SVG.",
55
"keywords": [
66
"dom",

src/core/ns.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
var d3_nsXhtml = "http://www.w3.org/1999/xhtml";
2+
13
var d3_nsPrefix = {
24
svg: "http://www.w3.org/2000/svg",
3-
xhtml: "http://www.w3.org/1999/xhtml",
5+
xhtml: d3_nsXhtml,
46
xlink: "http://www.w3.org/1999/xlink",
57
xml: "http://www.w3.org/XML/1998/namespace",
68
xmlns: "http://www.w3.org/2000/xmlns/"

src/selection/append.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ function d3_selection_creator(name) {
1313
function create() {
1414
var document = this.ownerDocument,
1515
namespace = this.namespaceURI;
16-
return namespace && namespace !== document.documentElement.namespaceURI
17-
? document.createElementNS(namespace, name)
18-
: document.createElement(name);
16+
return namespace === d3_nsXhtml && document.documentElement.namespaceURI === d3_nsXhtml
17+
? document.createElement(name)
18+
: document.createElementNS(namespace, name);
1919
}
2020

2121
function createNS() {

src/start.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
!function(){
2-
var d3 = {version: "3.5.15"}; // semver
2+
var d3 = {version: "3.5.16"}; // semver

0 commit comments

Comments
 (0)