-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
228 lines (185 loc) · 7.01 KB
/
index.html
File metadata and controls
228 lines (185 loc) · 7.01 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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
<html>
<head>
<title>Code Player</title>
<link rel="stylesheet" type="text/css" href="reset.css">
<style type="text/css">
/* GENERAL */
html, body{
height: 100%;
}
body {
font-family: Arial, Helvetica, sans-serif;
display: flex;
flex-direction: column;
align-items: stretch;
}
/* HEADER */
header{
background-color: #1b1b1b;
display: flex;
align-items: center;
}
#logo{
font-size: 200%;
font-weight: normal;
vertical-align: middle;
margin: 0.5vw;
color: #8A8A8A;
}
#buttons-container{
margin: auto;
}
#buttons button{
border: none;
border-radius: 5px;
padding: 5px 10px 5px 10px;
font-size: 130%;
color: #8A8A8A;
margin-left: 10px;
background-color: #424242;
}
#buttons{
display: inline-block;
padding: 10px;
}
/* MAIN - Code area */
main{
display: flex;
flex: 1;
background-color: black;
}
.code-title {
color: #8A8A8A;
background-color: #424242;
}
#code-html, #code-css, #code-js {
font-size: 16px;
}
#out-section{
background-color: white;
}
.code-section{
text-align: center;
flex: 1;
display: flex;
flex-direction: column;
border-right: solid 1px black;
}
.code-section textarea {
flex: 1;
padding: 5px;
resize: none;
}
iframe {
width: 100%;
height: 100%;
}
/* FOOTER */
footer {
padding: 0.5vw;
text-align: center;
color: gray;
background-color: rgb(41, 41, 41);
}
</style>
</head>
<body>
<header>
<p id="logo">CODE PLAYER</h1>
<section id="buttons-container">
<span id="buttons">
<button id="btn-html">HTML</button>
<button id="btn-css">CSS</button>
<button id="btn-js">Javascript</button>
<button id="btn-out">Output</button>
<span>
</section>
</header>
<main>
<section class="code-section" id="html-section">
<h1 class="code-title">html code</h1>
<div id="code-html" style="flex: 1;"></div>
</section>
<section class="code-section" id="css-section">
<h1 class="code-title">css code</h1>
<div id="code-css" style="flex: 1"></div>
</section>
<section class="code-section" id="js-section">
<h1 class="code-title">javascript code</h1>
<div id="code-js" style="flex: 1"></div>
</section>
<section class="code-section" id="out-section">
<h1 class="code-title">Output</h1>
<iframe id="output"></iframe>
</section>
</main>
<footer>
<p> Made with <span style="color: #e25555;">♥</span> by Lucas Ramos </p>
</footer>
<!-- Import jquery -->
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<!-- Import ACE code text editor -->
<script src="ace-builds-master/src-noconflict/ace.js" type="text/javascript" charset="utf-8"></script>
<script type="text/javascript">
// Config ACE code text editor
var fontSize = "20px";
var htmlEditor = ace.edit("code-html");
htmlEditor.setTheme("ace/theme/monokai");
htmlEditor.session.setMode("ace/mode/html");
htmlEditor.session.on('change', function(delta) {
updateOutput();
});
var cssEditor = ace.edit("code-css");
cssEditor.setTheme("ace/theme/monokai");
cssEditor.session.setMode("ace/mode/css");
cssEditor.session.on('change', function(delta) {
updateOutput();
});
var jsEditor = ace.edit("code-js");
jsEditor.setTheme("ace/theme/monokai");
jsEditor.session.setMode("ace/mode/javascript");
jsEditor.session.on('change', function(delta) {
updateOutput();
});
//set default codes
htmlEditor.setValue("<h1>Welcome to CodePlayer</h1>\n<p>i am inside HTML tag body</p>\n<p id='text'>i will be changed</p>\n",1);
cssEditor.setValue("p { color: green } \n\nbody {\n background-color: #1b1b1b;\n color: #8A8A8A;\n}\n",1);
jsEditor.setValue('document.getElementById("text").innerHTML = "Hi i am JS !"\n',1);// 1 moves cursor to the end of the text
// Tell ace editors that they were resized
function resizeEditors(){
htmlEditor.resize();
cssEditor.resize();
jsEditor.resize();
}
// handle buttons actions
$("#btn-html").click(function (){
$("#html-section").toggle();
resizeEditors();
})
$("#btn-css").click(function (){
$("#css-section").toggle();
resizeEditors();
})
$("#btn-js").click(function (){
$("#js-section").toggle();
resizeEditors();
})
$("#btn-out").click(function (){
$("#out-section").toggle();
resizeEditors();
})
// handle on input events and create resulting html
function updateOutput(){
let head = "<style type='text/css'>" + cssEditor.getValue(); + "</style>";
$("#output").contents().find("head").html(head); // add css to iframe
$("#output").contents().find("body").html(htmlEditor.getValue()); // add body of html to iframe
try{
document.getElementById("output").contentWindow.eval(jsEditor.getValue()); // add js to iframe
}catch(err){
console.log("invalid javascript code")
}
}
updateOutput(); //generate output on the start of the site
</script>
</body>
</html>