Skip to content

Commit

Permalink
Make require('dc') work in node
Browse files Browse the repository at this point in the history
Fixes problems loading the module in node.
  • Loading branch information
bewest committed Mar 5, 2013
1 parent 52cc6d7 commit 615a3e7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 0 deletions.
9 changes: 9 additions & 0 deletions globals.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
var document = global.document = require("jsdom").jsdom("<html><head></head><body></body></html>"),
window = global.window = document.createWindow();

// 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 + "");
};
18 changes: 18 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
var globals = ["document", "window", "d3"],
globalValues = {};

globals.forEach(function(g) {
if (g in global) globalValues[g] = global[g];
});

require("./globals");
d3 = require("d3");
crossfilter = require("crossfilter");
require("./dc");

module.exports = dc;

globals.forEach(function(g) {
if (g in globalValues) global[g] = globalValues[g];
else delete global[g];
});

0 comments on commit 615a3e7

Please sign in to comment.