forked from audreyt/ethercalc
-
Notifications
You must be signed in to change notification settings - Fork 5
/
player.js
533 lines (533 loc) · 25.3 KB
/
player.js
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
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
// Generated by LiveScript 1.5.0
(function(){
this.include = function(){
return this.client({
'/player/main.js': function(){
var $, doPlay, onReady, onLoad, ref$, this$ = this;
$ = window.jQuery || window.$;
if (!$) {
return location.reload();
}
doPlay = function(){
var requestParams, ref$, endpoint, ref1$, ref2$, ref3$, options, showError, x$, ref4$, emit;
window.SocialCalc == null && (window.SocialCalc = {});
SocialCalc._username = Math.random().toString();
SocialCalc.isConnected = true;
requestParams = SocialCalc.requestParams;
if (requestParams['auth'] != null) {
SocialCalc._auth = requestParams['auth'];
}
if (requestParams['app'] != null) {
SocialCalc._app = true;
}
if (requestParams['view'] != null) {
SocialCalc._view = true;
}
SocialCalc._room == null && (SocialCalc._room = ((ref$ = window.EtherCalc) != null ? ref$._room : void 8) || window.location.hash.replace('#', ''));
SocialCalc._room = (SocialCalc._room + "").replace(/^_+/, '').replace(/\?.*/, '');
endpoint = (ref1$ = $('script[src*="/socket.io/socket.io.js"]')) != null ? (ref2$ = ref1$.attr('src')) != null ? ref2$.replace(/\.?\/socket.io\/socket.io.js.*/, '') : void 8 : void 8;
if (endpoint === '') {
endpoint = location.pathname.replace(/\/(view|edit)$/, '');
endpoint = endpoint.replace(RegExp('' + SocialCalc._room + '$'), '');
}
if ((ref3$ = window.Drupal) != null && ref3$.sheetnode) {
if (/overlay=node\/\d+/.test(window.location.hash)) {
SocialCalc._room = window.location.hash.match(/=node\/(\d+)/)[1];
} else if (/\/node\/\d+/.test(window.location.href)) {
SocialCalc._room = window.location.href.match(/\/node\/(\d+)/)[1];
}
} else if (SocialCalc._room) {
if (!SocialCalc.CurrentSpreadsheetControlObject) {
setTimeout(function(){
window.history.pushState({}, '', "./" + SocialCalc._room + (function(){
switch (false) {
case !SocialCalc._app:
return '/app';
case !SocialCalc._view:
return '/view';
case !SocialCalc._auth:
return '/edit';
default:
return '';
}
}()));
if (/^(?:www\.)?ethercalc\.(?:org|com)$/.exec(location.host)) {
return $('<a />', {
id: "restore",
target: "_blank",
href: "https://ethercalc.org/log/?" + SocialCalc._room,
title: "View & Restore Backups"
}).text("↻").appendTo('body');
}
}, 100);
}
} else {
window.location = './_start';
return;
}
options = {
'connect timeout': 1500,
reconnect: true,
'reconnection delay': 500,
'max reconnection attempts': 1800
};
if (endpoint) {
options.path = endpoint.replace(/\/?$/, '/socket.io');
}
showError = function(it){
if (typeof vex != 'undefined' && vex !== null) {
vex.closeAll();
}
if (typeof vex != 'undefined' && vex !== null) {
vex.defaultOptions.className = 'vex-theme-flat-attack';
}
return typeof vex != 'undefined' && vex !== null ? vex.dialog.open({
message: it,
buttons: []
}) : void 8;
};
window.addEventListener('offline', function(){
return showError('Disconnected from server. please check network connection and refresh.');
});
x$ = (ref4$ = this$.connect(window.location.origin + ':8000/', options)) != null ? ref4$.io : void 8;
if (x$ != null) {
x$.on('reconnect', function(){
if (!((typeof SocialCalc != 'undefined' && SocialCalc !== null) && SocialCalc.isConnected)) {
return;
}
return SocialCalc.Callbacks.broadcast('ask.log');
});
}
if (x$ != null) {
x$.on('connect_error', function(){
return showError('Connection error; please refresh to try again.');
});
}
if (x$ != null) {
x$.on('connect_timeout', function(){
return showError('Connection timeout; please refresh to try again.');
});
}
if (x$ != null) {
x$.on('reconnect_error', function(){
if (!((typeof SocialCalc != 'undefined' && SocialCalc !== null) && SocialCalc.isConnected)) {
return;
}
SocialCalc.hadSnapshot = false;
return showError('Disconnected from server. Reconnecting....');
});
}
if (x$ != null) {
x$.on('connect_failed', function(){
return showError('Reconnection Failed.');
});
}
emit = function(data){
return this$.emit({
data: data
});
};
SocialCalc.Callbacks.broadcast = function(type, data){
data == null && (data = {});
if (!SocialCalc.isConnected) {
return;
}
data.user = SocialCalc._username;
if (data.room == null) {
data.room = SocialCalc._room;
}
data.type = type;
if (SocialCalc._auth) {
data.auth = SocialCalc._auth;
}
return emit(data);
};
SocialCalc.isConnected = true;
SocialCalc.RecalcInfo.LoadSheetCache = {};
SocialCalc.RecalcInfo.LoadSheet = function(ref){
if (/[^.=_a-zA-Z0-9]/.exec(ref)) {
return;
}
ref = ref.toLowerCase();
return emit({
type: 'ask.recalc',
user: SocialCalc._username,
room: ref
});
};
return this$.on({
data: function(){
var ss, ref$, ref1$, editor, user, ref2$, ecell, peerClass, find, cr, cell, origCR, origCell, ref3$, parts, cmdstr, line, refreshCmd, sheetdata, ref4$;
if (!((typeof SocialCalc != 'undefined' && SocialCalc !== null) && SocialCalc.isConnected)) {
return;
}
if (this.data.user === SocialCalc._username && this.data.room === SocialCalc._room) {
return;
}
if (this.data.to && this.data.to !== SocialCalc._username) {
return;
}
ss = window.spreadsheet;
if (!ss) {
return;
}
if (this.data.room && this.data.room !== SocialCalc._room && ((ref$ = ss.formDataViewer) != null ? ref$._room : void 8) !== this.data.room && this.data.type === "log") {
return;
}
if (this.data.room && this.data.room !== SocialCalc._room && this.data.type !== "recalc" && this.data.type !== "log") {
if (((ref1$ = ss.formDataViewer) != null ? ref1$._room : void 8) !== this.data.room) {
return;
}
ss = ss.formDataViewer;
}
editor = ss.editor;
switch (this.data.type) {
case 'confirmemailsent':
SocialCalc.EditorSheetStatusCallback(null, "confirmemailsent", this.data.message, editor);
break;
case 'chat':
if (typeof window.addmsg == 'function') {
window.addmsg(this.data.msg);
}
break;
case 'ecells':
if (SocialCalc._app) {
break;
}
for (user in ref2$ = this.data.ecells) {
ecell = ref2$[user];
if (user === SocialCalc._username) {
continue;
}
peerClass = " " + user + " defaultPeer";
find = new RegExp(peerClass, 'g');
cr = SocialCalc.coordToCr(ecell);
cell = SocialCalc.GetEditorCellElement(editor, cr.row, cr.col);
if ((cell != null ? cell.element.className.search(find) : void 8) === -1) {
cell.element.className += peerClass;
}
}
break;
case 'ecell':
peerClass = " " + this.data.user + " defaultPeer";
find = new RegExp(peerClass, 'g');
if (this.data.original) {
origCR = SocialCalc.coordToCr(this.data.original);
origCell = SocialCalc.GetEditorCellElement(editor, origCR.row, origCR.col);
if (origCell != null) {
origCell.element.className = origCell.element.className.replace(find, '');
}
if (this.data.original === editor.ecell.coord || this.data.ecell === editor.ecell.coord) {
SocialCalc.Callbacks.broadcast('ecell', {
to: this.data.user,
ecell: editor.ecell.coord
});
}
}
if (SocialCalc._app) {
break;
}
cr = SocialCalc.coordToCr(this.data.ecell);
cell = SocialCalc.GetEditorCellElement(editor, cr.row, cr.col);
if ((cell != null ? (ref2$ = cell.element) != null ? ref2$.className.search(find) : void 8 : void 8) === -1) {
cell.element.className += peerClass;
}
break;
case 'ask.ecell':
if (SocialCalc._app) {
break;
}
SocialCalc.Callbacks.broadcast('ecell', {
to: this.data.user,
ecell: editor.ecell.coord
});
break;
case 'log':
ss = window.spreadsheet;
if (typeof vex != 'undefined' && vex !== null) {
vex.closeAll();
}
if (((ref3$ = ss.formDataViewer) != null ? ref3$._room : void 8) === this.data.room) {
if (this.data.snapshot) {
parts = ss.DecodeSpreadsheetSave(this.data.snapshot);
}
ss.formDataViewer.sheet.ResetSheet();
ss.formDataViewer.loaded = true;
SocialCalc.Callbacks.broadcast('ask.log');
if (parts != null && parts.sheet) {
ss.formDataViewer.ParseSheetSave(this.data.snapshot.substring(parts.sheet.start, parts.sheet.end));
ss.formDataViewer.context.sheetobj.ScheduleSheetCommands("recalc\n", false, true);
}
break;
}
if (SocialCalc.hadSnapshot) {
break;
}
SocialCalc.hadSnapshot = true;
if (this.data.snapshot) {
parts = ss.DecodeSpreadsheetSave(this.data.snapshot);
}
if (parts != null) {
if (parts.sheet) {
ss.sheet.ResetSheet();
ss.ParseSheetSave(this.data.snapshot.substring(parts.sheet.start, parts.sheet.end));
}
if (parts.edit) {
ss.editor.LoadEditorSettings(this.data.snapshot.substring(parts.edit.start, parts.edit.end));
}
}
if (typeof window.addmsg == 'function') {
window.addmsg(this.data.chat.join('\n'), true);
}
cmdstr = (function(){
var i$, ref$, len$, results$ = [];
for (i$ = 0, len$ = (ref$ = this.data.log).length; i$ < len$; ++i$) {
line = ref$[i$];
if (!/^re(calc|display)$/.test(line)) {
results$.push(line);
}
}
return results$;
}.call(this)).join('\n');
if (cmdstr.length) {
refreshCmd = 'recalc';
ss.context.sheetobj.ScheduleSheetCommands(cmdstr + "\n" + refreshCmd + "\n", false, true);
} else {
ss.context.sheetobj.ScheduleSheetCommands("recalc\n", false, true);
}
break;
case 'snapshot':
if (typeof vex != 'undefined' && vex !== null) {
vex.closeAll();
}
SocialCalc.hadSnapshot = true;
if (this.data.snapshot) {
parts = ss.DecodeSpreadsheetSave(this.data.snapshot);
}
if (parts != null && parts.sheet) {
ss.sheet.ResetSheet();
ss.ParseSheetSave(this.data.snapshot.substring(parts.sheet.start, parts.sheet.end));
ss.context.sheetobj.ScheduleSheetCommands("recalc\n", false, true);
}
break;
case 'recalc':
if (this.data.force) {
delete SocialCalc.Formula.SheetCache.sheets[this.data.room];
if (ss != null) {
ss.sheet.recalconce = true;
}
}
if (this.data.snapshot) {
parts = ss.DecodeSpreadsheetSave(this.data.snapshot);
}
if (parts != null && parts.sheet) {
sheetdata = this.data.snapshot.substring(parts.sheet.start, parts.sheet.end);
SocialCalc.RecalcLoadedSheet(this.data.room, sheetdata, true);
if (SocialCalc.RecalcInfo.LoadSheetCache[this.data.room] !== sheetdata) {
SocialCalc.RecalcInfo.LoadSheetCache[this.data.room] = sheetdata;
ss.context.sheetobj.ScheduleSheetCommands("recalc\n", false, true);
}
} else {
SocialCalc.RecalcLoadedSheet(this.data.room, '', true);
}
break;
case 'execute':
ss.context.sheetobj.ScheduleSheetCommands(this.data.cmdstr, this.data.saveundo, true);
if (ss.currentTab === ((ref4$ = ss.tabnums) != null ? ref4$.graph : void 8)) {
setTimeout(function(){
return window.DoGraph(false, false);
}, 100);
}
break;
case 'stopHuddle':
$('#content').uiDisable();
alert("[Collaborative Editing Session Completed]\n\nThank you for your participation.\n\nCheck the activity stream to see the newly edited page!");
window.onunload = null;
window.onbeforeunload = null;
window.location = '/';
break;
case 'error':
if (typeof vex != 'undefined' && vex !== null) {
vex.closeAll();
}
if (typeof vex != 'undefined' && vex !== null) {
vex.defaultOptions.className = 'vex-theme-flat-attack';
}
if (typeof vex != 'undefined' && vex !== null) {
vex.dialog.open({
message: this.data.message,
buttons: [$.extend({}, typeof vex != 'undefined' && vex !== null ? vex.dialog.buttons.YES : void 8, {
text: 'Return to ready-only mode',
click: function(){
return location.href = "../" + SocialCalc._room;
}
})]
});
}
}
}
});
};
window.doresize = function(){
var ref$;
if ((ref$ = window.spreadsheet) != null) {
ref$.DoOnResize();
}
};
onReady = function(){
var ref$, ref1$, ref2$, $container, ref3$;
if (!((ref$ = window.Drupal) != null && ((ref1$ = ref$.sheetnode) != null && ((ref2$ = ref1$.sheetviews) != null && ref2$.length)))) {
return onLoad();
}
$container = (ref3$ = window.Drupal) != null ? ref3$.sheetnode.sheetviews[0].$container : void 8;
return $container.bind('sheetnodeReady', function(_, arg$){
var spreadsheet;
spreadsheet = arg$.spreadsheet;
if (spreadsheet.tabbackground === 'display:none;') {
if (spreadsheet.InitializeSpreadsheetControl) {
return;
}
SocialCalc._auth = '0';
}
return onLoad(spreadsheet);
});
};
$(function(){
return setTimeout(onReady, 1);
});
onLoad = function(ssInstance){
var ss, ref$, ref1$, ref2$, ref3$;
ssInstance == null && (ssInstance = SocialCalc.CurrentSpreadsheetControlObject);
window.spreadsheet = ss = ssInstance || (SocialCalc._view || SocialCalc._app
? new SocialCalc.SpreadsheetViewer()
: new SocialCalc.SpreadsheetControl());
if (window.GraphOnClick == null) {
SocialCalc.Callbacks.broadcast('ask.log');
return;
}
ss.ExportCallback = function(s){
return alert(SocialCalc.ConvertSaveToOtherFormat(SocialCalc.Clipboard.clipboard, "csv"));
};
SocialCalc.Constants.s_loc_form = "Form";
if (ss.tabs) {
ss.tabnums.form = ss.tabs.length;
}
if ((ref$ = ss.tabs) != null) {
ref$.push({
name: 'form',
text: SocialCalc.Constants.s_loc_form,
html: "<div id=\"%id.formtools\" style=\"display:none;\"><div style=\"%tbt.\"><table cellspacing=\"0\" cellpadding=\"0\">\n<tr><td style=\"vertical-align:middle;padding-right:32px;padding-left:16px;\"><div style=\"%tbt.\">\n<input type=\"button\" value=\"Live Form\" onclick=\"parent.location='" + SocialCalc._room + "/form'\" style=\"background-color: #5cb85c;border-color: #4cae4c;cursor: pointer;\"> " + document.location.origin + "/" + SocialCalc._room + "/form </div></td>\n</tr></table></div></div>",
view: 'sheet',
onclick: null,
onclickFocus: true
});
}
if (ss.tabs) {
ss.tabnums.graph = ss.tabs.length;
}
if ((ref1$ = ss.tabs) != null) {
ref1$.push({
name: 'graph',
text: SocialCalc.Constants.s_loc_graph,
html: "<div id=\"%id.graphtools\" style=\"display:none;\"><div style=\"%tbt.\"><table cellspacing=\"0\" cellpadding=\"0\"><tr><td style=\"vertical-align:middle;padding-right:32px;padding-left:16px;\"><div style=\"%tbt.\">Cells to Graph</div><div id=\"%id.graphrange\" style=\"font-weight:bold;\">Not Set</div></td><td style=\"vertical-align:top;padding-right:32px;\"><div style=\"%tbt.\">Set Cells To Graph</div><select id=\"%id.graphlist\" size=\"1\" onfocus=\"%s.CmdGotFocus(this);\"><option selected>[select range]</option><option>Select all</option></select></td><td style=\"vertical-align:middle;padding-right:4px;\"><div style=\"%tbt.\">Graph Type</div><select id=\"%id.graphtype\" size=\"1\" onchange=\"window.GraphChanged(this);\" onfocus=\"%s.CmdGotFocus(this);\"></select><input type=\"button\" value=\"OK\" onclick=\"window.GraphSetCells();\" style=\"font-size:x-small;\"></div></td><td style=\"vertical-align:middle;padding-right:16px;\"><div style=\"%tbt.\"> </div><input id=\"%id.graphhelp\" type=\"button\" onclick=\"DoGraph(true);\" value=\"Help\" style=\"font-size:x-small;\"></div></td><td style=\"vertical-align:middle;padding-right:16px;\">Min X <input id=\"%id.graphMinX\" onchange=\"window.MinMaxChanged(this,0);\" onfocus=\"%s.CmdGotFocus(this);\" size=5/>Max X <input id=\"%id.graphMaxX\" onchange=\"window.MinMaxChanged(this,1);\" onfocus=\"%s.CmdGotFocus(this);\" size=5/><br/>Min Y <input id=\"%id.graphMinY\" onchange=\"window.MinMaxChanged(this,2);\" onfocus=\"%s.CmdGotFocus(this);\" size=5/>Max Y <input id=\"%id.graphMaxY\" onchange=\"window.MinMaxChanged(this,3);\" onfocus=\"%s.CmdGotFocus(this);\" size=5/></div></td></tr></table></div></div>",
view: 'graph',
onclick: window.GraphOnClick,
onclickFocus: true
});
}
if ((ref2$ = ss.views) != null) {
ref2$.graph = {
name: 'graph',
divStyle: "overflow:auto;",
values: {},
html: '<div style="padding:6px;">Graph View</div>'
};
}
if ((ref3$ = ss.editor) != null) {
ref3$.SettingsCallbacks.graph = {
save: window.GraphSave,
load: window.GraphLoad
};
}
ss.sheet.cells["A1"] = new SocialCalc.Cell("A1");
ss.sheet.cells["A1"].displaystring = '<div class="loader"></div>';
if (typeof ss.InitializeSpreadsheetViewer == 'function') {
ss.InitializeSpreadsheetViewer('tableeditor', 0, 0, 0);
}
if (typeof ss.InitializeSpreadsheetControl == 'function') {
ss.InitializeSpreadsheetControl('tableeditor', 0, 0, 0);
}
if (SocialCalc._view == null && ss.formDataViewer != null) {
ss.formDataViewer.sheet._room = ss.formDataViewer._room = SocialCalc._room + "_formdata";
SocialCalc.Callbacks.broadcast('ask.log', {
room: ss.formDataViewer._room
});
} else {
SocialCalc.Callbacks.broadcast('ask.log');
}
if (typeof ss.ExecuteCommand == 'function') {
ss.ExecuteCommand('redisplay', '');
}
if (typeof ss.ExecuteCommand == 'function') {
ss.ExecuteCommand('set sheet defaulttextvalueformat text-wiki');
}
$(document).on('mouseover', '.te_download tr:nth-child(2) td:first', function(){
return $(this).attr({
title: 'Export...'
});
});
return $(document).on('click', '.te_download tr:nth-child(2) td:first', function(){
var isMultiple;
if ((typeof vex != 'undefined' && vex !== null) && vex.dialog.open) {
SocialCalc.Keyboard.passThru = true;
}
isMultiple = window.__MULTI__ || /\.[1-9]\d*$/.exec(SocialCalc._room);
if (typeof vex != 'undefined' && vex !== null) {
vex.defaultOptions.className = 'vex-theme-flat-attack';
}
return typeof vex != 'undefined' && vex !== null ? vex.dialog.open({
message: "Please choose an export format." + (isMultiple ? "<br><small>(EXCEL supports multiple sheets.)</small>" : ""),
callback: function(){
return SocialCalc.Keyboard.passThru = false;
},
buttons: [
$.extend({}, typeof vex != 'undefined' && vex !== null ? vex.dialog.buttons.YES : void 8, {
text: 'Excel',
click: function(){
if (isMultiple) {
if (window.parent.location.href.match(/(^.*\/=[^?/]+)/)) {
return window.open(RegExp.$1 + ".xlsx");
} else {
return window.open("." + (window.parent.location.pathname.match('/.*/view$') || window.parent.location.pathname.match('/.*/edit$') ? '.' : '') + "/=" + SocialCalc._room.replace(/\.[1-9]\d*$/, '') + ".xlsx");
}
} else {
return window.open("." + (window.parent.location.pathname.match('/.*/view$') || window.parent.location.pathname.match('/.*/edit$') ? '.' : '') + "/" + SocialCalc._room + ".xlsx");
}
}
}), $.extend({}, typeof vex != 'undefined' && vex !== null ? vex.dialog.buttons.YES : void 8, {
text: 'CSV',
click: function(){
return window.open("." + (window.parent.location.pathname.match('/.*/view$') || window.parent.location.pathname.match('/.*/edit$') ? '.' : '') + "/" + SocialCalc._room + ".csv");
}
}), $.extend({}, typeof vex != 'undefined' && vex !== null ? vex.dialog.buttons.YES : void 8, {
text: 'HTML',
click: function(){
return window.open("." + (window.parent.location.pathname.match('/.*/view$') || window.parent.location.pathname.match('/.*/edit$') ? '.' : '') + "/" + SocialCalc._room + ".html");
}
}), $.extend({}, typeof vex != 'undefined' && vex !== null ? vex.dialog.buttons.NO : void 8, {
text: 'Cancel'
})
]
}) : void 8;
});
};
if ((ref$ = window.Document) != null && ref$.Parser) {
SocialCalc.Callbacks.expand_wiki = function(val){
return "<div class=\"wiki\">" + new Document.Parser.Wikitext().parse(val, new Document.Emitter.HTML()) + "</div>";
};
}
return doPlay();
}
});
};
}).call(this);