|
0 |
function launch(config) {
|
|
1 |
config.container.innerHTML = `
|
|
2 |
<textarea id="prog" rows="10" cols="80"></textarea>
|
|
3 |
<div id="control-panel"></div>
|
|
4 |
<div><button id="run-button">Run</button></div>
|
|
5 |
<pre id="result"></pre>
|
|
6 |
`;
|
|
7 |
|
|
8 |
function makeSelect(container, labelText, optionsArray, fun) {
|
|
9 |
var label = document.createElement('label');
|
|
10 |
label.innerHTML = labelText;
|
|
11 |
container.appendChild(label);
|
|
12 |
var select = document.createElement("select");
|
|
13 |
for (var i = 0; i < optionsArray.length; i++) {
|
|
14 |
var op = document.createElement("option");
|
|
15 |
op.text = optionsArray[i].filename;
|
|
16 |
op.value = optionsArray[i].contents;
|
|
17 |
select.options.add(op);
|
|
18 |
}
|
|
19 |
select.onchange = function(e) {
|
|
20 |
fun(optionsArray[select.selectedIndex]);
|
|
21 |
};
|
|
22 |
select.selectedIndex = 0;
|
|
23 |
label.appendChild(select);
|
|
24 |
return select;
|
|
25 |
};
|
|
26 |
|
|
27 |
function selectOptionByText(selectElem, text) {
|
|
28 |
var optElem;
|
|
29 |
for (var i = 0; optElem = selectElem.options[i]; i++) {
|
|
30 |
if (optElem.text === text) {
|
|
31 |
selectElem.selectedIndex = i;
|
|
32 |
selectElem.dispatchEvent(new Event('change'));
|
|
33 |
return;
|
|
34 |
}
|
|
35 |
}
|
|
36 |
}
|
|
37 |
|
|
38 |
var controlPanel = document.getElementById('control-panel');
|
|
39 |
var select = makeSelect(controlPanel, "example program:", examplePrograms, function(option) {
|
|
40 |
document.getElementById('prog').value = option.contents;
|
|
41 |
});
|
|
42 |
selectOptionByText(select, "hello.burro");
|
|
43 |
}
|
|
44 |
|
|
45 |
launch({ container: document.getElementById('installation') });
|