-
Notifications
You must be signed in to change notification settings - Fork 0
/
portal.html
303 lines (263 loc) · 8.39 KB
/
portal.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
<!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" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery.js"></script>
<script src="js/script.js"></script>
<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>
<script>
if(!isReady()){
alert("Diese Website sollte nur mit modernen Browsern genutzt werden - z.B. Firefox ab Version 2.0, IE ab Version 8, Safari ab Version 4.0, Chrome ab Version 4.0.");
}else{
if(!isLoggedIn()){
changeToLogin();
}
}
/* TODO:
* Design
* CSS Classe für gespeichert
*/
// alle Lektionen in Objekt definiert
var lektionObj = {
lektionen : [{
nummer : 1,
titel : "1) Mit HTML starten"
},{
nummer : 2,
titel : "2) Überschriften, Links & Bilder"
},{
nummer : 3,
titel : "3) Listen"
},{
nummer : 4,
titel : "4) Challenge 1"
},{
nummer : 5,
titel : "5) Inline-Styling mit CSS"
},{
nummer : 6,
titel : "6) Styling mit Internal Style Sheet"
},{
nummer : 7,
titel : "7) Box Modell"
},{
nummer : 8,
titel : "8) Challenge 2"
},{
nummer : 9,
titel : "9) Box-Inhalt"
},{
nummer : 10,
titel : "10) Positionierung"
},{
nummer: 11,
titel : "11) Challenge 3"
}]
};
// Wenn DOM ready
$(document).ready(function() {
checkHash();
$("#console").hide();
// Schau ob admin
var user = JSON.parse(localStorage.getItem("user"));
if(user.matrikelnummer == "admin"){
$("#administration").show();
}
// Zeige Usernamen an
$("#username").append(user.name);
// Alle Lektionen anzeigen --> TODO: Icon, wenn von User schon bearbeitet
updateLektionenList(user);
// onclick für Nav
$("#navi li").click(function() {
//console.log("click navi li");
//console.log(this.id);
switch(this.id){
case "lektion":
//console.log("click lektion");
$("#allLektionen").show();
location.hash = "lektion";
$("#coding").hide();
$("#admin").hide();
$("#saveButton").hide();
$("#resetButton").hide();
$("#content h1").hide();
//TODO update LektionsList --> css class für gespeicherte
break;
case "administration":
$("#allLektionen").hide();
$("#coding").hide();
$("#admin").show();
location.hash = "administration";
$("#saveButton").hide();
$("#resetButton").hide();
$("#content h1").hide();
break;
}
$("#navi li").removeClass("active");
$(this).addClass("active");
});
// onclick für allLektionen
$("#allLektionen li").click(function(){
var clickedItemId = this.id;
$("#allLektionen").hide();
$("#content h1").hide();
$("#coding").show();
location.hash = "coding";
$("#saveButton").show();
$("#resetButton").show();
// Hole Daten zur Lektion aus DB && Insert Lektion in DB für Matrikelnummer (wenn nicht admin) && Update localStorage UserObjekt mit Lektion
getLektion(splitLektion(clickedItemId));
localStorage.setItem("aktLektion", clickedItemId);
$("#navEditor li").removeClass("active");
$("#liHTML").addClass("active");
});
$("#navEditor li").click(function(){
switch(this.id){
case "liHTML":
$("#editorHTML").show();
$("#editorCSS").hide();
break;
case "liCSS":
$("#editorHTML").hide();
$("#editorCSS").show();
setCode("css", localStorage.getItem("aktLektion"));
break;
}
$("#navEditor li").removeClass("active");
$(this).addClass("active");
});
});
</script>
</head>
<body>
<div class="wrap">
<div id="navi">
<p>Hallo, <span id="username"></span>!<button onclick="logout()">logout</button></p>
<ul>
<li id="lektion">Lektionen
</li>
<!--<li id="administration" style="display:none;">Administration</li>-->
</ul>
</div>
<div id="content">
<h1>
Herzlich Willkommen im Übungsportal zur Lehrveranstaltung Einführung Interaktive Medien.
</h1>
<button id="saveButton" onclick="saveLektion()" style="display:none;">Lektion speichern</button>
<button id="resetButton" onclick="resetLektion()" style="display:none;">Code zurücksetzen</button>
<div id="allLektionen" style="display:none;">
<h2></h2>
<ul>
</ul>
</div>
<div id="admin" style="display:none;">
<h2>Administration</h2>
</div>
<div id="coding" style="display:none;">
<h2></h2>
<h3 id="console"></h3>
<div class="left">
<div id="navEditor">
<ul>
<li id="liHTML">HTML</li>
</ul>
</div>
<div id="editorHTML">
<textarea id="code" name="code"></textarea>
</div>
<div id="editorCSS" style="display:none;">
<textarea id="codeCSS" name="codeCSS"></textarea>
</div>
</div>
<div id="previewDiv">
<div id="navEditorPreview">
<ul>
<li id="liVorschau">Vorschau</li>
</ul>
</div>
<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();
// Check codeHTML auf <title>-Tag und ersetze Text Vorschau
var splitTitle1 = codeHTML.split("<title>");
if(splitTitle1[1]){
var splitTitle2 = splitTitle1[1].split("</title>");
var title = $.trim(splitTitle2[0]);
if(title.length == 0){
title = "Vorschau";
}
$("#liVorschau").html(title);
}else{
$("#liVorschau").html("Vorschau");
}
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>
</div>
</div>
</body>
</html>