-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.html
159 lines (132 loc) · 5.3 KB
/
jquery.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
<!DOCTYPE html>
<html>
<head>
<title>Code Player</title>
<script type="text/javascript" src="jquery.min.js"></script>
<script type="text/javascript" src="jquery-ui/jquery-ui.min.js"></script>
<link rel="stylesheet" href="jquery-ui/jquery-ui.min.css">
<style type="text/css">
body {
font-family: Arial, Helvetica, sans-serif;
margin: 0;
padding: 0;
background-color: rgb(222, 222, 222);
}
header {
padding: 10px;
background-color: rgb(222, 222, 222);
margin: 0 0 0px 0;
height: 50px;
}
#logo {
float: left;
margin: 0;
padding-top: 5px;
}
#toggleButtonsContainer {
width: 330px;
margin: 0 auto;
}
.toggleButton {
padding: 15px;
font-size: 16px;
float: left;
border: 1px solid #757575;
border-right: none;
}
#htmlButton {
border-top-left-radius: 5px;
border-bottom-left-radius: 5px;
}
#outputButton {
border-top-right-radius: 5px;
border-bottom-right-radius: 5px;
border-right: 1px solid #757575;
}
.active {
background-color: #e8f2ff;
}
.highlightButton {
background-color: gray;
}
#editorSpace {
margin: 0px;
padding: 0px;
}
textarea {
resize: none;
}
.textSpace {
float: left;
width: 50%;
/* border-right: 1px solid #ccc; */
}
#htmlButtonSpace {
background: rgb(235, 233, 159);
}
#cssButtonSpace {
background: rgb(138, 167, 221);
}
#jsButtonSpace {
background: rgb(197, 148, 148);
}
#outputButtonSpace {
background-color: #fff;
border: none;
}
.hidden {
display: none;
}
</style>
</head>
<header>
<h1 id="logo">CodePlayer</h1>
<div id="toggleButtonsContainer">
<div class="toggleButton active" id="htmlButton">HTML</div>
<div class="toggleButton" id="cssButton">CSS</div>
<div class="toggleButton" id="jsButton">JavaScript</div>
<div class="toggleButton active" id="outputButton">Output</div>
</div>
</header>
<div id="editorSpace">
<textarea id="htmlButtonSpace" class="textSpace" name="htmlSpace"><p id="paragraph">Hello World!</p></textarea>
<textarea id="cssButtonSpace" class="textSpace hidden" name="cssSpace">p { color: blue; }</textarea>
<textarea id="jsButtonSpace" class="textSpace hidden" name="jsSpace">document.getElementById("paragraph").innerHTML = "Hello Bob!";</textarea>
<iframe id="outputButtonSpace" class="textSpace"></iframe>
</div>
<body>
<script type="text/javascript">
function updateIframe() {
$("iframe").contents().find("html").html("<html><head><style type='text/css'>" + $("#cssButtonSpace").val() + "</style></head><body>" + $("#htmlButtonSpace").val() + "</body></html>");
// TODO: Need to find a better and safer way to do this without .eval()
document.getElementById("outputButtonSpace").contentWindow.eval($("#jsButtonSpace").val());
}
// Add the Class highlightButton when hovering over the buttons
$(".toggleButton").hover(function() {
$(this).addClass("highlightButton");
}, function() {
$(this).removeClass("highlightButton");
});
// Toggle the Button with the class active when click and remove highlightButton class
$(".toggleButton").click(function() {
$(this).toggleClass("active");
$(this).removeClass("highlightButton");
// Control the display of the spaces and iframe
var spaceId = $(this).attr("id") + "Space";
$("#" + spaceId).toggleClass("hidden");
// Divide the spaces based on hidden elements
var numberOfActiveSpaces = 4 - $(".hidden").length;
$(".textSpace").width(($(window).width() / numberOfActiveSpaces) - 6);
});
// Adjust textarea and iframe to window height
$(".textSpace").height($(window).height() - $("header").height() - 30);
// Fix textarea and iframe width to fit window
$(".textSpace").width(($(window).width() / 2) - 6);
updateIframe();
// Allows textarea to display in iframe
$("textarea").on('change keyup paste', function() {
updateIframe();
});
</script>
</body>
</html>