-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patheditor.html
65 lines (64 loc) · 2.13 KB
/
editor.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
60
61
62
63
64
65
<html>
<head>
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/3.0.0/css/bootstrap.min.css"></link>
<style>
#editor {
height: 300px;
}
</style>
</head>
<body style="padding:60px;">
<div class="container">
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Editor</h3>
</div>
<div class="panel-body">
<div id="editor">function foo(items) {
var x = "All this is syntax highlighted";
return x;
}</div>
</div>
</div>
</div>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/ace/1.2.6/ace.js" type="text/javascript" charset="utf-8"></script>
<script src="bundle.js"></script>
<script>
var editor = ace.edit("editor");
editor.$blockScrolling = Infinity
editor.setTheme("ace/theme/monokai");
editor.getSession().setMode("ace/mode/javascript");
var grtcID = GRTC.queryParameter(window.location.search);
if (grtcID.length == 0) {
var grtcID = GRTC.uuid();
window.history.pushState('', '', '?collaborate=' + grtcID);
var grtc = new GRTC(grtcID, window.location.origin, true);
} else {
var grtc = new GRTC(grtcID, window.location.origin, false);
}
var inserting = false;
grtc.on('peerConnected', function(){
console.log('secret acknowledged confirmed');
editor.getSession().on('change', function(e) {
window.x = e;
if(!inserting) {
grtc.send(e);
console.log('changed', e);
}
});
});
grtc.on('peerConnected', function(l) {
grtc.on('peerEncryptedData', function(d){
console.log(d);
});
grtc.on('peerData', function(d){
console.log(d);
inserting = true;
editor.getSession().getDocument().applyDeltas([d]);
inserting = false;
});
});
</script>
</body>
</html>