Added Linear Mode which quizzes all items in order.

This commit is contained in:
neviyn 2015-12-24 01:40:24 +00:00
parent a94dee2d97
commit 441623a947
3 changed files with 55 additions and 5 deletions

View File

@ -1,7 +1,16 @@
linearMode = false
linearCount = 0;
refreshQuestion = () -> refreshQuestion = () ->
if(sessionStorage.getItem('user_items')) if(sessionStorage.getItem('user_items'))
items = JSON.parse(sessionStorage.getItem('user_items')) items = JSON.parse(sessionStorage.getItem('user_items'))
selection = items[Math.floor(Math.random() * items.length)] if linearMode
selection = items[linearCount]
linearCount++
if linearCount >= items.length # Wrap around
linearCount = 0
else
selection = items[Math.floor(Math.random() * items.length)]
$("#help-area").text(''); $("#help-area").text('');
$("#kana").removeClass("correct").val(''); $("#kana").removeClass("correct").val('');
$("#question-area").text(''); $("#question-area").text('');
@ -70,8 +79,18 @@ $('#filter-form').submit( (e) ->
e.preventDefault() e.preventDefault()
filterQuestions() filterQuestions()
$('#modal-filter').modal('hide') $('#modal-filter').modal('hide')
linearCount = 0
) )
toggleQuizMode = () ->
linearMode = !linearMode
if linearMode
$('#mode-toggle').text("Linear Mode")
else
linearCount = 0
$('#mode-toggle').text("Random Mode")
refreshQuestion()
$(document).keypress (e) -> $(document).keypress (e) ->
if(e.which == 13) if(e.which == 13)
$("#submit-answer").click(); $("#submit-answer").click();
@ -112,4 +131,5 @@ $('#success-area').find('button').click () ->
$ -> $ ->
$(document).ready -> $(document).ready ->
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
document.getElementById('mode-toggle').onclick = toggleQuizMode
filterQuestions() filterQuestions()

View File

@ -1,12 +1,24 @@
// Generated by CoffeeScript 1.10.0 // Generated by CoffeeScript 1.10.0
(function() { (function() {
var filterQuestions, getItemTypeFilters, getSrsTypeFilters, refreshQuestion, updateQuizItemStats; var filterQuestions, getItemTypeFilters, getSrsTypeFilters, linearCount, linearMode, refreshQuestion, toggleQuizMode, updateQuizItemStats;
linearMode = false;
linearCount = 0;
refreshQuestion = function() { refreshQuestion = function() {
var input_element, items, selection; var input_element, items, selection;
if (sessionStorage.getItem('user_items')) { if (sessionStorage.getItem('user_items')) {
items = JSON.parse(sessionStorage.getItem('user_items')); items = JSON.parse(sessionStorage.getItem('user_items'));
selection = items[Math.floor(Math.random() * items.length)]; if (linearMode) {
selection = items[linearCount];
linearCount++;
if (linearCount >= items.length) {
linearCount = 0;
}
} else {
selection = items[Math.floor(Math.random() * items.length)];
}
$("#help-area").text(''); $("#help-area").text('');
$("#kana").removeClass("correct").val(''); $("#kana").removeClass("correct").val('');
$("#question-area").text(''); $("#question-area").text('');
@ -110,9 +122,21 @@
$('#filter-form').submit(function(e) { $('#filter-form').submit(function(e) {
e.preventDefault(); e.preventDefault();
filterQuestions(); filterQuestions();
return $('#modal-filter').modal('hide'); $('#modal-filter').modal('hide');
return linearCount = 0;
}); });
toggleQuizMode = function() {
linearMode = !linearMode;
if (linearMode) {
$('#mode-toggle').text("Linear Mode");
} else {
linearCount = 0;
$('#mode-toggle').text("Random Mode");
}
return refreshQuestion();
};
$(document).keypress(function(e) { $(document).keypress(function(e) {
if (e.which === 13) { if (e.which === 13) {
return $("#submit-answer").click(); return $("#submit-answer").click();
@ -164,6 +188,7 @@
$(function() { $(function() {
return $(document).ready(function() { return $(document).ready(function() {
$('[data-toggle="tooltip"]').tooltip(); $('[data-toggle="tooltip"]').tooltip();
document.getElementById('mode-toggle').onclick = toggleQuizMode;
return filterQuestions(); return filterQuestions();
}); });
}); });

View File

@ -11,7 +11,7 @@
</div> </div>
<form id="filter-form"> <form id="filter-form">
<div class="modal-body"> <div class="modal-body">
<label for=filter-input">Level</label><input type="text" pattern="\d[\d-,]*\d*" class="form-control" id="filter-input" placeholder="e.g. 1-3,5,8"> <label for=filter-input">Level</label><input type="text" pattern="\d[\d-,]*\d*" class="form-control" id="filter-input" placeholder="e.g. 1-3,5,8 (leave blank for all)">
<br /> <br />
<p><strong>Progress</strong></p> <p><strong>Progress</strong></p>
{% for srs_tag in srs_levels %} {% for srs_tag in srs_levels %}
@ -40,6 +40,11 @@
</a> </a>
</div> </div>
<ul class="nav navbar-nav navbar-right"> <ul class="nav navbar-nav navbar-right">
<li>
<button type="button" id="mode-toggle" class="btn btn-default navbar-btn">
Random Mode
</button>
</li>
<li> <li>
<button type="button" id="itemfilter" class="btn btn-default navbar-btn" data-toggle="modal" data-target="#modal-filter"> <button type="button" id="itemfilter" class="btn btn-default navbar-btn" data-toggle="modal" data-target="#modal-filter">
Filter Filter