browser-module-sandbox
Advanced tools
Comparing version 1.1.0 to 1.2.0
20
index.js
@@ -27,3 +27,2 @@ var inherits = require('inherits') | ||
var modules = detective(entry) | ||
self.emit('modules', modules) | ||
@@ -44,2 +43,4 @@ var body = { | ||
if (modules.length === 0) return makeIframe(entry) | ||
request({method: "POST", body: body, url: this.cdn + '/multi', json: true}, function(err, resp, json) { | ||
@@ -52,18 +53,25 @@ if (err) { | ||
var allBundles = '' | ||
var packages = [] | ||
Object.keys(json).map(function(module) { | ||
allBundles += json[module] | ||
allBundles += json[module]['bundle'] | ||
packages.push(json[module]['package']) | ||
}) | ||
self.emit('modules', packages) | ||
makeIframe(allBundles + entry) | ||
}) | ||
function makeIframe(script) { | ||
// setTimeout is because iframes report inaccurate window.innerWidth/innerHeight, even after DOMContentLoaded! | ||
var body = self.iframeBody + | ||
'<script type="text/javascript"> setTimeout(function(){' + | ||
allBundles + | ||
entry + | ||
script + | ||
'}, 0)</script>' | ||
var html = { head: self.iframeHead + self.iframeStyle, body: body } | ||
var html = { head: self.iframeHead + self.iframeStyle, body: body, script: script } | ||
self.iframe.setHTML(html) | ||
self.emit('bundleEnd', html) | ||
}) | ||
} | ||
} | ||
inherits(Sandbox, events.EventEmitter) |
{ | ||
"name": "browser-module-sandbox", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "uses browserify-cdn to run node code in an iframe", | ||
@@ -5,0 +5,0 @@ "repository": { |
@@ -18,4 +18,6 @@ # browser-module-sandbox | ||
## sandbox(options) | ||
## initialize | ||
### sandbox(options) | ||
```javascript | ||
@@ -31,3 +33,12 @@ var sandbox = sandbox({ | ||
``` | ||
## bundling | ||
### sandbox.bundle(entry, preferredVersions) | ||
``` | ||
sandbox.bundle('console.log(require("underscore"))', {'underscore': '1.3.3'}) | ||
``` | ||
`preferredVersions` is optional, version will otherwise default to `latest` | ||
## events | ||
@@ -34,0 +45,0 @@ |
4043
60
58