-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.html
85 lines (76 loc) · 1.84 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<html>
<head>
<title>Ascii to SVG</title>
<script src="main.js"> </script>
<link rel="stylesheet" href="lib/codemirror.css">
<script src="lib/codemirror.js"></script>
<style>
#editor
{
font-size:15.4px;
}
.CodeMirror
{
height:auto;
}
.CodeMirror-scroll
{
height:auto;
}
</style>
</head>
<body>
<div style="display:flex">
<div id="editor" style="border:1px solid #ccc"></div>
<div id="elm"></div>
</div>
<script>
var elm = document.getElementById("elm")
var app = Elm.Main.embed(elm);
app.ports.getAsciiText.subscribe(function(){
var asciiText = cm.getValue();
app.ports.receiveAsciiText.send(asciiText);
});
var editor = document.getElementById("editor")
app.ports.setAsciiText.subscribe(function(asciiText){
cm.setValue(asciiText)
});
var cm = CodeMirror(editor,
{
mode: "text",
lineNumbers: true,
lineWrapping: false,
gutters: ["CodeMirror-linenumbers"],
extraKeys: {
Tab: function(cm) {
var spaces = Array(cm.getOption("indentUnit") + 1).join(" ");
cm.replaceSelection(spaces, "end", "+input");
}
}
}
);
cm.setSize("500px", "auto");
function debounce(func, wait, immediate) {
var timeout;
return function() {
var context = this, args = arguments;
var later = function() {
timeout = null;
if (!immediate) func.apply(context, args);
};
var callNow = immediate && !timeout;
clearTimeout(timeout);
timeout = setTimeout(later, wait);
if (callNow) func.apply(context, args);
};
};
var sendAsciiText = debounce(function() {
window.requestAnimationFrame(function(){
var asciiText = cm.getValue();
app.ports.receiveAsciiText.send(asciiText);
});
}, 500);
cm.on("change",sendAsciiText);
</script>
</body>
</html>