Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Demote JSDOM to development dependency; fix #2190.
Code that previously assumed a global document or window now uses the related node’s ownerDocument or ownerDocument.defaultView as appropriate. If no related node is available, the corresponding code will crash; however, the rest of D3 will work just fine. For example, you can’t use d3.select(string) unless a global document is available; it just doesn’t make sense. Use d3.select(node) instead, followed by selection.select(string). Code that previously checked for a global on the window (e.g., XDomainRequest) now uses the global context (`this`) rather than the window.
- Loading branch information
Showing
22 changed files
with
261 additions
and
201 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,9 @@ | ||
var document = require("jsdom").jsdom(), | ||
globals = {}; | ||
var globals = {}; | ||
|
||
// Stash old globals. | ||
// Stash old global. | ||
if ("d3" in global) globals.d3 = global.d3; | ||
if ("window" in global) globals.window = global.window; | ||
if ("document" in global) globals.document = global.document; | ||
|
||
// Set temporary globals to pretend we’re in a browser. | ||
global.window = document.parentWindow; | ||
global.document = document; | ||
|
||
module.exports = require("./d3"); | ||
|
||
// Restore old globals. | ||
// Restore old global. | ||
if ("d3" in globals) global.d3 = globals.d3; else delete global.d3; | ||
if ("window" in globals) global.window = globals.window; else delete global.window; | ||
if ("document" in globals) global.document = globals.document; else delete global.document; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
import "../core/array"; | ||
import "../core/document"; | ||
|
||
// Redefine d3_array if the browser doesn’t support slice-based conversion. | ||
if (d3_document) { | ||
try { | ||
d3_array(d3_document.documentElement.childNodes)[0].nodeType; | ||
} catch (e) { | ||
d3_array = function(list) { | ||
var i = list.length, array = new Array(i); | ||
while (i--) array[i] = list[i]; | ||
return array; | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
import "array"; | ||
import "date"; | ||
import "style"; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,23 @@ | ||
import "../core/document"; | ||
|
||
try { | ||
d3_document.createElement("div").style.setProperty("opacity", 0, ""); | ||
} catch (error) { | ||
var d3_element_prototype = d3_window.Element.prototype, | ||
d3_element_setAttribute = d3_element_prototype.setAttribute, | ||
d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, | ||
d3_style_prototype = d3_window.CSSStyleDeclaration.prototype, | ||
d3_style_setProperty = d3_style_prototype.setProperty; | ||
d3_element_prototype.setAttribute = function(name, value) { | ||
d3_element_setAttribute.call(this, name, value + ""); | ||
}; | ||
d3_element_prototype.setAttributeNS = function(space, local, value) { | ||
d3_element_setAttributeNS.call(this, space, local, value + ""); | ||
}; | ||
d3_style_prototype.setProperty = function(name, value, priority) { | ||
d3_style_setProperty.call(this, name, value + "", priority); | ||
}; | ||
// Redefine style.setProperty et al. if the browser doesn’t coerce arguments. | ||
if (d3_document) { | ||
try { | ||
d3_document.createElement("DIV").style.setProperty("opacity", 0, ""); | ||
} catch (error) { | ||
var d3_element_prototype = this.Element.prototype, | ||
d3_element_setAttribute = d3_element_prototype.setAttribute, | ||
d3_element_setAttributeNS = d3_element_prototype.setAttributeNS, | ||
d3_style_prototype = this.CSSStyleDeclaration.prototype, | ||
d3_style_setProperty = d3_style_prototype.setProperty; | ||
d3_element_prototype.setAttribute = function(name, value) { | ||
d3_element_setAttribute.call(this, name, value + ""); | ||
}; | ||
d3_element_prototype.setAttributeNS = function(space, local, value) { | ||
d3_element_setAttributeNS.call(this, space, local, value + ""); | ||
}; | ||
d3_style_prototype.setProperty = function(name, value, priority) { | ||
d3_style_setProperty.call(this, name, value + "", priority); | ||
}; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,9 @@ | ||
import "array"; | ||
var d3_document = this.document; | ||
|
||
var d3_document = document, | ||
d3_documentElement = d3_document.documentElement, | ||
d3_window = window; | ||
function d3_documentElement(node) { | ||
return node && node.ownerDocument.documentElement; | ||
} | ||
|
||
// Redefine d3_array if the browser doesn’t support slice-based conversion. | ||
try { | ||
d3_array(d3_documentElement.childNodes)[0].nodeType; | ||
} catch(e) { | ||
d3_array = function(list) { | ||
var i = list.length, array = new Array(i); | ||
while (i--) array[i] = list[i]; | ||
return array; | ||
}; | ||
function d3_window(node) { | ||
return node && node.ownerDocument.defaultView; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.