-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathport.js
65 lines (60 loc) · 1.65 KB
/
port.js
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
window.initialPortValues["signalFromJS"] = "DUMMY";
window.initializers.push(function (elmRuntime) {
elmRuntime.ports.signalToJS.subscribe(function (info) {
if (info == "update") {
var s = window.document.getElementById("input").value;
console.log(s);
elmRuntime.ports.signalFromJS.send(s);
}
else {
console.log(info);
setTex(info);
}
});
});
function setTex (info) {
var s = info.replace(/\$/g,"");
console.log(s);
var target = window.document.getElementById("MathJax-Span-3");
console.log(target);
if (target) {
//console.log(target.textContent);
target.textContent = s;
elmRuntime.ports.signalFromJS.send("false");
}
else {
tex();
}
}
function tex() {
var script = document.createElement("script");
script.id = "TexScript";
script.type = "text/javascript";
script.src = "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML";
var head = document.getElementsByTagName("head")[0];
var node = document.getElementById("TexScript");
head.appendChild(script);
/*
if (node) {
head.removeChild(node);
head.appendChild(script);
}
else {
head.appendChild(script);
}*/
}
function clear() {
var node = document.getElementById("output");
var nodes = node.childNodes;
console.log(nodes);
var len = nodes.length;
console.log(len);
var i;
var temp = nodes[0];
while (node.firstChild) {
node.removeChild(node.firstChild);
}
if (!temp.nodetype) {
node.appendChild(temp);
}
}