-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
502 lines (493 loc) · 28.7 KB
/
index.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
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="description" content="A front-end template that helps you build fast, modern mobile web apps.">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Ask Questions</title>
<!-- Add to homescreen for Chrome on Android -->
<meta name="mobile-web-app-capable" content="yes">
<link rel="icon" sizes="192x192" href="images/android-desktop.png">
<!-- Add to homescreen for Safari on iOS -->
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<meta name="apple-mobile-web-app-title" content="Material Design Lite">
<link rel="apple-touch-icon-precomposed" href="images/ios-desktop.png">
<!-- Tile icon for Win8 (144x144 + tile color) -->
<meta name="msapplication-TileImage" content="images/touch/ms-touch-icon-144x144-precomposed.png">
<meta name="msapplication-TileColor" content="#3372DF">
<link rel="shortcut icon" href="images/favicon.png">
<!-- SEO: If your mobile URL is different from the desktop URL, add a canonical link to the desktop page https://developers.google.com/webmasters/smartphone-sites/feature-phones -->
<!--
<link rel="canonical" href="http://www.example.com/">
-->
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
rel="stylesheet">
<link href="https://fonts.googleapis.com/css?family=Roboto:regular,bold,italic,thin,light,bolditalic,black,medium&lang=en" rel="stylesheet">
<link rel="stylesheet" href="material.min.css">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="css/overlay.css">
<!-- Compiled and minified CSS -->
<link rel="stylesheet" href="css/materialize.css">
<script src="modernizr.custom.js"></script>
<!-- Compiled and minified JavaScript -->
<style>
#view-source {
position: fixed;
display: block;
right: 0;
bottom: 0;
margin-right: 40px;
margin-bottom: 40px;
z-index: 900;
}
#addButton {
position:fixed;
bottom:16px;
right:16px;
z-index:901;
}
</style>
</head>
<body>
<!-- Modal Structure -->
<div id="modal1" class="modal">
<div class="modal-content">
<h4>Provide your email</h4>
<div class="input-field">
<input id="email" type="email" class="validate">
<label for="email" data-error="Incorrect email address" data-success="Correct">Email</label>
</div>
</div>
<div class="modal-footer">
<a id="loginer" href="#!" onclick="checkLogin()" class="waves-effect waves-green btn-flat">Enter</a>
</div>
</div>
<!-- overlay -->
<div id="tst" class="overlay overlay-corner">
<button style="padding-left:0px;" type="button" class="overlay-close">Close Help Overlay<i class="material-icons">close</i></button>
<div style="margin-top:30px;text-align:left;width:20%;color:white;font-size:80%;position:absolute;top:35%;left:50%">
<h4>Icon overview</h4>
<p><i class="material-icons">lock_open</i> Question is private, but still open to answer</p>
<p><i class="material-icons">question_answer</i> Question is public and open to answer</p>
<p><i class="material-icons">lock</i> Question is closed</p>
</div>
<div style="color:white;position:fixed; bottom:10px; right:55px">
<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker style="color:white;" id="Triangle" viewBox="0 0 10 10" refX="1" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="white">
<path d="M 0 0 L 10 5 L 0 10 z"></path>
</marker>
</defs>
<text x="0" y="35" style="font-size:15;" fill="white">Add A Question</text>
<polyline points="10,50 10,80 90,80" fill="none" stroke="white" stroke-width="2" marker-end="url(#Triangle)"></polyline>
</svg>
</div>
<div style="color:white;position:fixed; top:20px; right:80px">
<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker style="color:white;" id="Triangle" viewBox="0 0 10 10" refX="1" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="white">
<path d="M 0 0 L 10 5 L 0 10 z"></path>
</marker>
</defs>
<text x="0" y="110" style="font-size:15;" fill="white">Search questions</text>
<polyline points="10,95 10,20 90,20" fill="none" stroke="white" stroke-width="2" marker-end="url(#Triangle)"></polyline>
</svg>
</div>
<div style="color:white;position:fixed; top:20px; left:350px">
<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker style="color:white;" id="Triangle" viewBox="0 0 10 10" refX="1" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="white">
<path d="M 0 0 L 10 5 L 0 10 z"></path>
</marker>
</defs>
<text x="22" y="60" style="font-size:15;" fill="white">Current course</text>
<polyline points="80,40 80,10 15,10" fill="none" stroke="white" stroke-width="2" marker-end="url(#Triangle)"></polyline>
</svg>
</div>
<div style="color:white;position:fixed; top:200px; left:250px">
<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker style="color:white;" id="Triangle" viewBox="0 0 10 10" refX="1" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="white">
<path d="M 0 0 L 10 5 L 0 10 z"></path>
</marker>
</defs>
<text x="22" y="60" style="font-size:15;" fill="white">All courses</text>
<polyline points="80,40 80,10 15,10" fill="none" stroke="white" stroke-width="2" marker-end="url(#Triangle)"></polyline>
</svg>
</div>
<div style="color:white;position:fixed; bottom:10px; left:150px">
<svg width="120" height="120" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker style="color:white;" id="Triangle" viewBox="0 0 10 10" refX="1" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="white">
<path d="M 0 0 L 10 5 L 0 10 z"></path>
</marker>
</defs>
<text x="22" y="20" style="font-size:15;" fill="white">Help Button</text>
<polyline points="80,50 80,110 10,110" fill="none" stroke="white" stroke-width="2" marker-end="url(#Triangle)"></polyline>
</svg>
</div>
<div style="color:white;position:fixed; top:0px; right:45px">
<svg width="120" height="220" viewBox="0 0 120 120" xmlns="http://www.w3.org/2000/svg" version="1.1" xmlns:xlink="http://www.w3.org/1999/xlink">
<defs>
<marker style="color:white;" id="Triangle" viewBox="0 0 10 10" refX="1" refY="5" markerWidth="6" markerHeight="6" orient="auto" fill="white">
<path d="M 0 0 L 10 5 L 0 10 z"></path>
</marker>
</defs>
<text x="0" y="110" style="font-size:12;" fill="white">Menu (logout, contact)</text>
<polyline points="110,95 110,10" fill="none" stroke="white" stroke-width="2" marker-end="url(#Triangle)"></polyline>
</svg>
</div>
</div>
<div class="demo-layout mdl-layout mdl-js-layout mdl-layout--fixed-drawer mdl-layout--fixed-header">
<header class="demo-header mdl-layout__header mdl-color--grey-100 mdl-color-text--grey-600">
<div class="mdl-layout__header-row">
<span class="mdl-layout-title">General</span>
<div class="mdl-layout-spacer"></div>
<div class="mdl-textfield mdl-js-textfield mdl-textfield--expandable">
<label style="bottom: 36px" class="mdl-button mdl-js-button mdl-button--icon" for="search">
<i class="material-icons">search</i>
</label>
<div class="mdl-textfield__expandable-holder">
<input class="mdl-textfield__input" type="text" id="search">
<label style="top:16px;" class="mdl-textfield__label" for="search">Provide a query...</label>
</div>
</div>
<button class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon" id="hdrbtn">
<i class="material-icons">more_vert</i>
</button>
<ul class="mdl-menu mdl-js-menu mdl-js-ripple-effect mdl-menu--bottom-right" for="hdrbtn">
<li class="mdl-menu__item">About</li>
<li class="mdl-menu__item">Contact</li>
<li class="mdl-menu__item"><a onclick="sessionStorage.removeItem('email');sleep(50);window.location='';return false;" href="">Logout</a></li>
</ul>
</div>
</header>
<div class="demo-drawer mdl-layout__drawer mdl-color--blue-grey-900 mdl-color-text--blue-grey-50">
<header class="demo-drawer-header">
<img id="avatar" src="images/user.jpg" class="demo-avatar">
<div class="demo-avatar-dropdown">
<span id="loginName">[email protected]</span>
<div class="mdl-layout-spacer"></div>
<!-- <button id="accbtn" class="mdl-button mdl-js-button mdl-js-ripple-effect mdl-button--icon">
<i class="material-icons" role="presentation">arrow_drop_down</i>
</button>
<ul class="mdl-menu mdl-menu--bottom-right mdl-js-menu mdl-js-ripple-effect" for="accbtn">
<li class="mdl-menu__item">View Profile</li>
<li class="mdl-menu__item">Logout</li>
</ul> -->
</div>
</header>
<nav class="demo-navigation mdl-navigation mdl-color--blue-grey-800">
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">General</a>
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">Dutch</a>
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">Math</a>
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">French</a>
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">English</a>
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">History</a>
<a onclick="switchCourse(this.innerHTML);" class="mdl-navigation__link" href="#">Geography</a>
<div class="mdl-layout-spacer"></div>
<a class="mdl-navigation__link" id="trigger-overlay" href="#"><i class="mdl-color-text--blue-grey-400 material-icons" role="presentation">help_outline</i><span class="visuallyhidden">Help</span></a>
</nav>
</div>
<button id="addButton" onclick="drawNewQuestion()" class="mdl-button mdl-js-button mdl-button--fab mdl-js-ripple-effect mdl-button--colored">
<i class="material-icons">add</i>
</button>
<div class="mdl-tooltip mdl-tooltip--top" for="addButton">
Add a new question
</div>
<main class="mdl-layout__content mdl-color--grey-100">
<ul style="width:90%; margin:auto; margin-top:10px;" id="mainul" class="collapsible popout" data-collapsible="accordion">
<li>
<div class="collapsible-header"><i class="material-icons">filter_drama</i>First</div>
<div class="collapsible-body"><p>Lorem ipsum dolor sit amet.</p></div>
</li>
<li>
<div class="collapsible-header"><select>First</div>
<div class="collapsible-body"><p>Lorem ipsum dolor sit amet.</p></div>
</li>
<li>
<div class="collapsible-header"><i class="material-icons">filter_drama</i>First</div>
<div class="collapsible-body">
<p>Lorem ipsum dolor sit amet.</p>
<div class="collapsible-header"><i class="material-icons">reply</i></div>
<div><p>tester</p></div>
</div>
</li>
</ul>
</main>
</div>
<script src="jquery-2.1.4.min.js"></script>
<script src="classie.js"></script>
<script src="demo1.js"></script>
<script src="material.min.js"></script>
<script src="materialize.min.js"></script>
<script src="http://crypto-js.googlecode.com/svn/tags/3.0.2/build/rollups/md5.js"></script>
<script>
var questions = {
"General": [{open:true, private:false, title:'What time does the library open?', contents: 'I want to study very early because i am a good student. Can I come in at 8 AM?', author:'[email protected]', followup:{title: "Yes!", contents: "The library is open from 7:30 AM, feel free to study from then!", author:"[email protected]", followup:{title:"Thanks", contents: "Will sure do!", author: "[email protected]"}}}],
"Math": [{open:false, private:true, title:'Rather stupid question.', contents: 'How do I find the greatest denominator', author:'[email protected]', followup:{title: "Ugh...", contents: "Just read your book", author:"[email protected]", followup:{title:"OK", contents: "Will sure do!", author: "[email protected]"}}}],
"English": [],
"French": [{open:true, private:false, title:'Whats the translation of this text?', contents: 'Bonjour, je m\'appelle jaque. J\'étudie a le VUB.', author:'[email protected]'}],
"Dutch": [{open:false, private:false, title:'Is there still class?', contents: 'Because of the terror level in Brussels, I am wondering if class on monday is still on?', author:'[email protected]', followup:{title: "Yes!", contents: "Don't be afraid of terrorists!", author:"[email protected]"}}, {open:true, title:'Whats the translation of this text?', contents: 'Hallo, ik ben jaque en studeer op de VUB.', author:'[email protected]'}],
"History": [],
"Geography": [],
};
var authAr = {
"General": ["@personel.be"],
"Math": ["[email protected]"],
"English": ["[email protected]"],
"French": ["[email protected]"],
"Dutch": ["[email protected]"],
"History": ["[email protected]"],
"Geography": ["[email protected]"],
};
var currentCourse = "General";
var email = "";
var addQuestion = function (course, title, contents, author, private) {
questions[course].unshift({open:true, private:private, title:title, contents:contents, author:author});
sessionStorage.questions = JSON.stringify(questions);
};
var addFolowUp = function(course, idx, title, contents, author) {
var rec = function self(obj) {
if(obj["followup"]) {
return self(obj["followup"]);
} else {
obj["followup"] = {title:title, contents:contents, author:author};
return obj;
}
};
rec(questions[course][idx]);
};
var drawQuestions = function (course, highlight) {
if (highlight === undefined) {
highlight = "";
}
var search;
if(highlight == "") {
search = function(arr) { return arr; };
}else {
search = function(arr) {
var rec = function recer(obj) {
var res = false;
if(obj.title.search(highlight) != -1) {
obj.title = obj.title.replace(new RegExp(highlight,"g"), "<span style='background-color:yellow;'>" + highlight + "</span>");
res = true;
}
if(obj.contents.search(highlight) != -1) {
obj.contents = obj.contents.replace(new RegExp(highlight,"g"), "<span style='background-color:yellow;'>" + highlight + "</span>");
res = true;
}
if(obj.author.search(highlight) != -1) {
obj.author = obj.author.replace(new RegExp(highlight,"g"), "<span style='background-color:yellow;'>" + highlight + "</span>");
res = true;
}
if(obj["followup"]) {
var recres = recer(obj["followup"]);
return [recres[0] || res, obj];
}
return [res, obj];
};
arr = arr.map(function(obj) { var copy = $.extend(true, {}, obj); return rec(copy)});
var arr = arr.filter(function(val) { return val[0];});
return arr.map(function(val) { return val[1];});
};
}
var questionhtml = "<li>"+
"<div class=\"collapsible-header\"><i id=\"questionIDPLACEHOLDERicon\" class=\"material-icons\">ICONPLACEHOLDER</i>TITLEPLACEHOLDER</div>" +
"<div class=\"mdl-tooltip\" for=\"questionIDPLACEHOLDERicon\">" +
"TOOLTIPPLACEHOLDER" +
"</div>" +
"<div class=\"collapsible-body\"><p>CONTENTPLACEHOLDER</p><p style=\"font-style:oblique;text-align:right;width:100%;\">AUTHORPLACEHOLDER</p>"+
"FOLLOWUPPLACEHOLDER</div>" +
"</li>";
var followuphtml = "<div class=\"collapsible-header\"><i class=\"material-icons\">reply</i>TITLEPLACEHOLDER</div>" +
"<div><p>CONTENTPLACEHOLDER</p><p style=\"margin:0px;font-style:oblique;text-align:right;width:100%;\">AUTHORPLACEHOLDER</p></div>";
search(questions[course]);
var list = search(questions[course]).reduce(function(lststr, ogobj, ig, nore) {
var followuprec = function(obj, res, i) {
if(i != 0) {
var str = followuphtml.replace(/TITLEPLACEHOLDER/g, obj.title)
.replace(/CONTENTPLACEHOLDER/g, obj.contents)
.replace(/AUTHORPLACEHOLDER/g, obj.author);
} else {
var str = "";
}
var response = "";
if(ogobj.open && stauth(ig, course)) {
response = "<div class=\"collapsible-header\"><i class='material-icons'>question_answer</i><div style=\"padding-top:0;padding-bottom:0;\" class=\"mdl-textfield mdl-js-textfield\">" +
"<input class=\"mdl-textfield__input\" name=\"title"+ig+"\" type=\"text\" id=\"title\">" +
"<label style=\"top:0;\" class=\"mdl-textfield__label\" for=\"title\">Response Title</label>" +
"</div></div>" +
"<div style=\"margin-left:20px;\" class=\"mdl-textfield mdl-js-textfield\">" +
"<textarea class=\"mdl-textfield__input\" type=\"text\" name=\"content"+ig+"\" rows=\"5\" id=\"content\" ></textarea>" +
"<label class=\"mdl-textfield__label\" for=\"content\">Write a response...</label>" +
"</div>" +
"<p style=\"font-style:oblique;text-align:right;width:100%;padding-bottom:15px;padding-right:15px;\">" +
"<button onclick=\"respond("+ig+")\" class=\"mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent\">Respond!</button></p>";
}
if(obj["followup"]) {
return followuprec(obj["followup"], res + str, i + 1);
} else if(i != 0) {
return res + str + response;
} else {
return res + response;
}
};
if(auth(ig, currentCourse)) {
// Zoveel lelijke code :(
return lststr + questionhtml.replace(/TITLEPLACEHOLDER/g, ogobj.title + (adminauth(ig, currentCourse) ? "<i style=\"float:right\" onclick=\"toggleopen("+ig+");expand("+ig+");\" id=\"azr"+ig+"\" class='material-icons'>" + (ogobj.open? 'lock' : 'lock_open') + "</i><div class=\"mdl-tooltip\" for=\"azr"+ig+"\">" + (ogobj.open ? 'Close this question' : 'Open this question') + "</div>" + "<i style=\"float:right\" onclick=\"toggleprivate("+ig+");expand("+ig+");\" id=\"azrr"+ig+"\" class='material-icons'>" + (ogobj.private? 'people' : 'person') + "</i><div class=\"mdl-tooltip\" for=\"azrr"+ig+"\">" + (ogobj.private ? 'Make this question public' : 'Make this question private') + "</div>" : ""))
.replace(/CONTENTPLACEHOLDER/g, ogobj.contents)
.replace(/ICONPLACEHOLDER/g, ogobj.open ? (ogobj.private ? 'lock_open' : 'question_answer'): 'lock')
.replace(/IDPLACEHOLDER/g, ig)
.replace(/TOOLTIPPLACEHOLDER/g, ogobj.open ? (ogobj.private ? 'This question is private<br>This question is open' : 'This question is open'): 'This question is closed')
.replace(/AUTHORPLACEHOLDER/g, ogobj.author)
.replace(/FOLLOWUPPLACEHOLDER/g, followuprec(ogobj, "", 0));
} else {
return lststr;
}
}, "");
if(list=="" && highlight=="") {
list = "<br /><br /><center><h4>No Questions for this course yet!</h4>Ask one by pressing the button in the bottom right corner!</center>";
} else if(list=="") {
list = "<br /><br /><center><h4>No Questions for the current search query!</h4>Ask one by pressing the button in the bottom right corner!</center>";
}
$("#mainul").html(list);
componentHandler.upgradeAllRegistered();
};
var drawNewQuestion = function() {
$("#questionForm").remove();
var questionhtml = "<li class=\"\" id=\"questionForm\">"+
"<div class=\"collapsible-header\"><i class='material-icons'>question_answer</i><div style=\"padding-top:0;padding-bottom:0;\" class=\"mdl-textfield mdl-js-textfield\">" +
"<input class=\"mdl-textfield__input\" name=\"title\" type=\"text\" id=\"title\">" +
"<label style=\"top:0;\" class=\"mdl-textfield__label\" for=\"title\">Question Title</label>" +
"</div><div onclick=\"$('#questionForm').remove()\" style=\"float:right;padding-top:5px;\"><i class='material-icons'>close</i></div></div>" +
"<div style=\"margin-left:20px;\" class=\"mdl-textfield mdl-js-textfield\">" +
"<textarea class=\"mdl-textfield__input\" type=\"text\" name=\"content\" cols=\"50\" rows=\"5\" id=\"content\" ></textarea>" +
"<label class=\"mdl-textfield__label\" for=\"content\">Ask a question...</label>" +
"</div>" +
"<div style=\"width:100%\">"+
"<label style=\"margin-left:21px;width:80px;\" id=\"tooltiplabel\" class=\"mdl-switch mdl-js-switch mdl-js-ripple-effect\" for=\"switch-1\">" +
"<input onclick=\"$(this).change(function(e) { $(e.target).next().html($(e.target).prop('checked') ? 'Private' : 'Public')})\" type=\"checkbox\" id=\"switch-1\" class=\"mdl-switch__input\" checked>" +
"<span class=\"mdl-switch__label\">Private</span>" +
"</label>" +
"</div>" +
"<div class=\"mdl-tooltip\" for=\"tooltiplabel\">" +
"Only your professor<br>will see this question" +
"</div>" +
"<p style=\"font-style:oblique;text-align:right;width:100%;padding-bottom:15px;padding-right:15px;\">" +
"<button onclick=\"addQuestionClick()\" class=\"mdl-button mdl-js-button mdl-button--raised mdl-js-ripple-effect mdl-button--accent\">Ask!</button></p>" +
"</li>";
$("#mainul").prepend(questionhtml);
componentHandler.upgradeAllRegistered();
$("#title").focus();
expand(0);
};
var auth = function(qidx, course) {
return ! questions[course][qidx].private
|| (questions[course][qidx].author == email)
|| (questions[course][qidx].private && authAr[course].reduce(function(prev, cur) {return prev || -1 != email.toLowerCase().search(cur)}, false));
};
var stauth = function(qidx, course) {
return (email.toLowerCase().search("@student.be") != -1) || adminauth(qidx, course);
};
var adminauth = function(qidx, course) {
return authAr[course].reduce(function(prev, cur) {return prev || -1 != email.toLowerCase().search(cur)}, false) || questions[course][qidx].author == email;
};
var toggleopen = function(qid) {
questions[currentCourse][qid].open = !questions[currentCourse][qid].open;
sessionStorage.questions = JSON.stringify(questions);
drawQuestions(currentCourse);
};
var toggleprivate = function(qid) {
questions[currentCourse][qid].private = !questions[currentCourse][qid].private;
sessionStorage.questions = JSON.stringify(questions);
drawQuestions(currentCourse);
};
var switchCourse = function(course) {
currentCourse = course;
$(".mdl-layout-title").html(currentCourse);
$("#mainul").html("");
drawQuestions(currentCourse);
return false;
};
var addQuestionClick = function() {
// TODO checks
addQuestion(currentCourse, $("#title").val(), $("#content").val(), email, $("#switch-1").prop('checked'));
drawQuestions(currentCourse);
};
var respond = function(idx){
var title = $('input[name=title'+idx+']').val();
var cont = $('textarea[name=content'+idx+']').val();
addFolowUp(currentCourse, idx, title, cont, email);
drawQuestions(currentCourse);
expand(idx);
};
var expand = function(idx) {
$('.collapsible-header').eq(idx).trigger('click');
}
var setEmail = function(lemail) {
email = lemail;
$("#loginName").html(email);
$("#avatar").prop('src', 'http://www.gravatar.com/avatar/' + CryptoJS.MD5(email));
sessionStorage.email = email;
sessionStorage.questions = JSON.stringify(questions);
};
var closeQuestion = function(qid) {
questions[currentCourse][qid].open = false;
drawQuestions(currentCourse);
expand(qid);
sessionStorage.questions = JSON.stringify(questions);
};
var checkLogin = function() {
var isValidEmailAddress= function(emailAddress) {
var pattern = /^([a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+(\.[a-z\d!#$%&'*+\-\/=?^_`{|}~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]+)*|"((([ \t]*\r\n)?[ \t]+)?([\x01-\x08\x0b\x0c\x0e-\x1f\x7f\x21\x23-\x5b\x5d-\x7e\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|\\[\x01-\x09\x0b\x0c\x0d-\x7f\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]))*(([ \t]*\r\n)?[ \t]+)?")@(([a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\d\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.)+([a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]|[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF][a-z\d\-._~\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF]*[a-z\u00A0-\uD7FF\uF900-\uFDCF\uFDF0-\uFFEF])\.?$/i;
return pattern.test(emailAddress);
}
var email = $("#email").val();
if(email.length == 0) {
alert("Please enter an email adress");
}
if(isValidEmailAddress(email)) {
setEmail(email);
$("#modal1").closeModal();
drawQuestions(currentCourse);
$("#trigger-overlay").trigger('click');
}
};
var init = function () {
if(!sessionStorage.email) {
$('#modal1').openModal({
dismissible:false,
opacity:0.8
});
} else {
email = sessionStorage.email;
questions = JSON.parse(sessionStorage.questions);
}
drawQuestions(currentCourse);
$("#email").keyup(function (e) {
if (e.keyCode == 13) {
checkLogin();
}
});
var focusfix = false;
$("#search").keyup(function (e) {
if (e.keyCode == 13) {
drawQuestions(currentCourse, $("#search").val());
focusfix=true;
}
});
$("#search").focusout(function (e) {
if(focusfix) {
focusfix = false;
} else {
drawQuestions(currentCourse, $("#search").val());
}
});
};
init();
</script>
</body>
</html>