-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
138 lines (116 loc) · 4.02 KB
/
index.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
<html>
<head>
<meta charset="UTF-8">
<title>Code player</title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<style type="text/css">
body{
font-family: sans-serif;
padding: 0;
margin: 0;
}
iframe{
border: none;
}
#header{
width: 100%-10px;
background-color: beige;
padding: 5px;
height: 30px;
}
#logo{
float: left;
font-weight: bold;
font-size: 120%;
padding: 3px 5px;
}
#buttonsContainer{
width: 200px;
margin: 0 auto;
}
.toggleButton{
float: left;
border: 1px solid grey;
padding: 6px;
border-right: none;
font-size: 90%;
user-select: none;
}
.toggleButton:first-child{
border-top-left-radius: 4px;
border-bottom-left-radius: 4px;
}
.toggleButton:last-child{
border-right: 1px solid grey;
border-top-right-radius: 4px;
border-bottom-right-radius: 4px;
}
.active{
background-color: #d7bcf4;
}
.hidden{
display: none;
}
.highlighted{
background-color: greenyellow;
}
.panel{
float: left;
resize: none;
border-left: none;
border-top: none;
border-bottom: none;
}
</style>
</head>
<body>
<div id="header">
<div id="logo">
<a href="#" style="color: inherit; text-decoration: inherit;">CodePlayer</a>
</div>
<div id="buttonsContainer">
<div class="toggleButton active" id="html">HTML</div>
<div class="toggleButton" id="css">CSS</div>
<div class="toggleButton" id="javascript">JS</div>
<div class="toggleButton active" id="output">Output</div>
</div>
</div>
<div class="panelsContainer">
<textarea class="panel" id="htmlPanel"><p id="paragraph">Hello, World!</p></textarea>
<textarea class="panel hidden" id="cssPanel">p{
color: green;
}</textarea>
<textarea class="panel hidden" id="javascriptPanel">document.getElementById("paragraph").innerHTML = "Hello, there!";</textarea>
<iframe class="panel" id="outputPanel"></iframe>
</div>
<script type="application/javascript">
function updateOutput(){
$("iframe").contents().find("html").html("<html><head><style type='text/css'>" + $('#cssPanel').val() + "</style></head><body>" + $('#htmlPanel').val() + "</body></html>");
document.getElementById('outputPanel').contentWindow.eval($('#javascriptPanel').val());
}
$('.toggleButton').hover(function(){
$(this).addClass('highlighted');
}, function(){
$(this).removeClass('highlighted');
});
$('.toggleButton').click(function(){
$(this).toggleClass('active');
$(this).removeClass('highlighted');
var panelId = $(this).attr('id')+"Panel";
$('#'+panelId).toggleClass('hidden');
var numberOfActivePanels = 4-$('.hidden').length;
$(".panel").width(($(window).width()/numberOfActivePanels)-10);
});
$(".panel").on('change paste keyup', function(){
updateOutput();
});
$(window).resize(function(){
$(".panel").height(window.innerHeight-$("#header").height()-14);
$(".panel").width(($(window).width()/2)-10);
});
$(".panel").height(window.innerHeight-$("#header").height()-14);
$(".panel").width(($(window).width()/2)-10);
updateOutput();
</script>
</body>
</html>