forked from d3/d3
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix d3.select(document) and d3.select(object).
Also add tests for d3_documentElement and d3_window so that they work for the three cases we care about: a node, a document and a window. For anything else they return undefined.
- Loading branch information
Showing
12 changed files
with
95 additions
and
14 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,6 +1,6 @@ | ||
{ | ||
"name": "d3", | ||
"version": "3.5.4", | ||
"version": "3.5.5", | ||
"main": "d3.js", | ||
"scripts": [ | ||
"d3.js" | ||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
var d3_document = this.document; | ||
|
||
function d3_documentElement(node) { | ||
return node && (node.ownerDocument || node.document).documentElement; | ||
return node | ||
&& (node.ownerDocument // node is a Node | ||
|| node.document // node is a Window | ||
|| node).documentElement; // node is a Document | ||
} | ||
|
||
function d3_window(node) { | ||
return node && node.ownerDocument ? node.ownerDocument.defaultView : node; | ||
return node | ||
&& ((node.ownerDocument && node.ownerDocument.defaultView) // node is a Node | ||
|| (node.document && node) // node is a Window | ||
|| node.defaultView); // node is a 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
!function(){ | ||
var d3 = {version: "3.5.4"}; // semver | ||
var d3 = {version: "3.5.5"}; // semver |
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,50 @@ | ||
var vows = require("vows"), | ||
load = require("../load"), | ||
assert = require("../assert"); | ||
|
||
var suite = vows.describe("document"); | ||
|
||
suite.addBatch({ | ||
"d3_documentElement": { | ||
topic: load("core/document").document().expression("{document:document,window:window,d3_documentElement:d3_documentElement}"), | ||
"the document element exists": function(_) { | ||
assert.strictEqual(_.document.documentElement.nodeType, 1); | ||
assert.strictEqual(_.document.documentElement.nodeName, "HTML"); | ||
assert.strictEqual(_.document.defaultView, _.window); | ||
}, | ||
"given a node, returns the node’s document element": function(_) { | ||
assert.strictEqual(_.d3_documentElement(_.document.body), _.document.documentElement); | ||
}, | ||
"given a document, returns the document’s document element": function(_) { | ||
assert.strictEqual(_.d3_documentElement(_.document), _.document.documentElement); | ||
}, | ||
"given a window, returns the window’s document’s document element": function(_) { | ||
assert.strictEqual(_.d3_documentElement(_.window), _.document.documentElement); | ||
}, | ||
"returns undefined for anything else": function(_) { | ||
assert.isUndefined(_.d3_documentElement({})); | ||
} | ||
}, | ||
"d3_window": { | ||
topic: load("core/document").document().expression("{document:document,window:window,d3_window:d3_window}"), | ||
"the document element exists": function(_) { | ||
assert.strictEqual(_.document.documentElement.nodeType, 1); | ||
assert.strictEqual(_.document.documentElement.nodeName, "HTML"); | ||
assert.strictEqual(_.document.defaultView, _.window); | ||
}, | ||
"given a node, returns its owner document’s default view": function(_) { | ||
assert.strictEqual(_.d3_window(_.document.body), _.window); | ||
}, | ||
"given a document, returns its default view": function(_) { | ||
assert.strictEqual(_.d3_window(_.document), _.window); | ||
}, | ||
"given a window, returns the window": function(_) { | ||
assert.strictEqual(_.d3_window(_.window), _.window); | ||
}, | ||
"returns undefined for anything else": function(_) { | ||
assert.isUndefined(_.d3_window({})); | ||
} | ||
} | ||
}); | ||
|
||
suite.export(module); |
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 @@ | ||
var d3 = {version: "0.0.1"}; // semver |