-
Notifications
You must be signed in to change notification settings - Fork 0
/
coding.html
168 lines (151 loc) · 4.58 KB
/
coding.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
160
161
162
163
164
165
166
167
168
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Einführung Interaktive Medien</title>
<link rel="stylesheet" href="codemirror/lib/codemirror.css" type="text/css" />
<link rel="stylesheet" href="codemirror/doc/docs.css" type="text/css" />
<script src="codemirror/lib/codemirror.js"></script>
<script src="codemirror/lib/util/searchcursor.js"></script>
<script src="codemirror/lib/util/match-highlighter.js"></script>
<script src="codemirror/lib/util/closetag.js"></script>
<script src="codemirror/mode/xml/xml.js"></script>
<script src="codemirror/mode/javascript/javascript.js"></script>
<script src="codemirror/mode/css/css.js"></script>
<script src="codemirror/mode/htmlmixed/htmlmixed.js"></script>
<style type="text/css" >
.clear{
clear: both;
}
.wrap{
margin-bottom: 2em;
}
.CodeMirror {
border: 1px solid black;
}
iframe {
width: 100%;
height: 100%;
border: 1px solid black;
border-left: 0px;
}
.left{
float: left;
width: 50%;
padding:0;
}
#previewDiv{
float: left;
width: 49%;
height: 601px;
}
#editorCSS .CodeMirror{
border-top: none;
}
span.CodeMirror-matchhighlight{
background: #e9e9e9
}
.CodeMirror-focused span.CodeMirror-matchhighlight{
background: #e7e4ff !important;
}
.activeline{
background: #e8f2ff !important;
}
</style>
</head>
<body>
<div class="wrap">
<h1>HTML Grundlagen</h1>
<div class="left">
<div id="editorHTML">
<textarea id="code" name="code"><!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>HTML5 canvas demo</title>
</head>
<body>
<p>Canvas pane goes here:</p>
<canvas id="pane" width="300" height="200"></canvas>
<script>
var canvas = document.getElementById('pane');
var context = canvas.getContext('2d');
context.fillStyle = 'rgb(250,0,0)';
context.fillRect(10, 10, 55, 50);
context.fillStyle = 'rgba(0, 0, 250, 0.5)';
context.fillRect(30, 30, 55, 50);
</script>
</body>
</html></textarea>
</div>
<div id="editorCSS">
<textarea id="codeCSS" name="codeCSS">body{
background:lightblue;
}
p{
font-family: Arial;
}</textarea>
</div>
</div>
<div id="previewDiv">
<iframe id="preview"></iframe>
</div>
<!-- Script -->
<script>
var delay;
// Initialize CodeMirror editor with a nice html5 canvas demo.
var editor = CodeMirror.fromTextArea(document.getElementById('code'), {
mode: 'text/html',
tabMode: 'indent',
onChange: function() {
clearTimeout(delay);
delay = setTimeout(updatePreview, 300);
},
lineNumbers: true,
lineWrapping: true,
onCursorActivity: function() {
editor.matchHighlight("CodeMirror-matchhighlight");
editor.setLineClass(hlLine, null, null);
hlLine = editor.setLineClass(editor.getCursor().line, null, "activeline");
},
extraKeys: {
"'>'": function(cm) { cm.closeTag(cm, '>'); },
"'/'": function(cm) { cm.closeTag(cm, '/'); }
},
wordWrap: true
});
var hlLine = editor.setLineClass(0, "activeline");
function updatePreview() {
var previewFrame = document.getElementById('preview');
var preview = previewFrame.contentDocument || previewFrame.contentWindow.document;
var codeHTML = editor.getValue();
var codeCSS = editorCSS.getValue();
var split = codeHTML.split("<head>");
var code = split[0] + "<style>" + codeCSS + "</style>" + split[1];
preview.open();
preview.write(code);
preview.close();
}
setTimeout(updatePreview, 300);
var delay2;
var editorCSS = CodeMirror.fromTextArea(document.getElementById('codeCSS'),{
mode:'text/css',
tabMode: 'indent',
onChange: function(){
clearTimeout(delay2);
delay2 = setTimeout(updatePreview, 300);
},
lineNumbers: true,
lineWrapping: true,
onCursorActivity: function(){
editorCSS.matchHighlight("CodeMirror-matchhighlight");
editorCSS.setLineClass(hlLine2, null, null);
hlLine2 = editorCSS.setLineClass(editorCSS.getCursor().line, null, "activeline");
},
});
var hlLine2 = editorCSS.setLineClass(0, "activeline");
</script>
<div class="clear"></div>
</div>
</body>
</html>