diff --git a/static/quiz_item.coffee b/static/quiz_item.coffee index efdb116..d8adbbb 100644 --- a/static/quiz_item.coffee +++ b/static/quiz_item.coffee @@ -1,13 +1,16 @@ linearMode = false linearCount = 0 selection = null +itemMax = 1 refreshQuestion = () -> if(sessionStorage.getItem('user_items')) items = JSON.parse(sessionStorage.getItem('user_items')) + itemMax = items.length if linearMode selection = items[linearCount] linearCount++ + refreshQuizCounter() if linearCount >= items.length # Wrap around linearCount = 0 else @@ -91,12 +94,18 @@ $('#filter-form').submit( (e) -> toggleQuizMode = () -> linearMode = !linearMode if linearMode + document.getElementById('quiz-counter').style.visibility = "visible" $('#mode-toggle').text("Linear Mode") else linearCount = 0 + document.getElementById('quiz-counter').style.visibility = "hidden" $('#mode-toggle').text("Random Mode") refreshQuestion() +refreshQuizCounter = () -> + document.getElementById('current-quiz').value = linearCount + document.getElementById('total-quiz').textContent = "/" + itemMax + $(document).keypress (e) -> if(e.which == 13) $("#submit-answer").click(); @@ -141,6 +150,15 @@ $('#error-area').find('button').click () -> $('#success-area').find('button').click () -> $('#success-area').hide() +$('#skip-to-item').click (e) -> + e.preventDefault() + targetValue = document.getElementById('current-quiz').value - 1 + if(targetValue >= 0 && targetValue < itemMax) + linearCount = targetValue + refreshQuestion() + else + refreshQuizCounter() + $ -> $(document).ready -> $('[data-toggle="tooltip"]').tooltip(); diff --git a/static/quiz_item.js b/static/quiz_item.js index a8eb283..0927d28 100644 --- a/static/quiz_item.js +++ b/static/quiz_item.js @@ -1,6 +1,6 @@ // Generated by CoffeeScript 1.10.0 (function() { - var filterQuestions, getItemTypeFilters, getSrsTypeFilters, linearCount, linearMode, refreshQuestion, selection, toggleQuizMode, updateQuizItemStats; + var filterQuestions, getItemTypeFilters, getSrsTypeFilters, itemMax, linearCount, linearMode, refreshQuestion, refreshQuizCounter, selection, toggleQuizMode, updateQuizItemStats; linearMode = false; @@ -8,13 +8,17 @@ selection = null; + itemMax = 1; + refreshQuestion = function() { var input_element, items; if (sessionStorage.getItem('user_items')) { items = JSON.parse(sessionStorage.getItem('user_items')); + itemMax = items.length; if (linearMode) { selection = items[linearCount]; linearCount++; + refreshQuizCounter(); if (linearCount >= items.length) { linearCount = 0; } @@ -136,14 +140,21 @@ toggleQuizMode = function() { linearMode = !linearMode; if (linearMode) { + document.getElementById('quiz-counter').style.visibility = "visible"; $('#mode-toggle').text("Linear Mode"); } else { linearCount = 0; + document.getElementById('quiz-counter').style.visibility = "hidden"; $('#mode-toggle').text("Random Mode"); } return refreshQuestion(); }; + refreshQuizCounter = function() { + document.getElementById('current-quiz').value = linearCount; + return document.getElementById('total-quiz').textContent = "/" + itemMax; + }; + $(document).keypress(function(e) { if (e.which === 13) { return $("#submit-answer").click(); @@ -204,6 +215,18 @@ return $('#success-area').hide(); }); + $('#skip-to-item').click(function(e) { + var targetValue; + e.preventDefault(); + targetValue = document.getElementById('current-quiz').value - 1; + if (targetValue >= 0 && targetValue < itemMax) { + linearCount = targetValue; + return refreshQuestion(); + } else { + return refreshQuizCounter(); + } + }); + $(function() { return $(document).ready(function() { $('[data-toggle="tooltip"]').tooltip(); diff --git a/templates/quiz.html b/templates/quiz.html index c348a27..aac5aef 100644 --- a/templates/quiz.html +++ b/templates/quiz.html @@ -65,6 +65,17 @@
+
+
+ +
+