diff --git a/static/quiz_item.coffee b/static/quiz_item.coffee index 253f01c..414acfc 100644 --- a/static/quiz_item.coffee +++ b/static/quiz_item.coffee @@ -1,7 +1,16 @@ +linearMode = false +linearCount = 0; + refreshQuestion = () -> if(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(''); $("#kana").removeClass("correct").val(''); $("#question-area").text(''); @@ -70,8 +79,18 @@ $('#filter-form').submit( (e) -> e.preventDefault() filterQuestions() $('#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) -> if(e.which == 13) $("#submit-answer").click(); @@ -112,4 +131,5 @@ $('#success-area').find('button').click () -> $ -> $(document).ready -> $('[data-toggle="tooltip"]').tooltip(); + document.getElementById('mode-toggle').onclick = toggleQuizMode filterQuestions() diff --git a/static/quiz_item.js b/static/quiz_item.js index c8effc1..9aea6b5 100644 --- a/static/quiz_item.js +++ b/static/quiz_item.js @@ -1,12 +1,24 @@ // Generated by CoffeeScript 1.10.0 (function() { - var filterQuestions, getItemTypeFilters, getSrsTypeFilters, refreshQuestion, updateQuizItemStats; + var filterQuestions, getItemTypeFilters, getSrsTypeFilters, linearCount, linearMode, refreshQuestion, toggleQuizMode, updateQuizItemStats; + + linearMode = false; + + linearCount = 0; refreshQuestion = function() { var input_element, items, selection; if (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(''); $("#kana").removeClass("correct").val(''); $("#question-area").text(''); @@ -110,9 +122,21 @@ $('#filter-form').submit(function(e) { e.preventDefault(); 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) { if (e.which === 13) { return $("#submit-answer").click(); @@ -164,6 +188,7 @@ $(function() { return $(document).ready(function() { $('[data-toggle="tooltip"]').tooltip(); + document.getElementById('mode-toggle').onclick = toggleQuizMode; return filterQuestions(); }); }); diff --git a/templates/quiz.html b/templates/quiz.html index 6c504af..65a7d7c 100644 --- a/templates/quiz.html +++ b/templates/quiz.html @@ -11,7 +11,7 @@