-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
75 lines (62 loc) · 1.97 KB
/
app.js
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
var htmlEditor = ace.edit("html");
htmlEditor.setTheme("ace/theme/cobalt");
htmlEditor.session.setMode("ace/mode/html");
htmlEditor.resize();
htmlEditor.setHighlightActiveLine(false);
var cssEditor = ace.edit("css");
cssEditor.setTheme("ace/theme/cobalt");
cssEditor.session.setMode("ace/mode/css");
cssEditor.resize();
cssEditor.setHighlightActiveLine(false);
var jsEditor = ace.edit("js");
jsEditor.setTheme("ace/theme/cobalt");
jsEditor.session.setMode("ace/mode/javascript");
jsEditor.resize();
jsEditor.setHighlightActiveLine(false);
function compiler() {
var htmlValue = htmlEditor.getValue();
var cssValue = cssEditor.getValue();
var jsValue = jsEditor.getValue();
var result = document.getElementById("result").contentWindow.document;
result.open();
result.writeln(
"<style>" +
cssValue +
"</style>" +
htmlValue +
"<script>" +
jsValue +
"</script>"
);
result.close();
}
var allButtons = document.querySelectorAll("#button-wrapper button");
var allPanels = document.querySelectorAll("#ide-container .panel-wrapper");
function switchPanel(panelIndex) {
switcher(panelIndex);
}
switchPanel(0);
function runEdit(panelIndex) {
switcher(panelIndex);
compiler();
}
function switcher(panelIndex) {
allButtons.forEach(function (node) {
node.style.background = "";
});
allButtons[panelIndex].style.background = "#002240";
allPanels.forEach(function (node) {
node.style.display = "none";
});
allPanels[panelIndex].style.display = "block";
}
function downloadCode() {
var htmlValue = htmlEditor.getValue();
var cssValue = cssEditor.getValue();
var jsValue = jsEditor.getValue();
var combinedCode = `<style>${cssValue}</style>${htmlValue}<script>${jsValue}</script>`;
var blob = new Blob([combinedCode], { type: "text/html" });
var url = URL.createObjectURL(blob);
var a = document.getElementById("download-button");
a.href = url;
}