/
index.html
executable file
·410 lines (392 loc) · 16.9 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="description" content="">
<meta name="author" content="">
<link rel="icon" href="favicon.ico">
<title>Tafels oefenen</title>
<!-- Bootstrap core CSS -->
<link href="vendor/bootstrap/css/bootstrap.min.css" rel="stylesheet">
<!-- Font Awesome -->
<link href="//maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css" rel="stylesheet">
<!-- Custom styles for this template -->
<link href="style.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<div class="site-wrapper">
<div class="site-wrapper-inner">
<div class="cover-container">
<div class="masthead clearfix">
<div class="inner">
<h3 class="masthead-brand">Tafels oefenen</h3>
<ul class="nav masthead-nav">
<li class="mode-1 active"><a href="#"><span class="glyphicon glyphicon-random"></span></a></li>
<li class="mode-2"><a href="#">2</a></li>
<li class="mode-3"><a href="#">3</a></li>
<li class="mode-4"><a href="#">4</a></li>
<li class="mode-5"><a href="#">5</a></li>
<li class="mode-6"><a href="#">6</a></li>
<li class="mode-7"><a href="#">7</a></li>
<li class="mode-8"><a href="#">8</a></li>
<li class="mode-9"><a href="#">9</a></li>
<li class="mode-10"><a href="#">10</a></li>
</ul>
</div>
</div>
<div class="inner cover">
<!-- #loading -->
<div id="loading">
<p>Bezig met laden...</p>
</div>
<!-- /#loading -->
<!-- #intro -->
<div id="intro"><p class="lead">Hoi! Tafels oefenen is niet altijd zo leuk, maar je leert er wel snel mee rekenen. Daarom krijg je na elke vijf juiste oplossingen hier een grappig filmpje te zien. Je kiest zelf welke tafels je wil oefenen, bovenaan de pagina. Opgelet! Telkens je daar een nieuwe tafel kiest, begint de teller weer van voren.</p>
<div class="buttons">
<button type="button" class="btn btn-lg btn-primary btn-tafel1" ><span class="glyphicon glyphicon-random"></span></button>
<button type="button" class="btn btn-lg btn-primary btn-tafel2" >2</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel3" >3</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel4" >4</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel5" >5</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel6" >6</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel7" >7</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel8" >8</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel9" >9</button>
<button type="button" class="btn btn-lg btn-primary btn-tafel10" >10</button>
</div>
</div>
<!-- /#intro -->
<!-- #success -->
<div id="outro-success"><p class="lead">Joechei! 't Is gedaan!</p>
<button type="button" class="btn btn-lg btn-primary startbtn" >Opnieuw!</button>
</div>
<!-- /#success -->
<!-- #fail -->
<div id="outro-fail"><p class="lead">Oeps, dat duurde iets te lang!</p>
<button type="button" class="btn btn-lg btn-primary startbtn" >Opnieuw!</button>
</div>
<!-- /#fail -->
<!-- #gif -->
<div id="intermission">
<div id="gifholder">
<img class="funnygif" src="funnygifs/cat1.gif" height="50%">
</div>
<button type="button" class="btn btn-lg btn-primary contbtn" >Verder</button>
</div>
<!-- /#gif -->
<!-- # excercise -->
<div id="excercise"><h1 class="cover-heading"><span id="firstpart"></span> x <span id="secondpart"></span> <span id="feedback"></span></h1>
<table class="table table-bordered" id="honderdveld">
<tr>
<td>Bezig met laden...</td>
</tr>
</table>
<!-- <button type="button" class="btn btn-lg btn-primary" id="nextbtn">Volgende</button> -->
</div>
<!-- /#excercise -->
</div>
<div class="mastfoot">
<div class="inner" id="progress">
<div id="orientation"><span id="currentex">1</span> van <span id="totalex">10</span></div>
<div class="progress">
<div id="countdownbar" class="progress-bar progress-bar-success" role="progressbar" style="width: 100%">
</div>
</div>
</div>
<div class="inner">
Gemaakt door <a href="http://www.automaton.be/">Toon Van de Putte</a> - <a href="https://github.com/toonvandeputte/tafels-oefenen"><i class="fa fa-github"></i> project op Github</a> - Sommige gifs © <a href="http://www.romain-laurent.com/">Romain Laurent</a>.
</div>
</div>
</div>
</div>
</div>
<!-- Bootstrap core JavaScript
================================================== -->
<!-- Placed at the end of the document so the pages load faster -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="vendor/bootstrap/js/bootstrap.min.js"></script>
<script>
$( document ).ready(function() {
$(document).bind("mobileinit", function() {
$.mobile.defaultPageTransition = 'none';
$.mobile.page.prototype.options.addBackBtn = true;
$.mobile.useFastClick = false;
});
$("#loading").hide();
$("#intro").show();
// begin initial data
var countdowninterval = null;
var multitables = [2,3,4,5,6,7,8,9,10];
var multipliers = [1,2,3,4,5,6,7,8,9,10];
var excounter = 0;
var tablemode =1;
var timetocount = 0;
var timeleft = 0
var timeperq = 4;
var penalty = 2;
var bonus = 1;
var enabled = false;
var playcounts = new Array();
var funnygifs = new Array();
$.getJSON("gifs.json", function(jsondata) {
enabled = true;
console.log(jsondata["funnygifs"]);
$.each(jsondata["funnygifs"], function(key,entry){
playcounts[entry]=0;
funnygifs.push(entry)
});
console.log(funnygifs);
});
console.table(playcounts);
// end initial data
// begin mode selector
for (m=1,mlen=10; m<=mlen;m++) {
$("li.mode-"+m+" a").data( "mode", m );
$("#intro .btn-tafel"+m).data( "mode", m );
//console.log("mode set: "+$("#intro .btn-tafel"+m).data( "mode"));
$("li.mode-"+m+" a").bind('click',function(){
$(".masthead-nav li").removeClass("active");
$(this).parent().addClass("active");
tablemode = $(this).data("mode");
startRun($(this).data("mode"));
//console.log($(this).data("mode"));
});
$("#intro .btn-tafel"+m).bind('click',function(){
//console.log("mode: "+$(this).data("mode"));
$(".masthead-nav li").removeClass("active");
$("li.mode-"+$(this).data("mode")).addClass("active");
tablemode = $(this).data("mode");
startRun($(this).data("mode"));
//console.log($(this).data("mode"));
});
}
// end mode selector
function startRun(tablemode) {
window.clearInterval(countdowninterval);
excounter = 0;
timetocount = 0;
//console.log("tablemode: "+tablemode);
$("#intro").hide();
$("#intermission").hide();
$("#outro-fail").hide();
$("#outro-success").hide();
$("#excercise").show();
$("#progress").show();
goTables(tablemode);
}
function drawField() {
var fieldhtml ="";
for(var row = 0, rlen = 10; row< rlen; row++) {
fieldhtml+="<tr>";
for(var cell = 1, clen = 10; cell<= clen; cell++) {
var cellval=(row*10)+cell;
var before="";
var after="";
var specialclass="";
if (cellval%5===0) {
var before="<strong>";
var after="</strong>";
var specialclass="hilite";
}
fieldhtml+="<td class='clickcell "+specialclass+"' id='cell"+cellval+"'>"+before+"<a class='celllink' data-value='"+cellval+"' href='?firstpart="+window.qtoshow[0].firstpart+"&secondpart="+window.qtoshow[0].secondpart+"&answer="+cellval+"'>"+cellval+"</a>"+after+"</td>";
}
fieldhtml+="</tr>";
}
$("#honderdveld").html(fieldhtml);
$(".celllink").bind('click',function(event){
event.preventDefault();
$(".celllink").removeClass("hilite");
$(this).addClass("hilite");
var answerclicked = parseInt($(this).attr("data-value"));
checkAnswer(answerclicked);
//console.log($(this).attr("data-value"));
});
//console.log(fieldhtml);
}
function goTables(limit) {
if (multitables.indexOf(limit) > -1) {
var mytables = [limit];
window.questions = [];
for(var i = 0, len = mytables.length; i< len; i++) {
var secondpart = mytables[i];
for(var j = 0, jlen = multipliers.length; j< jlen; j++) {
var firstpart = multipliers[j];
var solution = firstpart*secondpart;
var thisquestion = Object.create(null);
thisquestion.firstpart = firstpart;
thisquestion.secondpart = secondpart;
thisquestion.solution = solution;
window.questions.push(thisquestion);
}
}
} else {
var mytables = multitables.slice(0);
var mymultis = multipliers.slice(0);
window.questions = [];
for (var i=0;i<10;i++) {
a=Math.floor(Math.random()*(mytables.length));
b=Math.floor(Math.random()*(mymultis.length));
var firstpart = mytables[a];
var secondpart = mymultis.splice(b, 1)[0];
/*console.log("--- "+i+" ---");
console.log("firstpart: "+firstpart+"(el "+a+") "+mytables.length);
console.log("secondpart: "+secondpart+"(el "+b+") "+mymultis.length);*/
var solution = firstpart*secondpart;
var thisquestion = Object.create(null);
thisquestion.firstpart = firstpart;
thisquestion.secondpart = secondpart;
thisquestion.solution = solution;
window.questions.push(thisquestion);
}
//var mytables = multitables;
//console.log("all tables");
//console.table(window.questions);
}
$("#totalex").html(window.questions.length);
timetocount=window.questions.length*timeperq;
timeleft = timetocount;
updateBar();
window.paused=false;
countdowninterval = window.setInterval(trackTime,1000);
getQuestion();
}
function continueRun() {
$("#intermission").hide();
$("#excercise").show();
$("#progress").show();
//countdowninterval = window.setInterval(trackTime,1000);
window.paused=false;
}
function trackTime() {
if (window.paused===false){
timeleft--;
}
updateBar();
//console.log("timeleft: "+timeleft+" / countdowninterval:"+countdowninterval+" / timetocount: "+timetocount+" / relval: "+relval);
}
function updateBar() {
if (timeleft<0) {
timeleft=0;
if (window.questions.length>0) {
$("#excercise").hide();
$("#outro-fail").show();
}
}
relval=(timeleft/timetocount)*100;
//console.log(relval);
$("#countdownbar").css("width",relval+"%");
}
function findagif(playcount) {
if (playcount==undefined) {
playcount=0;
}
mygif = funnygifs[Math.floor(Math.random()*funnygifs.length)];
console.log("mygif: "+mygif);
loopcounter=0;
while (playcounts[mygif]!=playcount) {
mygif = funnygifs[Math.floor(Math.random()*funnygifs.length)];
loopcounter++;
if (loopcounter>=funnygifs.length) {
playcount++;
loopcounter=0;
}
}
//console.log("starting recursive function");
/*findagif(playcount);*/
return mygif;
}
function showIntermission(){
//window.clearInterval(countdowninterval);
window.paused=true;
valtocheck=undefined;
window.currentgif=findagif();
console.log(window.currentgif);
playcounts[mygif]+=1;
console.table(playcounts);
$("#progress").hide();
$("#excercise").hide();
$("#intermission").show();
$("#gifholder").html('<img class="funnygif" src="funnygifs/'+window.currentgif+'" width="80%">');
if (window.questions.length===0) {
$(".contbtn").bind('click',function(){
window.clearInterval(countdowninterval);
//console.log("interval "+countdowninterval+" should be cleared");
$("#excercise").hide();
$("#outro-success").show();
});
} else {
$(".contbtn").bind('click',function(){
continueRun();
});
}
}
function getQuestion(q) {
if (window.questions.length===0) {
$("#excercise").hide();
$("#outro-success").show();
window.clearInterval(countdowninterval);
//console.log("interval "+countdowninterval+" should be cleared");
} else {
if (excounter%3===0&&excounter>0) {
showIntermission();
}
excounter++;
$("#currentex").html(excounter);
//console.log("excounter: "+excounter);
if (q===undefined || q < 0) {
if (window.questions.length===1) {
q=0;
} else {
q=Math.floor(Math.random()*(window.questions.length));
}
}
//console.log("get question: "+q);
window.qtoshow = window.questions.splice(q, 1);
//console.log(qtoshow[0]);
//console.log(qtoshow[0].firstpart);
$("#firstpart").html(window.qtoshow[0].firstpart);
$("#secondpart").html(window.qtoshow[0].secondpart);
$("#feedback").html("<span class='glyphicon glyphicon-question-sign'></span>");
drawField();
$('#nextbtn').prop('disabled', true);
//console.table(qtoshow);
}
}
function checkAnswer(answer){
//console.log(answer+" / "+window.qtoshow[0].solution);
if (answer===window.qtoshow[0].solution) {
timeleft+=bonus;
//updateBar();
$("#feedback").html("<span class='glyphicon glyphicon-ok-circle'></span>");
//$('#nextbtn').prop('disabled', false);
window.timeOutID=window.setTimeout(getQuestion,(bonus*1000));
} else {
//timeleft-=penalty;
//updateBar();
$("#feedback").html("<span class='glyphicon glyphicon-remove-circle'></span>");
$('#nextbtn').prop('disabled', true);
}
}
//initial button activate
$(".startbtn").bind('click',function(){
startRun(tablemode);
});
$(".contbtn").bind('click',function(){
continueRun();
});
// next button action
$('#nextbtn').bind('click',function(){
getQuestion();
//console.log(window.questions.length);
});
});
</script>
</body>
</html>