Skip to content

Commit aaeb4da

Browse files
committed
Merge pull request SheetJS#5 from SheetJS/clean-up
Clean up
2 parents d5d1073 + 2af979a commit aaeb4da

28 files changed

+230
-216
lines changed
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

dropsheet.js renamed to assets/js/dropsheet.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ var DropSheet = function DropSheet(opts) {
2929
function sheetjsw(data, cb, readtype, xls) {
3030
pending = true;
3131
opts.on.workstart();
32-
var worker = new Worker('./sheetjsw.js');
32+
var scripts = document.getElementsByTagName('script');
33+
var dropsheetPath;
34+
for (var i = 0; i < scripts.length; i++) {
35+
if (scripts[i].src.indexOf('dropsheet') != -1) {
36+
dropsheetPath = scripts[i].src.split('dropsheet.js')[0];
37+
}
38+
}
39+
var worker = new Worker(dropsheetPath + 'sheetjsw.js');
3340
worker.onmessage = function(e) {
3441
switch(e.data.t) {
3542
case 'ready': break;
File renamed without changes.

assets/js/main.js

Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
/** drop target **/
2+
var _target = document.getElementById('drop');
3+
4+
/** Spinner **/
5+
var spinner;
6+
7+
var _workstart = function() { spinner = new Spinner().spin(_target); }
8+
var _workend = function() { spinner.stop(); }
9+
10+
/** Alerts **/
11+
var _badfile = function() {
12+
alertify.alert('This file does not appear to be a valid Excel file. If we made a mistake, please send this file to <a href="mailto:dev@sheetjs.com?subject=I+broke+your+stuff">dev@sheetjs.com</a> so we can take a look.', function(){});
13+
};
14+
15+
var _pending = function() {
16+
alertify.alert('Please wait until the current file is processed.', function(){});
17+
};
18+
19+
var _large = function(len, cb) {
20+
alertify.confirm("This file is " + len + " bytes and may take a few moments. Your browser may lock up during this process. Shall we play?", cb);
21+
};
22+
23+
var _failed = function(e) {
24+
console.log(e, e.stack);
25+
alertify.alert('We unfortunately dropped the ball here. We noticed some issues with the grid recently, so please test the file using the direct parsers for <a href="/js-xls/">XLS</a> and <a href="/js-xlsx/">XLSX</a> files. If there are issues with the direct parsers, please send this file to <a href="mailto:dev@sheetjs.com?subject=I+broke+your+stuff">dev@sheetjs.com</a> so we can make things right.', function(){});
26+
};
27+
28+
/** Handsontable magic **/
29+
var boldRenderer = function (instance, td, row, col, prop, value, cellProperties) {
30+
Handsontable.TextCell.renderer.apply(this, arguments);
31+
$(td).css({'font-weight': 'bold'});
32+
};
33+
34+
var $container, $parent, $window, availableWidth, availableHeight;
35+
var calculateSize = function () {
36+
var offset = $container.offset();
37+
availableWidth = Math.max($window.width() - 250,600);
38+
availableHeight = Math.max($window.height() - 250, 400);
39+
};
40+
41+
$(document).ready(function() {
42+
$container = $("#hot"); $parent = $container.parent();
43+
$window = $(window);
44+
$window.on('resize', calculateSize);
45+
});
46+
47+
/* make the buttons for the sheets */
48+
var make_buttons = function(sheetnames, cb) {
49+
var $buttons = $('#buttons');
50+
$buttons.html("");
51+
sheetnames.forEach(function(s,idx) {
52+
var button= $('<button/>').attr({ type:'button', name:'btn' +idx, text:s });
53+
button.append('<h3>' + s + '</h3>');
54+
button.click(function() { cb(idx); });
55+
$buttons.append(button);
56+
$buttons.append('<br/>');
57+
});
58+
};
59+
60+
var _onsheet = function(json, cols, sheetnames, select_sheet_cb) {
61+
$('#footnote').hide();
62+
63+
make_buttons(sheetnames, select_sheet_cb);
64+
calculateSize();
65+
66+
/* add header row for table */
67+
if(!json) json = [];
68+
json.unshift(function(head){var o = {}; for(i=0;i!=head.length;++i) o[head[i]] = head[i]; return o;}(cols));
69+
calculateSize();
70+
/* showtime! */
71+
$("#hot").handsontable({
72+
data: json,
73+
startRows: 5,
74+
startCols: 3,
75+
fixedRowsTop: 1,
76+
stretchH: 'all',
77+
rowHeaders: true,
78+
columns: cols.map(function(x) { return {data:x}; }),
79+
colHeaders: cols,
80+
cells: function (r,c,p) {
81+
if(r === 0) this.renderer = boldRenderer;
82+
},
83+
width: function () { return availableWidth; },
84+
height: function () { return availableHeight; },
85+
stretchH: 'all'
86+
});
87+
};
88+
89+
/** Drop it like it's hot **/
90+
DropSheet({
91+
drop: _target,
92+
on: {
93+
workstart: _workstart,
94+
workend: _workend,
95+
sheet: _onsheet,
96+
foo: 'bar'
97+
},
98+
errors: {
99+
badfile: _badfile,
100+
pending: _pending,
101+
failed: _failed,
102+
large: _large,
103+
foo: 'bar'
104+
}
105+
})
File renamed without changes.
File renamed without changes.
File renamed without changes.

xls.js renamed to assets/js/xls.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

index.html

Lines changed: 88 additions & 186 deletions
Original file line numberDiff line numberDiff line change
@@ -1,189 +1,91 @@
11
<!DOCTYPE html>
22
<html>
3-
<head>
4-
<title>SheetJS Live Grid Demo</title>
5-
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6-
<link rel="icon" type="image/png" href="logo.png" />
7-
<link rel="stylesheet" href="sheetjs.css">
8-
</head>
9-
<body>
10-
<script src="alertify.js"></script>
11-
<script src="hot/jquery.min.js"></script>
12-
<script src="hot/jquery.handsontable.full.js"></script>
13-
<link rel="stylesheet" media="screen" href="hot/jquery.handsontable.full.css">
14-
<link rel="stylesheet" media="screen" href="hot/samples.css">
15-
<link rel="stylesheet" media="screen" href="alertify.css">
16-
17-
<div id="body">
18-
<div id="left">
19-
<div id="logo"><a href="http://sheetjs.com"><img src="logo.png" class="logo" alt="SheetJS Logo" width=128px height=128px /></a></div>
20-
<div id="drop">Drop a file here</div>
21-
<h3> Choose a worksheet:</h3>
22-
<div id="buttons"></div>
23-
</div>
24-
<div id="right">
25-
<div id="header">
26-
<pre id="out"></pre>
27-
<h2>SheetJS In-Browser Live Grid Demo</h2>
28-
<h3>Drop a spreadsheet (XLS/XLSX/XLSM/XLSB/XML) in the box to the left to see a preview.<br/>
29-
Need a file? Why not the <a href="http://www.whitehouse.gov/sites/default/files/omb/budget/fy2014/assets/receipts.xls">OMB FY 2014 Federal Receipts?</a></h3>
30-
<table id="tt">
31-
<tr><td colspan="6"><a href="osstatus.html">SheetJS Libraries</a> (for parsing) and <a href="http://handsontable.com">Handsontable</a> (grid component)</td></tr>
32-
<tr>
33-
<th>XLS/XML</th>
34-
<td><a href="http://github.com/SheetJS/js-xls">Library Source</a></td>
35-
<td><a href="http://SheetJS.github.io/js-xls">Interactive Demo</a></td>
36-
<td><a href="http://npm.im/xlsjs">"xlsjs" on npm</a></td>
37-
<td><a href="https://travis-ci.org/SheetJS/js-xls">node CI status</a></td>
38-
<td><a href="stress.html">browser stress test</a></td>
39-
</tr>
40-
<tr>
41-
<th>XLSX/M/B</th>
42-
<td><a href="http://github.com/SheetJS/js-xlsx">Library Source</a></td>
43-
<td><a href="http://SheetJS.github.io/js-xlsx">Interactive Demo</a></td>
44-
<td><a href="http://npm.im/xlsx">"xlsx" on npm</a></td>
45-
<td><a href="https://travis-ci.org/SheetJS/js-xlsx">node CI status</a></td>
46-
<td><a href="stress.html">browser stress test</a></td>
47-
</tr>
48-
</table>
49-
</div>
50-
<div id="hot" style="overflow: scroll" class="handsontable"></div>
51-
<div id="footnote"><h3>This particular parser assumes that <b>the first row of the table is a header.</b><br/>
52-
For parsing a more general file, check the Interactive Demos</h3><br/>
53-
<h3>The entire process occurs within your browser <br />
54-
<b>NO SPREADSHEET DATA IS SENT TO ANY SERVER (parsing and rendering done in your browser)</b></br>
55-
<h3>This is a work in progress. Every bit helps. Please email <a href="mailto:dev@sheetjs.com">dev@sheetjs.com</a> with your feedback.
56-
<h3>Follow us on Twitter <a href="https://twitter.com/SheetJS">@SheetJS</a></h3>
57-
</div>
58-
</div>
59-
60-
<script src="xls.js"></script>
61-
<script src="jszip.js"></script>
62-
<script src="xlsx.js"></script>
63-
<script src="shim.js"></script>
64-
<script src="others/spin.js"></script>
65-
<script src="dropsheet.js"></script>
66-
67-
<script>
68-
/** drop target **/
69-
var _target = document.getElementById('drop');
70-
71-
/** Spinner **/
72-
var spinner;
73-
74-
var _workstart = function() { spinner = new Spinner().spin(_target); }
75-
var _workend = function() { spinner.stop(); }
76-
77-
/** Alerts **/
78-
var _badfile = function() {
79-
alertify.alert('This file does not appear to be a valid Excel file. If we made a mistake, please send this file to <a href="mailto:dev@sheetjs.com?subject=I+broke+your+stuff">dev@sheetjs.com</a> so we can take a look.', function(){});
80-
};
81-
82-
var _pending = function() {
83-
alertify.alert('Please wait until the current file is processed.', function(){});
84-
};
85-
86-
var _large = function(len, cb) {
87-
alertify.confirm("This file is " + len + " bytes and may take a few moments. Your browser may lock up during this process. Shall we play?", cb);
88-
};
89-
90-
var _failed = function(e) {
91-
console.log(e, e.stack);
92-
alertify.alert('We unfortunately dropped the ball here. We noticed some issues with the grid recently, so please test the file using the direct parsers for <a href="/js-xls/">XLS</a> and <a href="/js-xlsx/">XLSX</a> files. If there are issues with the direct parsers, please send this file to <a href="mailto:dev@sheetjs.com?subject=I+broke+your+stuff">dev@sheetjs.com</a> so we can make things right.', function(){});
93-
};
94-
95-
/** Handsontable magic **/
96-
var boldRenderer = function (instance, td, row, col, prop, value, cellProperties) {
97-
Handsontable.TextCell.renderer.apply(this, arguments);
98-
$(td).css({'font-weight': 'bold'});
99-
};
100-
101-
var $container, $parent, $window, availableWidth, availableHeight;
102-
var calculateSize = function () {
103-
var offset = $container.offset();
104-
availableWidth = Math.max($window.width() - 250,600);
105-
availableHeight = Math.max($window.height() - 250, 400);
106-
};
107-
108-
$(document).ready(function() {
109-
$container = $("#hot"); $parent = $container.parent();
110-
$window = $(window);
111-
$window.on('resize', calculateSize);
112-
});
113-
114-
/* make the buttons for the sheets */
115-
var make_buttons = function(sheetnames, cb) {
116-
var $buttons = $('#buttons');
117-
$buttons.html("");
118-
sheetnames.forEach(function(s,idx) {
119-
var button= $('<button/>').attr({ type:'button', name:'btn' +idx, text:s });
120-
button.append('<h3>' + s + '</h3>');
121-
button.click(function() { cb(idx); });
122-
$buttons.append(button);
123-
$buttons.append('<br/>');
124-
});
125-
};
126-
127-
var _onsheet = function(json, cols, sheetnames, select_sheet_cb) {
128-
$('#footnote').hide();
129-
130-
make_buttons(sheetnames, select_sheet_cb);
131-
calculateSize();
132-
133-
/* add header row for table */
134-
if(!json) json = [];
135-
json.unshift(function(head){var o = {}; for(i=0;i!=head.length;++i) o[head[i]] = head[i]; return o;}(cols));
136-
calculateSize();
137-
/* showtime! */
138-
$("#hot").handsontable({
139-
data: json,
140-
startRows: 5,
141-
startCols: 3,
142-
fixedRowsTop: 1,
143-
stretchH: 'all',
144-
rowHeaders: true,
145-
columns: cols.map(function(x) { return {data:x}; }),
146-
colHeaders: cols,
147-
cells: function (r,c,p) {
148-
if(r === 0) this.renderer = boldRenderer;
149-
},
150-
width: function () { return availableWidth; },
151-
height: function () { return availableHeight; },
152-
stretchH: 'all'
153-
});
154-
};
155-
156-
/** Drop it like it's hot **/
157-
DropSheet({
158-
drop: _target,
159-
on: {
160-
workstart: _workstart,
161-
workend: _workend,
162-
sheet: _onsheet,
163-
foo: 'bar'
164-
},
165-
errors: {
166-
badfile: _badfile,
167-
pending: _pending,
168-
failed: _failed,
169-
large: _large,
170-
foo: 'bar'
171-
}
172-
})
173-
174-
</script>
175-
<script type="text/javascript">
176-
var _gaq = _gaq || [];
177-
_gaq.push(['_setAccount', 'UA-36810333-1']);
178-
_gaq.push(['_setDomainName', 'sheetjs.com']);
179-
_gaq.push(['_setAllowLinker', true]);
180-
_gaq.push(['_trackPageview']);
181-
182-
(function() {
183-
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
184-
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
185-
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
186-
})();
187-
</script>
188-
</body>
3+
<head>
4+
<title>SheetJS Live Grid Demo</title>
5+
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
6+
<link rel="icon" type="image/png" href="assets/img/logo.png" />
7+
<link rel="stylesheet" href="assets/css/sheetjs.css">
8+
</head>
9+
<body>
10+
<script src="assets/vendor/alertify.js"></script>
11+
<script src="assets/vendor/jquery.min.js"></script>
12+
<script src="assets/vendor/jquery.handsontable.full.js"></script>
13+
14+
<link rel="stylesheet" media="screen" href="assets/vendor/jquery.handsontable.full.css">
15+
<link rel="stylesheet" media="screen" href="assets/vendor/samples.css">
16+
<link rel="stylesheet" media="screen" href="assets/vendor/alertify.css">
17+
18+
<div id="body">
19+
<div id="left">
20+
<div id="logo">
21+
<a href="http://sheetjs.com"><img src="assets/img/logo.png" class="logo" alt="SheetJS Logo" width=128px height=128px /></a>
22+
</div>
23+
<div id="drop">Drop a file here</div>
24+
<h3> Choose a worksheet:</h3>
25+
<div id="buttons"></div>
26+
</div>
27+
<div id="right">
28+
<div id="header">
29+
<pre id="out"></pre>
30+
<h2>SheetJS In-Browser Live Grid Demo</h2>
31+
<h3>
32+
Drop a spreadsheet (XLS/XLSX/XLSM/XLSB/XML) in the box to the left to see a preview.<br/>
33+
Need a file? Why not the <a href="http://www.whitehouse.gov/sites/default/files/omb/budget/fy2014/assets/receipts.xls">OMB FY 2014 Federal Receipts?</a>
34+
</h3>
35+
<table id="tt">
36+
<tr><td colspan="6"><a href="osstatus.html">SheetJS Libraries</a> (for parsing) and <a href="http://handsontable.com">Handsontable</a> (grid component)</td></tr>
37+
<tr>
38+
<th>XLS/XML</th>
39+
<td><a href="http://github.com/SheetJS/js-xls">Library Source</a></td>
40+
<td><a href="http://SheetJS.github.io/js-xls">Interactive Demo</a></td>
41+
<td><a href="http://npm.im/xlsjs">"xlsjs" on npm</a></td>
42+
<td><a href="https://travis-ci.org/SheetJS/js-xls">node CI status</a></td>
43+
<td><a href="stress.html">browser stress test</a></td>
44+
</tr>
45+
<tr>
46+
<th>XLSX/M/B</th>
47+
<td><a href="http://github.com/SheetJS/js-xlsx">Library Source</a></td>
48+
<td><a href="http://SheetJS.github.io/js-xlsx">Interactive Demo</a></td>
49+
<td><a href="http://npm.im/xlsx">"xlsx" on npm</a></td>
50+
<td><a href="https://travis-ci.org/SheetJS/js-xlsx">node CI status</a></td>
51+
<td><a href="stress.html">browser stress test</a></td>
52+
</tr>
53+
</table>
54+
</div>
55+
<div id="hot" style="overflow: scroll" class="handsontable"></div>
56+
<div id="footnote">
57+
<h3>
58+
This particular parser assumes that <b>the first row of the table is a header.</b><br/>
59+
For parsing a more general file, check the Interactive Demos
60+
</h3><br/>
61+
<h3>The entire process occurs within your browser <br />
62+
<b>NO SPREADSHEET DATA IS SENT TO ANY SERVER (parsing and rendering done in your browser)</b></br>
63+
<h3>This is a work in progress. Every bit helps. Please email <a href="mailto:dev@sheetjs.com">dev@sheetjs.com</a> with your feedback.
64+
<h3>Follow us on Twitter <a href="https://twitter.com/SheetJS">@SheetJS</a></h3>
65+
</div>
66+
</div>
67+
68+
<script src="assets/js/xls.js"></script>
69+
<script src="assets/js/jszip.js"></script>
70+
<script src="assets/js/xlsx.js"></script>
71+
<script src="assets/js/shim.js"></script>
72+
<script src="assets/js/dropsheet.js"></script>
73+
<script src="assets/js/main.js"></script>
74+
75+
<script src="assets/vendor/spin.js"></script>
76+
77+
<script type="text/javascript">
78+
var _gaq = _gaq || [];
79+
_gaq.push(['_setAccount', 'UA-36810333-1']);
80+
_gaq.push(['_setDomainName', 'sheetjs.com']);
81+
_gaq.push(['_setAllowLinker', true]);
82+
_gaq.push(['_trackPageview']);
83+
84+
(function() {
85+
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
86+
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
87+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
88+
})();
89+
</script>
90+
</body>
18991
</html>

0 commit comments

Comments
 (0)