forked from att/rcloud
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
85 lines (79 loc) · 2.94 KB
/
main.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
var interpreter = {
'plot': function(cmd) {
rclient.capture_answers(cmd.ps.length, function(result) {
rclient.post_div(create_scatterplot.apply(result));
});
for (var i=0; i<cmd.ps.length; ++i) {
rclient.send(cmd.ps[i], rclient.wrap_command);
}
},
'logout': function(cmd) {
$.cookies.set('user', null);
$.cookies.set('sessid', null);
window.location.href = '/login.html';
}
};
function interpret_command(command)
{
if (command[0] === '@') {
var cmd = parser.parse(command);
interpreter[cmd.id](cmd);
} else {
// rclient.log(command);
rclient.send(command, rclient.markdown_wrap_command);
}
}
function transpose(ar) {
return _.map(_.range(ar[0].length), function(i) {
return _.map(ar, function(lst) { return lst[i]; });
});
}
function main_init() {
rclient = RClient.create({
debug: false,
host: "ws://"+location.hostname+":8081/",
on_connect: function() {
$("#new-md-cell-button").click(function() {
shell.terminal.disable();
shell.new_markdown_cell("", "markdown");
var vs = shell.notebook.view.sub_views;
vs[vs.length-1].show_source();
});
$("#share-notebook").click(function() {
shell.serialize_state(function() {
window.location="share.html?user=" + shell.user + "&filename=" + shell.filename;
});
});
$("#rcloud-logout").click(function() {
$.cookies.set('user', null);
$.cookies.set('sessid', null);
window.location.href = '/login.html';
});
$(".collapse").collapse();
$("#input-text-search").click(function() {
shell.terminal.disable();
});
rcloud.init_client_side_data();
var that = this;
var shell_objtypes = ["scatterplot", "iframe", "facet_osm_plot", "facet_tour_plot"];
for (var i=0; i<shell_objtypes.length; ++i) {
(function(objtype) {
that.register_handler(objtype, function(data) {
var div = shell.handle(objtype, data);
shell.post_div(div);
// shell.handle(objtype, data);
});
})(shell_objtypes[i]);
}
editor.init();
if (location.search.length > 0) {
function getURLParameter(name) {
return decodeURIComponent((new RegExp('[?|&]' + name + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search)||[,""])[1].replace(/\+/g, '%20'))||null;
}
editor.load_file(getURLParameter("user"), getURLParameter("filename"));
$("#tabs").tabs("select", "#tabs-2");
}
}
});
}
window.onload = main_init;