-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
82 lines (75 loc) · 2.68 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
<!-- based on https://github.com/ravichugh/sketch-n-sketch/blob/visualeditor/build/deuce/index.html -->
<html>
<head>
<title>WolframAlpha in Elm</title>
<script type="text/javascript" src="interface.js"></script>
<script type="text/javascript"
src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML" id ="TexScript">
</script>
<meta charset="UTF-8">
<style type="text/css" media="screen">
#editor {
position: relative;
}
</style>
</head>
<body style="margin: 0 0 0 0;">
</body>
<script>
// Scripts below will load these up.
window.initialPortValues = {};
window.initializers = [];
</script>
<script>
window.initialPortValues["signalFromJS"] = ["update","DUMMY"];
window.initializers.push(function (elmRuntime) {
elmRuntime.ports.signalToJS.subscribe(function (info) {
if (info == "update" || info == "graphicUpdate") {
var s = window.document.getElementById("input").textContent;
console.log(s);
elmRuntime.ports.signalFromJS.send([info,s]);
}
else if (info == "clear") {
var input_node = window.document.getElementById("input");
//input_node.textContent = "";
var output_node = window.document.getElementById("output");
output_node.textContent = "";
}
else {
console.log(info);
var math_node = MathJax.Hub.getAllJax("output");
console.log(math_node);
var math = null;
if (math_node.length > 0) {
math = math_node[0];
var node = window.document.getElementById("output");
removeAll(node);
node.textContent = info;
console.log(math);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"output"])
}
else {
var node = window.document.getElementById("output");
removeAll(node);
node.textContent = info;
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"output"]);
}
}
});
});
function removeAll(node) {
while(node.firstChild) {
node.removeChild(node.firstChild);
}
}
</script>
<script>
// Start up Elm
var elmRuntime = Elm.fullscreen(Elm.Interface, window.initialPortValues);
// Call the initializers
for (var i in window.initializers) {
var initializer = window.initializers[i];
initializer(elmRuntime);
}
</script>
</html>