forked from audreyt/ethercalc
/
player-broadcast.js
125 lines (125 loc) · 5.21 KB
/
player-broadcast.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
// Generated by LiveScript 1.2.0
(function(){
this.include = function(){
return this.client({
'/player/broadcast.js': function(){
var SocialCalc, md5;
SocialCalc = window.SocialCalc || alert('Cannot find window.SocialCalc');
if (SocialCalc != null && SocialCalc.OrigDoPositionCalculations) {
return;
}
SocialCalc.OrigDoPositionCalculations = SocialCalc.DoPositionCalculations;
SocialCalc.DoPositionCalculations = function(){
var ref$;
SocialCalc.OrigDoPositionCalculations.apply(SocialCalc, arguments);
if (typeof (ref$ = SocialCalc.Callbacks).broadcast === 'function') {
ref$.broadcast('ask.ecell');
}
};
if (window.CryptoJS) {
md5 = function(it){
return CryptoJS.MD5(it).toString();
};
SocialCalc.hadSnapshot = true;
SocialCalc.OrigLoadEditorSettings = SocialCalc.LoadEditorSettings;
SocialCalc.LoadEditorSettings = function(editor, str, flags){
editor.SettingsCallbacks.ethercalc = {
save: function(){
return "ethercalc:" + md5(editor.context.sheetobj.CreateSheetSave()) + "\n";
},
load: function(editor, setting, line, flags){
var hash;
hash = line.replace(/^\w+:/, '');
if (hash === md5(editor.context.sheetobj.CreateSheetSave())) {
return SocialCalc.hadSnapshot = false;
} else {
return SocialCalc.hadSnapshot = true;
}
}
};
SocialCalc.LoadEditorSettings = SocialCalc.OrigLoadEditorSettings;
return SocialCalc.OrigLoadEditorSettings(editor, str, flags);
};
} else {
SocialCalc.hadSnapshot = false;
}
SocialCalc.OrigSizeSSDiv = SocialCalc.SizeSSDiv;
SocialCalc.SizeSSDiv = function(spreadsheet){
if (!(spreadsheet != null && spreadsheet.parentNode)) {
return;
}
return SocialCalc.OrigSizeSSDiv(spreadsheet);
};
SocialCalc.Sheet.prototype.ScheduleSheetCommands = function(){
return SocialCalc.ScheduleSheetCommands.apply(SocialCalc, [this].concat([].slice.call(arguments)));
};
SocialCalc.OrigScheduleSheetCommands = SocialCalc.ScheduleSheetCommands;
SocialCalc.ScheduleSheetCommands = function(sheet, cmdstr, saveundo, isRemote){
var ref$;
cmdstr = cmdstr.replace(/\n\n+/g, '\n');
if (!/\S/.test(cmdstr)) {
return;
}
if (!isRemote && cmdstr !== 'redisplay' && cmdstr !== 'recalc') {
if (typeof (ref$ = SocialCalc.Callbacks).broadcast === 'function') {
ref$.broadcast('execute', {
cmdstr: cmdstr,
saveundo: saveundo
});
}
}
return SocialCalc.OrigScheduleSheetCommands(sheet, cmdstr, saveundo, isRemote);
};
return SocialCalc.MoveECell = function(editor, newcell){
var highlights, ref$, cell, f;
highlights = editor.context.highlights;
if (editor.ecell) {
if (editor.ecell.coord === newcell) {
return newcell;
}
if (typeof (ref$ = SocialCalc.Callbacks).broadcast === 'function') {
ref$.broadcast('ecell', {
original: editor.ecell.coord,
ecell: newcell
});
}
cell = SocialCalc.GetEditorCellElement(editor, editor.ecell.row, editor.ecell.col);
delete highlights[editor.ecell.coord];
if (editor.range2.hasrange && editor.ecell.row >= editor.range2.top && editor.ecell.row <= editor.range2.bottom && editor.ecell.col >= editor.range2.left && editor.ecell.col <= editor.range2.right) {
highlights[editor.ecell.coord] = 'range2';
}
editor.UpdateCellCSS(cell, editor.ecell.row, editor.ecell.col);
editor.SetECellHeaders('');
editor.cellhandles.ShowCellHandles(false);
} else {
if (typeof (ref$ = SocialCalc.Callbacks).broadcast === 'function') {
ref$.broadcast('ecell', {
ecell: newcell
});
}
}
newcell = editor.context.cellskip[newcell] || newcell;
editor.ecell = SocialCalc.coordToCr(newcell);
editor.ecell.coord = newcell;
cell = SocialCalc.GetEditorCellElement(editor, editor.ecell.row, editor.ecell.col);
highlights[newcell] = 'cursor';
for (f in editor.MoveECellCallback) {
editor.MoveECellCallback[f](editor);
}
editor.UpdateCellCSS(cell, editor.ecell.row, editor.ecell.col);
editor.SetECellHeaders('selected');
for (f in editor.StatusCallback) {
editor.StatusCallback[f].func(editor, 'moveecell', newcell, editor.StatusCallback[f].params);
}
if (editor.busy) {
editor.ensureecell = true;
} else {
editor.ensureecell = false;
editor.EnsureECellVisible();
}
return newcell;
};
}
});
};
}).call(this);