aboutsummaryrefslogtreecommitdiff
path: root/lib/browser.js
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2013-04-28 12:38:02 +0100
committerMichael Williamson <mike@zwobble.org>2013-04-28 12:38:02 +0100
commite07b39afe54d744597c32f71fc3191ba1449ab90 (patch)
tree41f8b74cdb24ca4b281e75c8d4d99c302f8d5f02 /lib/browser.js
parent6ed031ebcf38481123ef8be5a7c9c9881cfcd26b (diff)
Allow browser to read separately from HTML generation
Diffstat (limited to 'lib/browser.js')
-rw-r--r--lib/browser.js27
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);