111 lines
2.2 KiB
HTML
111 lines
2.2 KiB
HTML
<!DOCTYPE html>
|
|
<!--
|
|
Javascript Playground -
|
|
-->
|
|
<html lang="fr">
|
|
<head>
|
|
<title>Javascript Playground</title>
|
|
<meta charset="utf-8" />
|
|
<script src="codeflask.min.js"></script>
|
|
<style>
|
|
html, body {
|
|
height: 100%;
|
|
}
|
|
body {
|
|
background: #0A3D62;
|
|
font-family: sans-serif;
|
|
font-size: 21px;
|
|
}
|
|
#codeContainer {
|
|
display: block;
|
|
width: 80%;
|
|
margin: auto;
|
|
height: 500px;
|
|
}
|
|
#code {
|
|
position: relative;
|
|
height: 100%;
|
|
}
|
|
#runBtn {
|
|
background-color: #079992;
|
|
color: white;
|
|
display: block;
|
|
width: 80%;
|
|
margin: auto;
|
|
border: none;
|
|
margin-top: 10px;
|
|
line-height: 3rem;
|
|
}
|
|
#console {
|
|
color: white;
|
|
width: 80%;
|
|
margin: auto;
|
|
margin-top: 10px;
|
|
}
|
|
.error {
|
|
background-color: #FF0000;
|
|
color: white;
|
|
}
|
|
footer {
|
|
font-size: 10px;
|
|
color: white;
|
|
margin-top: 10px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div id="codeContainer"><div id="code"></div></div>
|
|
<input type="button" onclick="run('code')" value="Exécuter !" id="runBtn" />
|
|
<div id="console">
|
|
</div>
|
|
<footer>
|
|
Romain de Laage - CC0
|
|
</footer>
|
|
<script>
|
|
const flask = new CodeFlask('#code', {
|
|
language: 'js',
|
|
lineNumbers: true,
|
|
areaId: 'thing1',
|
|
ariaLabelledby: 'header1',
|
|
handleTabs: true/*,
|
|
defaultTheme: false*/
|
|
});
|
|
|
|
let codeElmt = document.getElementById("code")
|
|
let consoleElmt = document.getElementById("console")
|
|
|
|
function run(elmtID) {
|
|
console = newConsole
|
|
console.clear()
|
|
try {
|
|
eval(flask.getCode())
|
|
}
|
|
catch (e) {
|
|
console.error(e)
|
|
}
|
|
console = oldConsole
|
|
}
|
|
|
|
/* Penser à réimplémenter toute la console : https://developer.mozilla.org/fr/docs/Web/API/Console */
|
|
const oldConsole = console
|
|
const newConsole = {
|
|
log: function (...msg) {
|
|
var outMsg = ""
|
|
outMsg += msg[0]
|
|
for (var i = 1; i < msg.length; i++) outMsg += " " + msg[i]
|
|
consoleElmt.innerHTML += "\<div class=\"message\">" + outMsg + "</div>"
|
|
},
|
|
clear: function () {
|
|
consoleElmt.innerHTML = ""
|
|
},
|
|
error: function (...msg) {
|
|
var outMsg = ""
|
|
outMsg = msg[0]
|
|
for (var i = 1; i < msg.length; i++) outMsg += " " + msg[i]
|
|
consoleElmt.innerHTML += "<div class=\"error\">" + outMsg + "</div>"
|
|
}
|
|
}
|
|
</script>
|
|
</body>
|
|
</html>
|