-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
59 lines (54 loc) · 1.94 KB
/
index.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
<!DOCTYPE html>
<html lang="en">
<head>
<script type="text/javascript" src="/socket.io/socket.io.js"></script>
<script>
var socket = io.connect('http://localhost:3000');
if (!socket) {
alert('Could not connect to server, Change could not be saved!!');
} else {
console.log('Connection established to server...');
}
socket.on('news', function(data) {
console.log(data);
socket.emit('my other event', {my: 'data'});
});
</script>
<title>ACE in Action</title>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<div id="editor"></div>
<script src="/public/ace/min/ace.js" type="text/javascript" charset="utf-8"></script>
<script>
socket.emit('getFile', {});
var changeEventHappend = false;
var editor = ace.edit("editor");
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
editor.getSession().on('change', function(e) {
console.log('editing...' + editor.getValue());
changeEventHappend = true;
});
socket.on('getFile', function(msg) {
console.log('got getFile:' + JSON.stringify(msg));
editor.setValue(msg.content.toString());
});
function autoSave() {
if (changeEventHappend) {
socket.emit('autoSave', {'fileName': 'testEdit.js', 'content': editor.getValue()});
}
changeEventHappend = false;
}
setInterval(autoSave, 5000);
</script>
</body>
</html>