Skip to content

Commit

Permalink
Merge branch 'fix-d3-global' into 3.4.13
Browse files Browse the repository at this point in the history
  • Loading branch information
mbostock committed Oct 17, 2014
2 parents 4c62314 + 0a412f6 commit 8852a1c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 16 deletions.
26 changes: 10 additions & 16 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
var document = require("jsdom").jsdom("<html><head></head><body></body></html>"),
window = document.parentWindow,
var document = require("jsdom").jsdom(),
globals = {};

// stash globals
// Stash old globals.
if ("d3" in global) globals.d3 = global.d3;
if ("window" in global) globals.window = global.window;
global.window = window;
if ("document" in global) globals.document = global.document;
global.document = document;

// https://github.com/chad3814/CSSStyleDeclaration/issues/3
var CSSStyleDeclaration_prototype = window.CSSStyleDeclaration.prototype,
CSSStyleDeclaration_setProperty = CSSStyleDeclaration_prototype.setProperty;
CSSStyleDeclaration_prototype.setProperty = function(name, value, priority) {
return CSSStyleDeclaration_setProperty.call(this, name + "", value == null ? null : value + "", priority == null ? null : priority + "");
};
// Set temporary globals to pretend we’re in a browser.
global.window = document.parentWindow;
global.document = document;

module.exports = require("./d3");

// restore globals
if ("window" in globals) global.window = globals.window;
else delete global.window;
if ("document" in globals) global.document = globals.document;
else delete global.document;
// Restore old globals.
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;
16 changes: 16 additions & 0 deletions test/index-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
var vows = require("vows"),
assert = require("./assert");

var suite = vows.describe("d3");

require("../");

suite.addBatch({
"d3": {
"is not a global when require’d": function() {
assert.equal("d3" in global, false);
}
}
});

suite.export(module);

0 comments on commit 8852a1c

Please sign in to comment.