-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathscript.js
More file actions
80 lines (71 loc) · 2.58 KB
/
Copy pathscript.js
File metadata and controls
80 lines (71 loc) · 2.58 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
var html_editor = CodeMirror.fromTextArea(document.getElementById("html"), {
lineNumbers: true,
mode: "text/html",
htmlMode:true,
theme:"3024-night",
matchBrackets:true,
autoCloseTags: true,
extraKeys:{"Ctrl-Space": "autocomplete"},
lint:true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"]
}),
css_editor = CodeMirror.fromTextArea(document.getElementById("css"), {
lineNumbers: true,
mode: "css",
theme:"3024-night",
matchBrackets:true,
autoCloseBrackets: true,
extraKeys:{"Ctrl-Space": "autocomplete"},
lint:true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"]
}),
js_editor = CodeMirror.fromTextArea(document.getElementById("js"), {
lineNumbers: true,
mode: "javascript",
theme:"3024-night",
matchBrackets:true,
autoCloseBrackets: true,
extraKeys:{"Ctrl-Space": "autocomplete"},
lint:true,
gutters: ["CodeMirror-linenumbers", "CodeMirror-foldgutter", "CodeMirror-lint-markers"]
});
var editors = [html_editor, css_editor, js_editor];
var base_tpl =
"<!doctype html>\n" +
"<html>\n\t" +
"<head>\n\t\t" +
"<link rel=\"stylesheet\" href=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css\">"+
"<script src=\"https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js\"></script>"+
"<script src=\"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js\"></script>\n\t"+
"<meta charset=\"utf-8\">\n\t\t" +
"<title>Test</title>\n\n\t\t\n\t" +
"</head>\n\t" +
"<body>\n\t\n\t" +
"</body>\n" +
"</html>";
var prepareSource = function() {
var html = html_editor.getValue(),
css = css_editor.getValue(),
jsdata=js_editor.getValue(),
src = '';
// HTML
src = base_tpl.replace('</body>', html + '</body>');
// CSS
css = '<style>' + css + '</style>';
src = src.replace('</head>', css + '</head>');
//JS
jsdata="<script>"+jsdata+"</script>";
src = src.replace('</body>', jsdata + '</body>');
return src;
};
function render() {
var source = prepareSource();
var iframe = document.querySelector('iframe');
var iframe_doc = iframe.contentDocument;
iframe_doc.open();
iframe_doc.write(source);
iframe_doc.close();
};
html_editor.on("change",render);
js_editor.on("change",render);
css_editor.on("change",render);