Add clear and example buttons

This commit is contained in:
Romain de Laage 2021-04-05 09:27:12 +02:00
parent 6fd1f6a46d
commit a498c5b5cd
Signed by: rdelaage
GPG Key ID: 534845FADDF0C329
5 changed files with 61 additions and 5 deletions

View File

@ -34,12 +34,25 @@ header {
position: relative;
height: 100%;
}
#exBtn {
background-color: #9A9F03;
color: white;
font-weight: bold;
display: inline-block;
width: 25%;
border: none;
height: 50px;
transition: 0.3s;
}
#exBtn:hover {
background-color: #7A7F0A;
}
#runBtn {
background-color: #079992;
color: white;
font-weight: bold;
display: block;
width: 100%;
display: inline-block;
width: 50%;
border: none;
height: 50px;
transition: 0.3s;
@ -47,6 +60,19 @@ header {
#runBtn:hover {
background-color: #007972;
}
#clearBtn {
background-color: #832317;
color: white;
font-weight: bold;
display: inline-block;
width: 25%;
border: none;
height: 50px;
transition: 0.3s;
}
#clearBtn:hover {
background-color: #6A1F13;
}
#console {
font-family: monospace;
color: white;

View File

@ -13,6 +13,14 @@ function run() {
console = oldConsole
}
function example() {
flask.updateCode("function foo(n) {\n for(i = 0; i < n; i++) {\n console.log('passe ' + i)\n }\n return n*n\n}\n\nconsole.log(foo(5))")
}
function clearCode() {
flask.updateCode("")
}
/* Penser à réimplémenter toute la console : https://developer.mozilla.org/fr/docs/Web/API/Console */
const oldConsole = console
const newConsole = {

View File

@ -14,7 +14,9 @@
<div id="codeContainer"><div id="code"></div></div><!--
--><div id="console">
</div>
<input type="button" onclick="run()" value="Exécuter !" id="runBtn" />
<input type="button" onclick="example()" value="Exemple" id="exBtn" /><!--
--><input type="button" onclick="run()" value="Exécuter !" id="runBtn" /><!--
--><input type="button" onclick="clearCode()" value="Effacer" id="clearBtn" />
</div>
<footer>
Romain de Laage - CC0

View File

@ -16,7 +16,9 @@
<div id="codeContainer"><div id="code"></div></div><!--
--><div id="console">
</div>
<input type="button" onclick="run()" value="Exécuter !" id="runBtn" />
<input type="button" onclick="example()" value="Exemple" id="exBtn" /><!--
--><input type="button" onclick="run()" value="Exécuter !" id="runBtn" /><!--
--><input type="button" onclick="clearCode()" value="Effacer" id="clearBtn" />
</div>
<footer>
Romain de Laage - CC0
@ -28,6 +30,14 @@
function run() {
fengari.load(flask.getCode())()
}
function example() {
flask.updateCode("function foo(n)\n for i = 0, n, 1 do\n print('passe ' .. tostring(i))\n end\n return n*n\nend\n\nprint(foo(5))")
}
function clearCode() {
flask.updateCode("")
}
</script>
</body>
</html>

View File

@ -17,7 +17,9 @@
<div id="codeContainer"><div id="code"></div></div><!--
--><div id="console">
</div>
<input type="button" onclick="run()" value="Exécuter !" id="runBtn" />
<input type="button" onclick="example()" value="Exemple" id="exBtn" /><!--
--><input type="button" onclick="run()" value="Exécuter !" id="runBtn" /><!--
--><input type="button" onclick="clearCode()" value="Effacer" id="clearBtn" />
</div>
<footer>
Romain de Laage - CC0
@ -62,6 +64,14 @@ document['console'].html = ''
ids:["pycode"]
})
}
function example() {
flask.updateCode("def foo(n):\n for i in range(n):\n print('passe ' + str(i))\n return n*n\n\nprint(foo(5))")
}
function clearCode() {
flask.updateCode("")
}
</script>
</body>
</html>