learn.html
10.1 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
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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="Miguel Barão">
<title>iLearn</title>
<link rel="icon" href="/static/favicon.ico">
<!-- MathJax -->
<script type="text/x-mathjax-config">
MathJax.Hub.Config({
tex2jax: {
inlineMath: [["$$$","$$$"], ["$","$"], ["\\(","\\)"]]
}
});
</script>
<script type="text/javascript" src="/static/mathjax/MathJax.js?delayStartupUntil=onload&config=TeX-AMS_CHTML-full"></script>
<!-- Bootstrap -->
<link rel="stylesheet" href="/static/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="/static/css/bootstrap-theme.min.css"> <!-- optional -->
<!-- other -->
<link rel="stylesheet" href="/static/css/animate.min.css">
<link rel="stylesheet" href="/static/font-awesome/css/font-awesome.min.css">
<link rel="stylesheet" href="/static/css/github.css">
<link rel="stylesheet" href="/static/css/learn.css">
<script src="/static/js/jquery.min.js"></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
</head>
<!-- ===================================================================== -->
<body>
<!-- <audio>
<source id="snd-intro" src="/static/sounds/intro.mp3" type="audio/mpeg">
<source id="snd-correct" src="/static/sounds/correct.mp3" type="audio/mpeg">
<source id="snd-wrong" src="/static/sounds/wrong.mp3" type="audio/mpeg">
</audio> -->
<!-- Navbar -->
<nav class="navbar navbar-default navbar-fixed-top" role="navigation">
<div class="container-fluid">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#myNavbar" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="#">{{ title }}</a>
</div>
<!-- nav links and other content for toggling -->
<div class="collapse navbar-collapse" id="myNavbar">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a class="dropdown-toggle" data-toggle="dropdown" href="#">
<i class="fa fa-graduation-cap" aria-hidden="true"></i>
<span id="name"> {{ name }}</span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu">
<li><a data-toggle="modal" href="#password_modal"><i class="fa fa-key" aria-hidden="true"></i> Alterar password</a></li>
<li><a href="/logout"><i class="fa fa-sign-out" aria-hidden="true"></i> Sair</a></li>
</ul>
</li>
</ul>
</div>
</div>
</nav>
<!-- ===================================================================== -->
<div class="row-offcanvas row-offcanvas-left">
<!-- topics sidebar -->
<div id="sidebar" class="sidebar-offcanvas">
<div class="col-md-12">
<div id="topics"></div>
</div>
</div>
<!-- main panel with questions -->
<div id="main">
<div id="body">
<div class="progress">
<div class="progress-bar progress-bar-success" id="topic_progress" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" style="min-width: 0em;width: 0%"></div>
</div>
<div class="col-md-12">
<p class="visible-xs">
<button type="button" class="btn btn-primary btn-xs" data-toggle="offcanvas"><i class="glyphicon glyphicon-chevron-left"></i></button>
</p>
<div id="notifications">
<!-- notifications go here -->
</div>
<!-- Question body -->
<form action="/question" method="post" id="question_form" autocomplete="off">
{% module xsrf_form_html() %}
<div id="question_div">
<!-- questions go here -->
</div>
</form>
<button class="btn btn-primary" id="submit">Continuar</button>
</div>
</div> <!-- body -->
</div> <!-- main -->
</div>
<!-- === Change Password Modal =========================================== -->
<div id="password_modal" class="modal fade" tabindex="-1" role="dialog">
<div class="modal-dialog modal-sm" role="document">
<div class="modal-content">
<!-- header -->
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title">Alterar Password</h4>
</div>
<!-- body -->
<div class="modal-body">
<div class="control-group">
<label for="new_password" class="control-label">Nova Password</label>
<div class="controls">
<input type="password" id="new_password" name="new_password" autocomplete="new-password">
</div>
</div>
</div>
<!-- footer -->
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Cancelar</button>
<button id="change_password" type="button" class="btn btn-danger" data-dismiss="modal">Alterar</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
<!-- ===================================================================== -->
<!-- JAVASCRIP -->
<!-- ===================================================================== -->
<script>
$.fn.extend({
animateCSS: function (animation) {
var animationEnd = 'webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend';
this.addClass('animated ' + animation).one(animationEnd, function() {
$(this).removeClass('animated ' + animation);
});
}
});
// Processes the response given by the server after an answer is submitted.
function updateQuestion(response){
switch (response["method"]) {
case "new_question":
$("#question_div").html(response["params"]["question"]);
$("#topics").html(response["params"]["state"]);
$('#topic_progress').css('width', (100*response["params"]["progress"])+'%').attr('aria-valuenow', 100*response["params"]["progress"]);
MathJax.Hub.Queue(["Typeset",MathJax.Hub,"question_div"]);
// enable shift+enter to submit and tab to spaces conversion
$("input:text, input:radio, input:checkbox").keydown(function (e) {
if (e.keyCode == 13 && e.shiftKey) {
e.preventDefault();
postQuestion();
}
});
$("textarea").keydown(function (e) {
if (e.keyCode == 13 && e.shiftKey) { // shift enter
e.preventDefault();
postQuestion();
}
else if (e.keyCode === 9) { // tab
e.preventDefault(); // prevent loosing focus
// get caret position/selection
var start = this.selectionStart;
var end = this.selectionEnd;
var value = $(this).val();
// set textarea value to: text before caret + tab + text after caret
$(this).val(value.substring(0, start) + " " + value.substring(end));
// put caret at right position again (add one for the tab)
this.selectionStart = this.selectionEnd = start + 4;
}
});
// var audio = new Audio('/static/sounds/correct.mp3');
// audio.play();
$('#question_div').animateCSS('zoomIn');
break;
case "shake":
// var audio = new Audio('/static/sounds/wrong.mp3');
// audio.play();
$('#topic_progress').css('width', (100*response["params"]["progress"])+'%').attr('aria-valuenow', 100*response["params"]["progress"]);
$('#question_div').animateCSS('shake');
break;
}
}
// Send answer and receive a response.
// The response can be a new_question or a shake if the answer is wrong.
function postQuestion() {
$.ajax({
type: "POST",
url: "/question",
// headers: {"X-XSRFToken": token},
data: $("#question_form").serialize(), // {'a':10,'b':20},
dataType: "json", // expected from server
success: updateQuestion,
error: function() {alert("O servidor não responde.");}
});
}
// Send answer and receive a response.
// The response can be a new_question or a shake if the answer is wrong.
function getQuestion() {
$.ajax({
// type: "GET",
url: "/question",
// headers: {"X-XSRFToken": token},
// data: $("#question_form").serialize(), // {'a':10,'b':20},
dataType: "json", // expected from server
success: updateQuestion,
error: function() {alert("O servidor não responde.");}
});
}
function change_password() {
$.ajax({
type: "POST",
url: "/change_password",
data: {
"new_password": $("#new_password").val(),
},
dataType: "json",
success: function(r) {
$("#notifications").html(r["msg"]);
$("#notification").fadeIn(250).delay(5000).fadeOut(500);
},
error: function(r) {
$("#notifications").html(r["msg"]);
$("#notification").fadeIn(250).delay(5000).fadeOut(500);
},
});
}
$(document).ready(function() {
// var audio = new Audio('/static/sounds/intro.mp3');
// audio.play();
getQuestion();
$("#submit").click(postQuestion);
$('[data-toggle=offcanvas]').click(function() {
$('.row-offcanvas').toggleClass('active');
});
$("#change_password").click(change_password);
});
</script>
</body>
</html>