diff --git a/ref-test/quiz/static/js/quiz.js b/ref-test/quiz/static/js/quiz.js index b71ed0e..344d849 100644 --- a/ref-test/quiz/static/js/quiz.js +++ b/ref-test/quiz/static/js/quiz.js @@ -21,20 +21,23 @@ $("#btn-toggle-navigator").click(function(event){ if ($quiz_navigator.is(":hidden")) { if ($quiz_settings.is(":visible")) { toggle_settings = true; - $quiz_settings.hide(); + $quiz_settings.fadeOut(); } - $quiz_render.hide(); - $quiz_navigator.show(); - $(".navigator-text").show(); - $(".review-text").hide(); + $quiz_render.fadeOut(); + $quiz_navigator.fadeIn(); + $(".navigator-text").fadeIn(); + $(".review-text").fadeOut(); toggle_navigator = false; + $quiz_navigator.focus(); } else { - $quiz_navigator.hide(); + $quiz_navigator.fadeOut(); if (toggle_settings) { - $quiz_settings.show(); + $quiz_settings.fadeIn(); + $quiz_settings.focus() toggle_settings = false; } else { - $quiz_render.show(); + $quiz_render.fadeIn(); + $question_title.focus(); } } event.preventDefault(); @@ -44,27 +47,31 @@ $("#btn-toggle-settings").click(function(event){ if (($quiz_settings).is(":hidden")) { if ($quiz_navigator.is(":visible")) { toggle_navigator = true; - $quiz_navigator.hide(); + $quiz_navigator.fadeOut(); } - $quiz_render.hide(); - $quiz_settings.show(); + $quiz_render.fadeOut(); + $quiz_settings.fadeIn(); + $quiz_settings.focus() toggle_settings = false; } else { - $quiz_settings.hide(); + $quiz_settings.fadeOut(); if (toggle_navigator) { - $quiz_navigator.show(); + $quiz_navigator.fadeIn(); toggle_navigator = false; + $quiz_navigator.focus(); } else { - $quiz_render.show(); + $quiz_render.fadeIn(); + $question_title.focus(); } } event.preventDefault(); }); $(".btn-quiz-return").click(function(event){ - $quiz_navigator.hide(); - $quiz_settings.hide(); - $quiz_render.show(); + $quiz_navigator.fadeOut(); + $quiz_settings.fadeOut(); + $quiz_render.fadeIn(); + $question_title.focus(); toggle_settings = false; toggle_navigator = false; event.preventDefault(); @@ -78,8 +85,9 @@ $("#navigator-container").on("click", ".q-navigator-button", function(event){ check_answered(); update_navigator(); current_question = parseInt($(this).attr("name")); - $quiz_render.show(); - $quiz_navigator.hide(); + $quiz_render.fadeIn(); + $question_title.focus(); + $quiz_navigator.fadeOut(); toggle_navigator = false; toggle_settings = false; render_question(); @@ -100,8 +108,8 @@ $(".q-question-nav").click(function(event){ } } else if ($(this).hasClass("q-navigator-button")) { current_question = $(this).attr("name"); - $quiz_render.show(); - $quiz_navigator.hide(); + $quiz_render.fadeIn(); + $quiz_navigator.fadeOut(); toggle_navigator = false; toggle_settings = false; } @@ -126,12 +134,6 @@ $("#q-nav-flag").click(function(event){ }); $("#btn-start-quiz").click(function(event){ - $(this).hide(); - $(".btn-quiz-return").show(); - $(".quiz-console").show(); - $("#quiz-settings").hide(); - $("#quiz-navigator").hide(); - $(".quiz-start-text").hide(); $.ajax({ url: `/api/questions/`, @@ -139,6 +141,12 @@ $("#btn-start-quiz").click(function(event){ data: JSON.stringify({'_id': _id}), contentType: "application/json", success: function(response) { + $(this).fadeOut(); + $(".btn-quiz-return").fadeIn(); + $(".quiz-console").fadeIn(); + $("#quiz-settings").fadeOut(); + $("#quiz-navigator").fadeOut(); + $(".quiz-start-text").fadeOut(); time_limit = response.time_limit; start_time = response.start_time; questions = response.questions; @@ -149,15 +157,32 @@ $("#btn-start-quiz").click(function(event){ render_question(); build_navigator(); check_flag(); - if (time_limit != 'null') { + if (time_limit != 'null' && time_limit != null) { + $("#q-timer-widget").fadeIn(); time_remaining = get_time_remaining(); clock = setInterval(timer, 1000); - } else { - $("#q-timer-widget").hide(); } }, error: function(response) { - console.log(response); + if (typeof response.responseJSON.error === 'string' || response.responseJSON.error instanceof String) { + alert.innerHTML = alert.innerHTML + ` +