-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodeFiddler.html
More file actions
81 lines (68 loc) · 2.33 KB
/
codeFiddler.html
File metadata and controls
81 lines (68 loc) · 2.33 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
<html>
<head>
<title>Code Fiddler</title>
<link rel="stylesheet" href="bootstrap.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,700" rel="stylesheet">
<link rel="stylesheet" href="codeFiddler.css">
</head>
<body>
<header>
<h1 class="text-center">Code Fiddler</h1>
<div id="buttonRow">
<a href="#htmlSection" class="sectionBtn active">HTML</a>
<a href="#cssSection" class="sectionBtn">CSS</a>
<a href="#javascriptSection" class="sectionBtn">JavaScript</a>
<a href="#resultSection" class="sectionBtn active">Result</a>
</div>
</header>
<section>
<div class="container-fluid">
<div id="htmlSection" class="col-xs-12 col-sm-6 sectionBody">
<h3 class="text-center">HTML</h3>
<textarea id="htmlContent" class="form-control box"></textarea>
</div>
<div id="cssSection" class="col-xs-12 col-sm-6 sectionBody">
<h3 class="text-center">CSS</h3>
<textarea id="cssContent" class="form-control box"></textarea>
</div>
<div id="javascriptSection" class="col-xs-12 col-sm-6 sectionBody">
<h3 class="text-center">JavaScript</h3>
<textarea id="javascriptContent" class="form-control box"></textarea>
</div>
<div id="resultSection" class="col-xs-12 col-sm-6 sectionBody">
<h3 class="text-center">Result</h3>
<iframe id="outputFrame" class="box"></iframe>
</div>
</div>
</section>
<script src="jquery.js"></script>
<script src="bootstrap.js"></script>
<script type="text/javascript">
$('#htmlContent, #cssContent').on("change keyup paste", function() {
var bodyContent = $('#htmlContent').val();
var cssContent = $('#cssContent').val();
var html = "<html><head><style>" + cssContent + "</style></head><body>" + bodyContent + "</body></html>";
// update iframe document content
$('#outputFrame').contents().find('html').html(html);
updateJS();
});
$('#javascriptContent').on('change', updateJS);
// apply JS to iframe
// NOT SAFE !!!
function updateJS() {
document.getElementById("outputFrame").contentWindow.eval($("#javascriptContent").val());
}
$('.sectionBtn').click(function(e) {
e.preventDefault();
var id = $(this).attr('href');
if ($(this).hasClass('active')) {
$(this).removeClass('active');
$(id).hide();
} else {
$(this).addClass('active');
$(id).show();
}
});
</script>
</body>
</html>