Permalink
Browse files

web worker

  • Loading branch information...
1 parent f8451d6 commit 1939b00fead792e9ac48337271d0f4d2df72b198 @SheetJSDev SheetJSDev committed Nov 22, 2013
Showing with 4,911 additions and 5 deletions.
  1. +5 −0 Makefile
  2. +21 −5 index.html
  3. +10 −0 misc/worker.js
  4. +4,875 −0 xlsworker.js
View
@@ -1,5 +1,10 @@
DEPS=$(wildcard bits/*.js)
TARGET=xls.js
+WORKER=xlsworker.js
+
+$(WORKER): $(TARGET) misc/worker.js
+ cat $^ > $@
+
$(TARGET): $(DEPS)
cat $^ > $@
View
@@ -27,6 +27,18 @@
<br />
<script src="xls.js"></script>
<script>
+function xlsworker(data, cb) {
+ var worker = new Worker('./xlsworker.js');
+ worker.onmessage = function(e) {
+ switch(e.data.t) {
+ case 'ready': break;
+ case 'e': console.error(e.data.d);
+ case 'xls': cb(e.data.d); break;
+ }
+ };
+ worker.postMessage(data);
+}
+
function get_radio_value( radioName ) {
var radios = document.getElementsByName( radioName );
for( var i = 0; i < radios.length; i++ ) {
@@ -107,11 +119,15 @@
var name = f.name;
reader.onload = function(e) {
var data = e.target.result;
- var cfb = XLS.CFB.read(data, {type: 'binary'});
- //var arr = String.fromCharCode.apply(null, new Uint8Array(data));
- //var cfb = XLS.CFB.read(btoa(arr), {type: 'base64'});
- var wb = XLS.parse_xlscfb(cfb);
- process_wb(wb);
+ if(typeof Worker !== 'undefined') {
+ xlsworker(data, process_wb);
+ } else {
+ var cfb = XLS.CFB.read(data, {type: 'binary'});
+ //var arr = String.fromCharCode.apply(null, new Uint8Array(data));
+ //var cfb = XLS.CFB.read(btoa(arr), {type: 'base64'});
+ var wb = XLS.parse_xlscfb(cfb);
+ process_wb(wb);
+ }
};
reader.readAsBinaryString(f);
//reader.readAsArrayBuffer(f);
View
@@ -0,0 +1,10 @@
+postMessage({t:"ready"});
+
+onmessage = function (oEvent) {
+ var v, cfb;
+ try {
+ cfb = XLS.CFB.read(oEvent.data, {type:"binary"});
+ v = XLS.parse_xlscfb(cfb);
+ } catch(e) { postMessage({t:"e",d:e.stack}); }
+ postMessage({t:"xls", d:v});
+};
Oops, something went wrong.

0 comments on commit 1939b00

Please sign in to comment.