forked from tibs/campug-jscript-editor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
61 lines (54 loc) · 1.82 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
60
61
<!DOCTYPE html>
<html lang="en">
<head>
<title>Python editor</title>
<style type="text/css" media="screen">
#editor {
position: absolute;
top: 0;
right: 0;
bottom: 0;
left: 0;
}
</style>
</head>
<body>
<!--
Run the tornado server (server.py) and look at http://localhost:8888
Useful URLs:
* https://github.com/ajaxorg/ace-builds/ - where this example started from
* http://ajaxorg.github.com/ace-builds/kitchen-sink.html - their big example
* http://api.jquery.com/jQuery.ajax/ - using jQuery for Ajax
-->
<div id="editor">{{ document }}</div>
<div id="completions" style="left: 40px; top: 20px; position: absolute">
<ul id="completion-list"></ul>
</div>
<script src="http://d1n0x3qji82z53.cloudfront.net/src-min-noconflict/ace.js"></script>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
var editor = ace.edit("editor");
editor.setTheme("ace/theme/chrome");
editor.session.setMode("ace/mode/python");
editor.session.on('change', function(e) {
$.post("/edit", JSON.stringify(e.data));
});
editor.commands.bindKey('ctrl-space', function(e) {
console.log("CTRL-SPACE PRESSED");
$.post("/completions", {}, function(response){
console.log("COMPLETIONS: " + response.completions);
$("#completion-list").html("");
$.each(response.completions, function(i, completion) {
var li = $("<li/>").text(completion);
$("#completion-list").append(li);
});
}, "json");
var left = $(".ace_cursor").position().left
var top = $(".ace_cursor").position().top
$("#completions").css("left", left)
$("#completions").css("top", top)
return false;
});
</script>
</body>
</html>