-
Notifications
You must be signed in to change notification settings - Fork 2
/
demo.html
59 lines (54 loc) · 2.1 KB
/
demo.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
<!DOCTYPE html>
<html>
<head>
<title>Demo editor</title>
<link rel="stylesheet" href="assets/codemirror/codemirror.css">
<link rel="stylesheet" href="assets/codemirror/addons/show-hint.css">
<link rel="stylesheet" href="assets/codemirror/addons/lint.css">
</head>
<body>
<textarea id="code-js" style="display: none;">var widgets = []
function updateHints() {
editor.operation(function(){
for (var i = 0; i < widgets.length; ++i)
editor.removeLineWidget(widgets[i]);
widgets.length = 0;
JSHINT(editor.getValue());
for (var i = 0; i < JSHINT.errors.length; ++i) {
var err = JSHINT.errors[i];
if (!err) continue;
var msg = document.createElement("div");
var icon = msg.appendChild(document.createElement("span"));
icon.innerHTML = "!!";
icon.className = "lint-error-icon";
msg.appendChild(document.createTextNode(err.reason));
msg.className = "lint-error";
widgets.push(editor.addLineWidget(err.line - 1, msg, {coverGutter: false, noHScroll: true}));
}
});
var info = editor.getScrollInfo();
var after = editor.charCoords({line: editor.getCursor().line + 1, ch: 0}, "local").top;
if (info.top + info.clientHeight < after)
editor.scrollTo(null, after - info.clientHeight + 3);
}
</textarea>
<script src="assets/codemirror/codemirror.js"></script>
<!-- Some code mirrors addons -->
<script src="assets/codemirror/javascript.js"></script>
<script src="assets/codemirror/addons/matchbrackets.js"></script>
<script src="assets/codemirror/addons/autorefresh.js"></script>
<script src="assets/codemirror/addons/javascript-hint.js"></script>
<script src="assets/codemirror/addons/jshint.js"></script>
<script src="assets/codemirror/addons/javascript-lint.js"></script>
<script src="assets/codemirror/addons/lint.js"></script>
<script src="assets/codemirror/addons/show-hint.js"></script>
<script type="text/javascript">
var editor = CodeMirror.fromTextArea(document.getElementById("code-js"), {
lineNumbers: true,
mode: "javascript",
gutters: ["CodeMirror-lint-markers"],
lint: true
});
</script>
</body>
</html>