-
Notifications
You must be signed in to change notification settings - Fork 0
/
CodePlayer.html
executable file
·222 lines (149 loc) · 5.09 KB
/
CodePlayer.html
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
<!doctype html>
<html>
<head>
<title>Learning jQuery</title>
<meta charset="utf-8" />
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<script type="text/javascript" src="jquery.min.js"></script>
<style type="text/css">
body{
margin: 0;
padding: 0;
font-family: "HelveticaNeue-Light", "Helvetica Neue Light", "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
font-weight: 300;
}
#menuBar{
width: 100%;
height: 40px;
background-color: #e0dede;
border-bottom: 1px solid grey;
}
#logo {
padding: 5px 0 0 20px;
font-weight: bold;
font-size: 120%;
float: left;;
}
#buttonDiv {
float: right;
padding: 5px 10px 0 0;
}
#runButton {
font-size: 120%;
}
#toggles {
width: 200px;
margin:0 auto;
list-style: none;
border: 1px solid grey;
border-radius: 3px;
height: 27px;
padding: 0;
position: relative;
top: 5px;
}
#toggles li {
float: left;
border-right: 1px solid grey;
padding: 5px 7px;
}
.clear {
clear: both;
}
.codeContainer {
height: 100%;
width: 50%;
float: left;
position: relative;
}
.codeContainer textarea{
width: 99%;
height: 100%;
border: none;
border-right: 1px solid grey;
font-family: monotype;
font-size: 90%;
padding: 5px;
border-right: 1px solid grey;
box-sizing: border-box;
padding: 10px;
}
.codeLabel {
position: absolute;
right: 10px;
top: 10px;
}
#CSSContainer, #JSContainer {
display: none;
}
iframe {
height: 100%;
position: relative;
left: 20px;
border: none;
}
.selected{
background-color: grey;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="menuBar">
<div id="logo">
Afan's CodePlayer
</div>
<div id="buttonDiv">
<button id="runButton">Run</button>
</div>
<ul id="toggles">
<li class="toggle selected">HTML</li>
<li class="toggle">CSS</li>
<li class="toggle">JS</li>
<li class="toggle selected" style="border:none">Result</li>
</ul>
</div>
<div class="clear"></div>
<div class="codeContainer" id="HTMLContainer">
<div class="codeLabel">HTML</div>
<textarea id="htmlCode"><div id="test"></div></textarea>
</div>
<div class="codeContainer" id="CSSContainer">
<div class="codeLabel">HTML</div>
<textarea id="cssCode">html {background-color:blue}</textarea>
</div>
<div class="codeContainer" id="JSContainer">
<div class="codeLabel">HTML</div>
<textarea id="jsCode">document.getElementById("test").innerHTML="It's working!";</textarea>
</div>
<div class="codeContainer" id="ResultContainer">
<div class="codeLabel">Result</div>
<iframe id="resultFrame"></iframe>
</div>
</div>
<script type="text/javascript">
var windowHeight = $(window).height();
//alert(windowHeight);
var menuBarHeight = $("#menuBar").height();
//alert(menuBarHeight);
var codeContainerHeight = windowHeight - menuBarHeight;
$(".codeContainer").height(codeContainerHeight+"px");
$(".toggle").click(function(){
$(this).toggleClass("selected");
var activDiv = $(this).html();
$("#"+ activDiv+"Container").toggle();
var showingDivs = $(".codeContainer").filter(function(){
return ($(this).css("display") != "none")
}).length;
var width=100/showingDivs;
$(".codeContainer").width(width+"%");
});
$("#runButton").click(function(){
$("iframe").contents().find("html").html('<style>'+$("#cssCode").val()+'</style>'+$("#htmlCode").val());
document.getElementById("resultFrame").contentWindow.eval($("#jsCode").val());
//eval($("#jsCode").val());
});
</script>
</body>
</html>