Linear mode now has tracking of the current quiz item index and allows skipping to the desired item.

closes #1
This commit is contained in:
neviyn 2016-02-19 17:49:33 +00:00
parent 45d6e6f30d
commit cf5852794b
3 changed files with 53 additions and 1 deletions

View File

@ -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();

View File

@ -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();

View File

@ -65,6 +65,17 @@
</div>
</nav>
<div class="container-fluid">
<div class="row">
<div class="col-md-2 col-md-offset-10">
<div id="quiz-counter" class="input-group" style="visibility: hidden">
<input id="current-quiz" type="number" class="form-control">
<span id="total-quiz" class="input-group-addon">/0</span>
<span class="input-group-btn">
<button class="btn btn-default" id="skip-to-item" type="button">Go!</button>
</span>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12 text-center">
<div id="error-area" class="alert alert-danger alert-dismissible collapse" role="alert">