-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEditorJS.html
More file actions
111 lines (100 loc) · 2.98 KB
/
EditorJS.html
File metadata and controls
111 lines (100 loc) · 2.98 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
<!DOCTYPE html>
<html>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<!-- this is the code that will allow icon to be visible in the title bar of the brower -->
<link rel="icon" type="image/ico" href="WebsiteLogo2.png" />
<!-- you can also say this: <link rel="icon" type="image/png" href="location/image.png" /> -->
<h1>JavaScript Code Sandbox</h1>
<textarea id="code">console.log("hi");</textarea>
<button id="run">Run</button>
<h2>Output</h2>
<pre id="output"></pre>
<style>
div.field {
font-family: 'Consolas';
font-size: 20px;
color: black;
width: 1000px;
height: 1000px;
border: 3px solid #cccccc;
background-color: white;
padding: 10px;
resize: none;
}
pre {
background-color: white;
width: 800px;
}
textarea {
resize: none;
width: 700px;
height: 400px;
color: black;
background-color: white;
}
::selection {
background: #eeb005da;
/* WebKit/Blink Browsers */
}
::-moz-selection {
background: #eeb005da;
/* Gecko Browsers */
}
body {
background-color: #E5E4E2;
}
h1 {
font-family: 'Consolas';
text-decoration: none;
border: none;
font-size: 30px;
}
h2 {
font-family: 'Consolas';
text-decoration: none;
border: none;
font-size: 20px;
}
button {
background-color: #bbb;
padding: .2em;
margin-left: 1em;
-moz-border-radius: 5px;
-webkit-border-radius: 5px;
border-radius: 10px;
color: #fff;
font-family: 'Consolas';
/*Oswald is a great font*/
text-decoration: none;
border: none;
font-size: 20px;
}
button:hover {
background-color: rgb(172, 122, 15);
}
</style>
<script>
let runner = document.getElementById("run");
runner.addEventListener("click", () => {
//console.log("running " + document.getElementById("code").value);
evalAndReturn(document.getElementById("code").value);
});
document.getElementById("output").insertBefore(document.createTextNode("Output from return() calls appear here, the most recent at the top\n"), output.childNodes[0]);
function evalAndReturn(code) {
let newItem = document.createTextNode(String(eval(code)) + "\n");
let output = document.getElementById("output");
if (eval(code) != undefined) {
output.insertBefore(newItem, output.childNodes[0]);
} else {
document.getElementById("output").appendChild(document.createTextNode("No results. You can view Console.logs in the console, but you need a return() value. \n"));
}
if(output.childNodes[8] != undefined){
output.removeChild(output.childNodes[8]);
}
//return x;
}
//console.log()
//evalAndReturn(document.getElementById("code").textContent);
// → 2
</script>
</html>