forked from audreyt/ethercalc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
start.html
335 lines (308 loc) · 11.4 KB
/
start.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
<!DOCTYPE html>
<html manifest="manifest.appcache">
<head>
<title>CellMaster</title>
<meta charset="utf-8" />
<meta content="IE=edge" http-equiv="X-UA-Compatible"/>
<script>try { window.history.pushState({}, '', './') } catch (e) {}</script>
<link href="./static/start.css" rel="stylesheet" type="text/css">
<style>
#intro-left h1{background:none;}
h1 {text-align:center;}
h2 {text-align:center;}
p {text-align:center;}
</style>
</head>
<body id="framedpagebody" class="home">
<div id="top">
<div id="topnav_wrap">
<div id="navigation"></div>
</div>
<div id="intro-left">
<h1><a target="_blank" style="border: none" href="https://www.cellmaster.com.au/">CellMaster</a></h1>
<h2>Web apps as simple as spreadsheets.</h2>
<p>Turn a spreadsheet into a web app. Allow your customers to communicate directly with you with minimal fuss! <br/>
Simple to use. Link up an exisiting spreadsheet. Customize the layout.</p>
<p><small><a href="./_new" style="color: #9ac6ff" alt="Create Blank Spreadsheet">Blank spreadsheet</a></small></p>
<div style="text-align:center;" id="intro-links">
<a id="demopadbutton" href="./examples2/appeditor" alt="Live Examples"><span>Live Examples</span></a><br>
<small>No sign-up, start editing instantly</small>
</div>
</div>
</div>
<a href="https://openshift.redhat.com/app/console/application_type/custom?&cartridges[]=nodejs-0.10&initial_git_url=https://github.com/eddyparkinson/cellmaster.git&name=cellmaster&initial_git_branch=website">
<img style="z-order: 9999;
position: absolute; top: 0; right: 0; border: 0"
alt="LAUNCH ON OpenShift" src="http://launch-shifter.rhcloud.com/launch/LAUNCH ON.svg">
</a>
<script src="./static/jszip.js"></script>
<script src="./static/xlsx.js"></script>
<script src="./static/shim.js"></script>
<script src="./static/jquery.js"></script>
<div id="drop">Drop a .csv, .ods, or a .xlsx file here to import it<div
style="display:block;font-size:60%;padding-top:0.5ex"><label style="cursor:pointer"><input type='checkbox' id='rename_sheet' name='rename_sheet'>Rename sheet(s) after upload</label></div></div>
<style>
#drop {
display: block;
clear: both;
margin-top: 40px;
background: #eee;
border:2px dashed #bbb;
-moz-border-radius:5px;
-webkit-border-radius:5px;
border-radius:5px;
padding:20px;
text-align:center;
font:20pt bold,"Vollkorn";color:#bbb
}
</style>
<script>
if (/^(?:www\.)?ethercalc\.(?:org|com)$/.test(location.host)) {
$("head").append("<link rel='stylesheet' type='text/css' href='https://ethercalc.org/log/css/material.min.css' />");
$("#restore").css('visibility', 'visible');
}
var rABS = typeof FileReader !== "undefined" && typeof FileReader.prototype !== "undefined" && typeof FileReader.prototype.readAsBinaryString !== "undefined";
function fixdata(data) {
var o = "", l = 0, w = 10240;
for(; l<data.byteLength/w; ++l)
o+=String.fromCharCode.apply(null,new Uint8Array(data.slice(l*w,l*w+w)));
o+=String.fromCharCode.apply(null, new Uint8Array(data.slice(o.length)));
return o;
}
// cb is typically process_wb
function xlsxworker(data, cb, id) {
var worker = new Worker('./static/xlsxworker.js');
worker.onmessage = function(e) {
switch(e.data.t) {
case 'ready': break;
case 'e': console.error(e.data.d); break;
case 'xlsx': cb(JSON.parse(e.data.d), id); break;
}
};
var arr = rABS ? data : btoa(fixdata(data));
worker.postMessage({d:arr,b:rABS});
}
function get_radio_value( radioName ) {
var radios = document.getElementsByName( radioName );
for( var i = 0; i < radios.length; i++ ) {
if( radios[i].checked ) {
return radios[i].value;
}
}
}
function to_csv(workbook) {
var result = [];
workbook.SheetNames.forEach(function(sheetName) {
var csv = XLSX.utils.sheet_to_csv(workbook.Sheets[sheetName]);
if(csv.length > 0){
result.push("SHEET: " + sheetName);
result.push("");
result = [];
result.push(csv);
}
});
return result.join("\n").replace(/,+\n/g, '\n').replace(/[\s]+$/, '\n');
}
/* xlsx2socialcalc.js (C) 2014 SheetJS -- http://sheetjs.com */
/* License: Apache 2.0 */
/* vim: set ts=2: */
var sheet_to_socialcalc = (function() {
var header = [
"socialcalc:version:1.5",
"MIME-Version: 1.0",
"Content-Type: multipart/mixed; boundary=SocialCalcSpreadsheetControlSave"
].join("\n");
var sep = [
"--SocialCalcSpreadsheetControlSave",
"Content-type: text/plain; charset=UTF-8",
""
].join("\n");
/* TODO: the other parts */
var meta = [
"# SocialCalc Spreadsheet Control Save",
"part:sheet"
].join("\n");
var end = "--SocialCalcSpreadsheetControlSave--";
var scencode = function(s) { return s.replace(/\\/g, "\\b").replace(/:/g, "\\c").replace(/\n/g,"\\n"); }
var scsave = function scsave(ws) {
if(!ws || !ws['!ref']) return "";
var o = [], oo = [], cell, coord;
var r = XLSX.utils.decode_range(ws['!ref']);
for(var R = r.s.r; R <= r.e.r; ++R) {
for(var C = r.s.c; C <= r.e.c; ++C) {
coord = XLSX.utils.encode_cell({r:R,c:C});
if(!(cell = ws[coord]) || cell.v == null) continue;
oo = ["cell", coord, 't'];
switch(cell.t) {
case 's': case 'str': oo.push(scencode(cell.v)); break;
case 'n':
if(cell.f) {
oo[2] = 'vtf';
oo.push('n');
oo.push(cell.v);
oo.push(scencode(cell.f));
}
else {
oo[2] = 'v';
oo.push(cell.v);
} break;
}
o.push(oo.join(":"));
}
}
o.push("sheet:c:" + (r.e.c - r.s.c + 1) + ":r:" + (r.e.r - r.s.r + 1) + ":tvf:1");
o.push("valueformat:1:text-wiki");
o.push("copiedfrom:" + ws['!ref']);
return o.join("\n");
};
return function socialcalcify(ws, opts) {
return [header, sep, meta, sep, scsave(ws), end].join("\n");
//return ["version:1.5", scsave(ws)].join("\n");
};
})();
function process_wb(wb, id) {
var output = "";
if (wb.SheetNames.length > 1) {
var toc = '"#url","#title"\n';
var names = [].concat(wb.SheetNames);
var idx = 0;
var res = [];
var sheetsToIdx = {}
for (var i = 0; i < names.length; i++) {
sheetsToIdx[names[i]] = i+1;
res.push(names[i].replace(/'/g, "''").replace(/(\W)/g, '\\$1'));
}
var step = function(){
if (names.length) {
idx++;
var k = names.shift();
output = sheet_to_socialcalc(wb.Sheets[k]);
toc += '"/' + id + '.' + idx + '",';
toc += '"' + k.replace(/"/g, '""') + '"\n';
output = output.replace(
RegExp('(\'?)\\b(' + res.join('|') + ')\\1!', 'g'),
function(_0, _1, ref){ return "'" + id + "." + sheetsToIdx[ref.replace(/''/g, "'")] + "'!"; }
);
$.ajax({
url: './_/' + id + '.' + idx,
method: 'PUT',
contentType: 'text/x-socialcalc; charset=utf-8',
processData: false,
data: output,
success: function(data, msg, xhr) {
step();
}
});
}
else {
$.ajax({
url: './_/' + id,
method: 'PUT',
contentType: 'text/csv; charset=utf-8',
processData: false,
data: toc,
success: function(data, msg, xhr) {
location.href = './=' + id
}
});
}
};
step();
return;
}
output = sheet_to_socialcalc(wb.Sheets[wb.SheetNames[0]]);
$.ajax({
url: './_/' + id,
method: 'PUT',
contentType: 'text/x-socialcalc; charset=utf-8',
processData: false,
data: output,
success: function(data, msg, xhr) {
location.href = './' + id
}
});
}
function post_csv (csv, id) {
$.ajax({
url: './_/' + id,
method: 'PUT',
contentType: 'text/csv',
processData: false,
data: csv,
success: function(data, msg, xhr) {
location.href = './' + id
}
});
}
var BASE64URICHARS = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz-_'.split('');
function newId (len, radix) {
var chars = BASE64URICHARS, newId = [], i=0;
radix = radix || chars.length;
len = len || 22;
for (i = 0; i < len; i++) newId[i] = chars[0 | Math.random()*radix];
return newId.join('');
};
function get_id(file, checked) {
var id = null;
if (checked) {
id = prompt("Enter a spreadsheet name for " + file + " (alphanumeric only)", "");
id = id.trim().toLowerCase().replace(/\s/g, "_");
}
if (id === null) {
id = newId(10, 36).toLowerCase();
}
return id;
}
var drop = document.getElementById('drop');
var renameSheetCheckbox = document.getElementById('rename_sheet');
function handleDrop(e) {
e.stopPropagation();
e.preventDefault();
var toggle = function(){
$(drop).fadeOut('fast', function(){ $(drop).fadeIn('fast', toggle) });
}
var files = e.dataTransfer.files;
var i,f;
$(drop).text('Working...');
for (i = 0, f = files[i]; i != files.length; ++i) {
var reader = new FileReader();
var name = f.name;
var id = get_id(name, $(renameSheetCheckbox).is(":checked"));
reader.onload = function(e) {
var data = e.target.result;
if (!/^PK\u0003\u0004/.test(data) && /^[^\n]+,(?:[^\n]+)*\n/.test(data)) {
return post_csv(data, id);
}
if(typeof Worker !== 'undefined') {
xlsxworker(data, process_wb, id);
} else {
var wb;
if(rABS) {
wb = XLSX.read(data, {type: 'binary'});
} else {
var arr = fixdata(data);
wb = XLSX.read(btoa(arr), {type: 'base64'});
}
process_wb(wb, id);
}
};
if(rABS) {
reader.readAsBinaryString(f);
} else {
reader.readAsArrayBuffer(f);
}
}
}
function handleDragover(e) {
e.stopPropagation();
e.preventDefault();
e.dataTransfer.dropEffect = 'copy';
}
if(drop.addEventListener) {
drop.addEventListener('dragenter', handleDragover, false);
drop.addEventListener('dragover', handleDragover, false);
drop.addEventListener('drop', handleDrop, false);
}
</script>
</body>
</html>