Skip to content

Commit

Permalink
Pass on browserified inky version
Browse files Browse the repository at this point in the history
  • Loading branch information
kball committed Sep 1, 2016
1 parent 835c6e3 commit 08b5ec3
Show file tree
Hide file tree
Showing 5 changed files with 27,511 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/node_modules
*.DS_Store
test/fixtures/_build
*.swp
39 changes: 39 additions & 0 deletions bin/inky-browser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
var cheerio = require('cheerio');
var Inky = require('../lib/inky');

var inky;

var setupInky = function(opts, cb) {
opts = opts || {};
opts.cheerio = Inky.mergeCheerioOpts(opts.cheerio);
if (typeof inky === 'undefined') {
inky = new Inky(opts);
}

// This transform function takes in an element and calls a callback.
function transform(html, callback) {
var convertedHtml = inky.releaseTheKraken(html, opts.cheerio);
callback(null, convertedHtml);
}

cb(transform);
}

if(typeof(window) !== 'undefined') {
window.runInky = function(opts, elem) {
if(typeof(elem) === 'undefined') {
elem = opts;
opts = {};
}
setupInky(opts, function(transform) {
transform(elem.outerHTML, function(err, html) {
if(err === null) {
elem.outerHTML = html;
} else {
console.log(err);
}
});
});
}
}

Loading

0 comments on commit 08b5ec3

Please sign in to comment.