diff options
Diffstat (limited to 'lib/browser.js')
| -rw-r--r-- | lib/browser.js | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/lib/browser.js b/lib/browser.js index 2a9c4e1..5a8d70a 100644 --- a/lib/browser.js +++ b/lib/browser.js @@ -2,11 +2,12 @@ var q = require("q"); var mammoth = require("./"); -exports.Converter = mammoth.Converter; -exports.fileInput = fileInput; +module.exports = Object.create(mammoth); -function fileInput(inputElement, callback) { - var converter = new mammoth.Converter(mammoth.standardOptions); +module.exports.fileInput = fileInput; +module.exports.readFileInputOnChange = readFileInputOnChange; + +function readFileInputOnChange(inputElement, callback) { function handleFileSelect(event) { var file = event.target.files[0]; @@ -15,7 +16,7 @@ function fileInput(inputElement, callback) { reader.onload = function(loadEvent) { var arrayBuffer = loadEvent.target.result; try { - converter.convertToHtml({file: openFile(arrayBuffer)}) + mammoth.read({file: openFile(arrayBuffer)}) .then(callback, function(error) { callback({error: error}); }) @@ -30,6 +31,22 @@ function fileInput(inputElement, callback) { inputElement.addEventListener('change', handleFileSelect, false); } +function fileInput(inputElement, callback) { + readFileInputOnChange(inputElement, function(documentResult) { + if (documentResult.error) { + callback(documentResult); + } else { + var options = mammoth.standardOptions; + mammoth.convertDocumentToHtml(documentResult, options) + .then(callback, function(error) { + callback({error: error}); + }) + .done(); + } + + }); +} + function openFile(arrayBuffer) { var zipFile = new JSZip(arrayBuffer); |
