-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathlibview.html
145 lines (131 loc) · 5.49 KB
/
libview.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<!doctype html>
<html>
<head>
<title>View Library Code</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<link rel="stylesheet" href="http://codemirror.net/lib/codemirror.css">
<link rel="stylesheet" href="http://codemirror.net/addon/fold/foldgutter.css">
<link rel="stylesheet" href="http://codemirror.net/addon/hint/show-hint.css">
<link rel="stylesheet" href="/CodeMirror/Suneido.css">
<link rel="stylesheet" href="/CodeMirror/Dialog.css">
<script src="http://codemirror.net/lib/codemirror.js"></script>
<script src="http://codemirror.net/addon/fold/foldcode.js"></script>
<script src="http://codemirror.net/addon/fold/foldgutter.js"></script>
<script src="http://codemirror.net/addon/fold/brace-fold.js"></script>
<script src="http://codemirror.net/addon/edit/matchbrackets.js"></script>
<script src="http://codemirror.net/addon/edit/closebrackets.js"></script>
<script src="http://codemirror.net/addon/hint/show-hint.js"></script>
<script src="http://codemirror.net/addon/comment/comment.js"></script>
<script src="http://codemirror.net/addon/search/searchcursor.js"></script>
<script src="http://codemirror.net/addon/selection/active-line.js"></script>
<script src="http://codemirror.net/addon/display/panel.js"></script>
<script src="http://codemirror.net/addon/runmode/runmode.js"></script>
<script src="/CodeMirror/Suneido-editor.js"></script>
<script src="/CodeMirror/Suneido.js"></script>
<script src="/CodeMirror/Dialog.js"></script>
<script src="/CodeMirror/Suneido-search.js"></script>
<script src="/CodeMirror/HighlightWords.js"></script>
<script src="/CodeMirror/Suneido-hint.js"></script>
<script type="text/javascript">
window.onload = function() {
var text = document.getElementById('text');
var editor = SuneidoEditor(text);
function load() {
var name = document.getElementById("name").value;
history.pushState(null, null, '/libview?' + name);
load2(name);
}
function load2(name) {
if (name === undefined)
name = document.getElementById("name").value;
if (!name) {
editor.setValue("");
return;
}
var req = new XMLHttpRequest();
req.onload = display;
req.open("get", "/libget?stdlib/" + name, true);
req.send();
};
function display() {
editor.setValue(this.responseText);
};
function keypress(event) {
if (event.which == 13 || event.keyCode == 13) {
load();
return false;
}
return true;
};
document.getElementById('load').onclick = load;
document.getElementById('name').onkeypress = keypress;
function update() {
editor.setValue("updating...")
var req = new XMLHttpRequest();
req.onload = display;
req.open("post", "/update", true);
req.send();
}
document.getElementById('update').onclick = update;
function goToDefinition(cm) {
// TODO be able to locate to the definitions of variables ands methods
var doc = cm.getDoc();
var sel;
var wordPos;
var name = document.getElementById('name');
sel = doc.getSelection();
if (!sel) {
wordPos = cm.findWordAt(cm.getCursor());
sel = cm.getRange(wordPos.anchor, wordPos.head)
}
name.value = sel;
load();
}
function goto(event) {
if (event.which == 123 || event.keyCode == 123) {
goToDefinition(editor);
return false;
}
return true;
}
document.getElementsByClassName('CodeMirror')[0].onkeydown = goto;
window.addEventListener("popstate", function(e) {
document.getElementById("name").value = location.search.substr(1);
load2();
});
// handle non ajax (re)load
if (location.search.length > 1) {
document.getElementById("name").value = location.search.substr(1);
load2();
}
};
</script>
<style>
.CodeMirror {
border: 1px solid gray;
height: 70vh;
}
.button {
padding: 2px;
color: white;
font-family: sans-serif;
font-weight: bold;
background-color: blue;
cursor: pointer;
}
#name {
font-size: large;
}
</style>
</head>
<body>
<h1>suneido.js Library View</h1>
<input id="name" type="text" style="margin-bottom: 1em;"></input>
<span id="load" class="button">Load</span>
<span id="update" class="button" style="float: right;">Update</span>
<br style="clear: both;" />
<div id="text"></div>
<p>Keyboard shortcuts: Ctrl+F = Search, F3 = Find Next, Shift+F3 = Find Previous, Ctrl+H = Replace, Shift+Ctrl+H = Replace All, Ctrl+/ = comment with //, Shift+Ctrl+/ = comment with /* */, F12 = go to selected name
</p>
</body>
</html>