/
ace.html
71 lines (62 loc) · 2.33 KB
/
ace.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
70
71
<!doctype html>
<html>
<head>
<meta charset="utf-8" />
<!-- Wilddog -->
<script src="https://cdn.wilddog.com/js/client/current/wilddog.js"></script>
<!-- ACE and its JavaScript mode and theme files -->
<script src="https://dl.wdstatic.cn/cloudflare/ajax/libs/ace/1.1.3/ace.js"></script>
<script src="https://dl.wdstatic.cn/cloudflare/ajax/libs/ace/1.1.3/mode-javascript.js"></script>
<script src="https://dl.wdstatic.cn/cloudflare/ajax/libs/ace/1.1.3/theme-textmate.js"></script>
<!-- Wildpad -->
<link rel="stylesheet" href="https://cdn.wilddog.com/app/wildpad/0.1/wildpad.css" />
<script src="https://cdn.wilddog.com/app/wildpad/0.1/wildpad.js"></script>
<style>
html { height: 100%; }
body { margin: 0; height: 100%; position: relative; }
/* Height / width / positioning can be customized for your use case.
For demo purposes, we make wildpad fill the entire browser. */
#wildpad-container {
width: 100%;
height: 100%;
}
</style>
</head>
<body>
<div id="wildpad-container"></div>
<script>
function init() {
//// Initialize Wilddog.
var wildpadRef = getExampleRef();
// TODO: Replace above line with:
// var wildpadRef = new Wilddog('<YOUR WILDDOG URL>');
//// Create ACE
var editor = ace.edit("wildpad-container");
editor.setTheme("ace/theme/textmate");
var session = editor.getSession();
session.setUseWrapMode(true);
session.setUseWorker(false);
session.setMode("ace/mode/javascript");
//// Create Wildpad.
var wildpad = Wildpad.fromACE(wildpadRef, editor, {
defaultText: '// JavaScript Editing with Wildpad!\nfunction go() {\n var message = "Hello, world.";\n console.log(message);\n}'
});
}
// Helper to get hash from end of URL or generate a random one.
function getExampleRef() {
var ref = new Wilddog('https://wildpad.wilddogio.com');
var hash = window.location.hash.replace(/#/g, '');
if (hash) {
ref = ref.child(hash);
} else {
ref = ref.push(); // generate unique location.
window.location = window.location + '#' + ref.key(); // add it as a hash to the URL.
}
if (typeof console !== 'undefined')
console.log('Wilddog data: ', ref.toString());
return ref;
}
window.onload = init;
</script>
</body>
</html>