-
Notifications
You must be signed in to change notification settings - Fork 0
/
browsercanvas.js
84 lines (66 loc) · 1.65 KB
/
browsercanvas.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
var OSName = "";
if (navigator.appVersion.indexOf("Win")!=-1) OSName="Windows";
if (navigator.appVersion.indexOf("Mac")!=-1) OSName="MacOS";
if (navigator.appVersion.indexOf("X11")!=-1) OSName="Linux";
if (navigator.appVersion.indexOf("Linux")!=-1) OSName="Linux";
function browsercanvas()
{
checkIfNeedsUpdate();
}
function handle_update_messages(messages)
{
reply=new Array();
for(var i=0;i<messages.length; i++) {
var message=messages[i];
console.log(message);
try {
if ( typeof message == "string" ) {
eval(message);
}
}
catch(e) {
reply.push(e);
}
}
return reply;
}
function go_to_new_location()
{
window.location = g_new_location;
}
function checkIfNeedsUpdate(reply)
{
if ( reply==undefined) reply=null
new Ajax.Request('/needsupdate.dyn', {
method:'post',
parameters: "reply="+Object.toJSON(reply),
onSuccess: function(transport){
if (transport.status == 0) {
console.info('Server shutdown...');
return;
}
try {
var response = transport.responseText.evalJSON();
}
catch (e) {
checkIfNeedsUpdate(e);
return;
}
//console.log("/needsupdate:"+transport.responseText);
if ( response['new_url'] ) {
// bug with new_url handling
//alert("window.location="+response.new_url);
//alert(transport.responseText);
g_new_location =response.new_url;
window.setTimeout(go_to_new_location, 100);
//window.location=response.new_url;
return;
}
var reply = handle_update_messages( response.messages);
checkIfNeedsUpdate(reply);
},
onFailure: function(){
console.error('Something went wrong...');
}
});
}