-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathFrameIT_test.html
More file actions
132 lines (123 loc) · 3.84 KB
/
FrameIT_test.html
File metadata and controls
132 lines (123 loc) · 3.84 KB
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
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>NuFrameIT JS Test</title>
<style>
.row{
display: flex;
margin-bottom: 10px;
}
.col{
display: flex;
flex-direction: column;
}
button{
width: 5em;
margin: 10px;
}
textarea[error="true"]{
color: red;
}
.grow-wrap {
/* easy way to plop the elements on top of each other and have them both sized based on the tallest one's height */
display: grid;
width: 40%;
}
.grow-wrap::after {
/* Note the weird space! Needed to prevent jumpy behavior */
content: attr(data-replicated-value) " ";
/* This is how textarea text behaves */
white-space: pre-wrap;
/* Hidden from view, clicks, and screen readers */
visibility: hidden;
}
.grow-wrap > textarea {
/* You could leave this, but after a user resizes, then it ruins the auto sizing */
resize: none;
/* Firefox shows scrollbar on growth, you can hide like this. */
overflow: hidden;
/*! visibility: hidden; */
}
.grow-wrap > textarea,
.grow-wrap::after {
/* Identical styling required!! */
border: 1px solid black;
padding: 0.5rem;
font: inherit;
/* Place on top of each other */
grid-area: 1 / 1 / 2 / 2;
}
</style>
<script type="text/javascript" src="./target/scala-2.13/upl-fastopt/main.js"></script>
<script type="text/javascript">
function addToProject() {
const decls = document.getElementById("projIn").value
const projOut = document.getElementById("projOut")
if(FrameIT.add(decls)){
projOut.removeAttribute("error")
projOut.value = FrameIT.showSiTh
}
else {
projOut.setAttribute("error","true")
projOut.value = FrameIT.getErrors
}
projOut.dispatchEvent(new Event('input', { bubbles: true }));
}
function reset() {
const projOut = document.getElementById("projOut")
FrameIT.resetLevel()
projOut.removeAttribute("error")
projOut.value = FrameIT.showSiTh
projOut.dispatchEvent(new Event('input', { bubbles: true }));
}
function evalUPL() {
const exprs = document.getElementById("in").value
const evalOut = document.getElementById("out")
// an empty line can be used to separate multiple expressions
const eS = exprs.split("\n\n")
evalOut.removeAttribute("error")
evalOut.value = ""
eS.forEach(expr => {
console.log(expr)
evalOut.value += FrameIT.eval(expr) + "\n\n"
try {
} catch (error) {
evalOut.value = error.name +" : "+ error.message + "\n\n"
evalOut.setAttribute("error","true")
console.error(error)
}
});
// remove the unnecessary linebreaks at the end
evalOut.value = evalOut.value.trim()
evalOut.dispatchEvent(new Event('input', { bubbles: true }));
}
// clone the value to the wrapper, so it can adapt the size
function replicateValue(node){
node.parentNode.dataset.replicatedValue = node.value + '\n'
}
</script>
</head>
<body>
<div class="row">
<div class="grow-wrap">
<textarea id="projIn" oninput="replicateValue(this)">x = 1</textarea>
</div>
<div class="col">
<button id="button_add" onclick="addToProject()">Add</button>
<button id="button_reset" onclick="reset()">Reset</button>
</div>
<div class="grow-wrap">
<textarea id="projOut" oninput="replicateValue(this)"></textarea>
</div>
</div><div class="row">
<div class="grow-wrap">
<textarea id="in" oninput="replicateValue(this)">SiTh{x=1}.x+1</textarea>
</div>
<button id="button_eval" onclick="evalUPL()">Evaluate</button>
<div class="grow-wrap">
<textarea id="out" oninput="replicateValue(this)"></textarea>
</div>
</div>
</body>
</html>