-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
55 lines (45 loc) · 1.87 KB
/
script.js
File metadata and controls
55 lines (45 loc) · 1.87 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
const htmlEditor = CodeMirror.fromTextArea(document.getElementById('html-editor'), {
mode: 'xml',
lineNumbers: true,
theme: 'nature',
extraKeys: {"Ctrl-Space": "autocomplete"},
hintOptions: {schemaInfo: CodeMirror.htmlSchema}
});
const cssEditor = CodeMirror.fromTextArea(document.getElementById('css-editor'), {
mode: 'css',
lineNumbers: true,
theme: 'nature',
extraKeys: {"Ctrl-Space": "autocomplete"}
});
const jsEditor = CodeMirror.fromTextArea(document.getElementById('js-editor'), {
mode: 'javascript',
lineNumbers: true,
theme: 'nature',
extraKeys: {"Ctrl-Space": "autocomplete"}
});
document.getElementById('run-btn').addEventListener('click', () => {
const htmlContent = htmlEditor.getValue();
const cssContent = `<style>${cssEditor.getValue()}</style>`;
const jsContent = `<script>${jsEditor.getValue()}<\/script>`;
const output = document.getElementById('output');
output.contentDocument.body.innerHTML = htmlContent + cssContent + jsContent;
});
document.getElementById('theme-selector').addEventListener('change', (e) => {
const theme = e.target.value;
htmlEditor.setOption('theme', theme);
cssEditor.setOption('theme', theme);
jsEditor.setOption('theme', theme);
});
document.getElementById('export-btn').addEventListener('click', () => {
const htmlContent = htmlEditor.getValue();
const cssContent = cssEditor.getValue();
const jsContent = jsEditor.getValue();
const zip = new JSZip();
zip.file("index.html", htmlContent);
zip.file("styles.css", cssContent);
zip.file("scripts.js", jsContent);
zip.generateAsync({ type: "blob" })
.then(function(content) {
saveAs(content, "MyProject.zip");
});
});