-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcode.html
70 lines (59 loc) · 1.8 KB
/
code.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
66
67
68
69
<html>
<head>
<link href="ace/style.css" rel="stylesheet" type="text/css">
<title>Code editor</title>
</head>
<body>
<div id="header">
<div id="htext">
Editing <b id='docname'>...</b>
<a style="padding-left: 50px;" href="/code.html">New</a>
</div>
</div>
<div id="editor">Loading...</div>
<script src="/lib/ace/ace.js"></script>
<script src="/lib/ace/mode-coffee.js"></script>
<script src="/lib/ace/theme-idle_fingers.js"></script>
<script src="/channel/bcsocket.js"></script>
<script src="/share/share.uncompressed.js"></script>
<script src="/share/ace.js"></script>
<script>
var randomDocName = function(length) {
var chars, x;
if (length == null) {
length = 10;
}
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-=";
var name = [];
for (x = 0; x < length; x++) {
name.push(chars[Math.floor(Math.random() * chars.length)]);
}
return name.join('');
};
window.onload = function() {
var editor = ace.edit("editor");
editor.setReadOnly(true);
editor.getSession().setUseSoftTabs(true);
editor.getSession().setTabSize(2);
editor.getSession().setMode(new (require("ace/mode/coffee").Mode));
editor.setTheme("ace/theme/idle_fingers");
if (!document.location.hash) {
document.location.hash = '#' + randomDocName();
}
var docName = "code:" + document.location.hash.slice(1);
var span = document.getElementById('docname').innerText = docName;
sharejs.open(docName, 'text', function(error, doc) {
if (error) {
console.error(error);
return;
}
if (doc.created) {
doc.insert(0, "# Coffeescript editor!\n\nexports.foo = ->\n console.log 'hi!'");
}
doc.attach_ace(editor);
editor.setReadOnly(false);
});
};
</script>
</body>
</html>