Skip to content

Commit

Permalink
adds support for use as a pouchdb plugin; changed promise definition …
Browse files Browse the repository at this point in the history
…for chrome.
  • Loading branch information
marten-de-vries committed Feb 1, 2015
1 parent bda6758 commit 2935dfb
Show file tree
Hide file tree
Showing 6 changed files with 48 additions and 20 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
node_modules
dist
fauxton/js/pouchdb-offline.js
8 changes: 0 additions & 8 deletions fauxton/js/pouchdb-offline.js

This file was deleted.

31 changes: 31 additions & 0 deletions lib/index-pouchdb-plugin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
var fs = require("fs");

var html = fs.readFileSync(__dirname + "/../fauxton/index.html", {encoding: "UTF-8"});
var scr = fs.readFileSync(__dirname + "/../fauxton/js/require.js", {encoding: "UTF-8"});
scr += fs.readFileSync(__dirname + "/../fauxton/js/pouchdb-offline.js", {encoding: "UTF-8"});
var css = fs.readFileSync(__dirname + "/../fauxton/css/index.css", {encoding: "UTF-8"});

module.exports = function enableFauxton(PouchDB, allDbs) {
var iframe = global.document.createElement("iframe");
document.body.appendChild(iframe);

iframe.onload = function () {
iframe.contentDocument.write(html);
iframe.contentWindow.PouchDB = PouchDB;

var style = iframe.contentDocument.createElement("style");
var script = iframe.contentDocument.createElement("script");

style.appendChild(iframe.contentDocument.createTextNode(css));
script.appendChild(iframe.contentDocument.createTextNode(scr));

iframe.contentDocument.body.appendChild(style);
iframe.contentDocument.body.appendChild(script);
};
iframe.style.width = "90%";
iframe.style.height = "500px";
iframe.style.position = "fixed";
iframe.style.right = "0";
iframe.style.bottom = "0";
iframe.style.border = "3px groove #CBCBCB";
};
2 changes: 1 addition & 1 deletion lib/postmessagerpc.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ is never resolved.
*/

var Promise = Promise || require("lie");
var Promise = global.Promise || require("lie");

function PostMessageRPC(postMessage, thisName) {
this._postMessage = function (msg) {
Expand Down
2 changes: 1 addition & 1 deletion lib/req2resp.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var route = require("pouchdb-route");
var Promise = Promise || require("lie");
var Promise = global.Promise || require("lie");
var uuid = require("random-uuid-v4");

module.exports = function (PouchDB) {
Expand Down
24 changes: 14 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,23 @@
],
"license": "Apache-2.0",
"dependencies": {
"pouchdb": "*",
"lie": "*",
"pouchdb-all-dbs": "*",
"random-uuid-v4": "*",
"pouchdb-route": "*"
"pouchdb": "^3.2.1",
"lie": "^2.6.0",
"pouchdb-all-dbs": "^1.0.1",
"random-uuid-v4": "^0.0.4",
"pouchdb-route": "^1.0.2"
},
"devDependencies": {
"browserify": "^6.1.0"
},
"scripts": {
"build-debug": "browserify lib/index.js -o fauxton/js/pouchdb-offline.js",
"build-debug": "./node_modules/.bin/browserify lib/index.js -o fauxton/js/pouchdb-offline.js",
"build": "npm run build-debug && uglifyjs fauxton/js/pouchdb-offline.js -o fauxton/js/pouchdb-offline.js",
"build-injected": "mkdir -p dist && browserify -x lie lib/index-injected.js -o dist/injected.js",
"build-postmessagerpc": "browserify lib/postmessagerpc.js -x lie --standalone PostMessageRPC -o dist/postmessagerpc.js",
"build-firefox": "browserify lib/index-firefox-addon.js -x lie -o fauxton/js/pouchdb-offline.js && npm run build-injected",
"build-chrome": "browserify lib/index-chrome-extension.js -x lie -o fauxton/js/pouchdb-offline.js && npm run build-injected && npm run build-postmessagerpc",
"build-injected": "mkdir -p dist && ./node_modules/.bin/browserify -x lie lib/index-injected.js -o dist/injected.js",
"build-postmessagerpc": "./node_modules/.bin/browserify lib/postmessagerpc.js -x lie --standalone PostMessageRPC -o dist/postmessagerpc.js",
"build-firefox": "./node_modules/.bin/browserify lib/index-firefox-addon.js -x lie -o fauxton/js/pouchdb-offline.js && npm run build-injected",
"build-chrome": "./node_modules/.bin/browserify lib/index-chrome-extension.js -x lie -o fauxton/js/pouchdb-offline.js && npm run build-injected && npm run build-postmessagerpc",
"build-pouchdb-plugin": "npm run build-debug && ./node_modules/.bin/browserify lib/index-pouchdb-plugin.js -t brfs -s PouchDBFauxton -o dist/pouchdb-plugin.js",
"test": "mocha"
}
}

0 comments on commit 2935dfb

Please sign in to comment.