git @ Cat's Eye Technologies Quylthulg / 52718e1
Add ability to select an example program, to HTML5 w/hastec demo. Chris Pressey 1 year, 4 months ago
3 changed file(s) with 73 addition(s) and 5 deletion(s). Raw diff Collapse all Expand all
0 document.getElementById('installation').innerHTML = (
1 '<textarea id="prog" rows="10" cols="80"></textarea>' +
2 '<div><button id="run-button">Run</button></div>' +
3 '<pre id="result"></pre>'
4 );
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, "length-and-sum.quylthulg");
43 }
44
45 launch({ container: document.getElementById('installation') });
1010
1111 <div id="installation"></div>
1212
13 <script src="../eg/examplePrograms.jsonp.js"></script>
1314 <script src="qlzqqlzuup-hastec-launcher.js"></script>
1415 <script src="qlzqqlzuup.js"></script>
1516 </body>
0 examplePrograms = [
1 {
2 "contents": "foreach $x$ = :L:[1, 2, 3, goto $L$] with $a$ = 0 be $x$ else be null\n",
3 "filename": "infinite-loop.quylthulg"
4 },
5 {
6 "contents": "foreach $x$ = [10, 20, 40]\n with $a$ = ,0,0, be\n ,+<$a$<0<+1+,+>$a$>0>+$x$+,\n else be\n null\n",
7 "filename": "length-and-sum.quylthulg"
8 },
9 {
10 "contents": "foreach $x$ = [10, 20, 40, 80]\n with $a$ = null be\n ,$x$,$a$,\n else be\n null\n",
11 "filename": "reverse.quylthulg"
12 },
13 {
14 "contents": "{*[SQR][*{X}*{X}*]}{*[X][5]}{SQR}\n",
15 "filename": "square.quylthulg"
16 },
17 {
18 "contents": "foreach $x$ = [10, 20, 40, 80, 60, 10, 30]\n with $a$ = ,null,[1,1,1,1], be\n foreach $n$=>>$a$>null>>null>\n with $r$=99999 be\n ,,$x$,<$a$<null<,,>>$a$>null>>null>,\n else be\n abort\n else be\n null\n",
19 "filename": "take-3-reverse.quylthulg"
20 },
21 {
22 "contents": "foreach $x$ = :L:[10, 20, goto $L$]\n with $a$ = ,null,[1,1,1,1,1,1], be\n foreach $n$=>>$a$>null>>null>\n with $r$=99999 be\n ,,$x$,<$a$<null<,,>>$a$>null>>null>,\n else be\n abort\n else be\n null\n",
23 "filename": "take-5-from-cyclic-list.quylthulg"
24 }
25 ];