diff --git a/js/main.js b/js/main.js index b577d6d..8b93e4c 100644 --- a/js/main.js +++ b/js/main.js @@ -8,7 +8,7 @@ window.exam_mode = false; window.packet_list = []; -// var questions = null +window.questions = null; window.question_order = []; window.number_of_questions = null; window.question_type = null; @@ -19,7 +19,6 @@ window.allow_self_marking = true; window.dfile = null; - retrievePacketList(); /** @@ -28,23 +27,19 @@ retrievePacketList(); * and then fallback to packets.json */ function retrievePacketList() { - $.getJSON("packets/", function(data) { + $.getJSON("packets/", function (data) { loadPacketList(data); }) - .done(function() { - }) - .fail(function() { - $.getJSON("packets/packets.json", function(data) { - loadPacketList(data); - }) - .fail(function() { - console.log("No packet list available"); - showLoginDialog(); - }); - }) - .always(function() { + .done(function () {}) + .fail(function () { + $.getJSON("packets/packets.json", function (data) { + loadPacketList(data); + }).fail(function () { + console.log("No packet list available"); + showLoginDialog(); }); - + }) + .always(function () {}); // setUpPacket(questions); } @@ -56,11 +51,12 @@ function retrievePacketList() { */ function loadPacketList(data) { window.packet_list = data.packets; - window.packet_list.forEach(function(packet) { + window.packet_list.forEach(function (packet) { $("#packet-list").append( - $("
").click(function() { - loadPacketFromAjax("packets/" + packet); - })); + $("").click(function () { + loadPacketFromAjax("packets/" + packet); + }) + ); }); $("#options-panel").show(); } @@ -71,46 +67,45 @@ function loadPacketList(data) { */ function loadPacketFromAjax(path) { console.log("loading packet from " + path); - $.getJSON(path, function(data) { + $.getJSON(path, function (data) { setUpPacket(data); $("#options-panel").hide(); }) - .done(function() { - }) - .fail(function() { - console.log("Unable to load packet at: " + path); - }); + .done(function () {}) + .fail(function () { + console.log("Unable to load packet at: " + path); + }); } /** * Build the currently loaded quiz */ function setUpQuestions() { - if (questions == undefined) { + if (window.questions == undefined) { return; } // Set an order for the questions window.question_order = []; - Object.keys(questions).forEach(function(e) { + Object.keys(window.questions).forEach(function (e) { window.question_order.push(e); // Make sure answers are arrays - if (!Array.isArray(questions[e]["answers"])) { - questions[e]["answers"] = [questions[e]["answers"]]; + if (!Array.isArray(window.questions[e]["answers"])) { + window.questions[e]["answers"] = [window.questions[e]["answers"]]; } }); console.log("pre", window.question_order); window.question_order = helper.shuffleArray(window.question_order); console.log("post", window.question_order); - window.number_of_questions = Object.keys(questions).length; + window.number_of_questions = Object.keys(window.questions).length; window.review = false; console.log(window.question_order); // Horrible way to get type of questions // We assume they are all of the same type.... if (window.question_type == null) { - window.question_type = questions[Object.keys(questions)[0]].type; + window.question_type = window.questions[Object.keys(window.questions)[0]].type; } if (window.exam_mode) { @@ -183,7 +178,6 @@ function setUpPacket(data) { setUpQuestions(); } - /** * Loads a specific question * @param {number} n - Question number to load @@ -197,7 +191,7 @@ function loadQuestion(n, section = 1, force_reload = false) { const qid = window.question_order[n]; console.log("qid", qid); - const current_question = questions[qid]; + const current_question = window.questions[qid]; console.log("N=", n, section, current_question); @@ -216,33 +210,33 @@ function loadQuestion(n, section = 1, force_reload = false) { $(".navigation[value='previous']").attr("disabled", "disabled"); } else { $(".navigation[value='previous']") - .removeAttr("disabled") - .click(function() { - loadQuestion(n - 1); - }); + .removeAttr("disabled") + .click(function () { + loadQuestion(n - 1); + }); } if (n == window.number_of_questions - 1) { $(".navigation[value='next']").attr("disabled", "disabled"); } else { $(".navigation[value='next']") - .removeAttr("disabled") - .click(function() { - loadQuestion(n + 1); - }); + .removeAttr("disabled") + .click(function () { + loadQuestion(n + 1); + }); } const display_n = n + 1; if (current_question.title) { $(".question .title").get(0).innerHTML = - "" + + '' + display_n + " " + current_question.title; } else { $(".question .title").get(0).innerHTML = - "" + display_n + ""; + '' + display_n + ""; } // Close any open figures @@ -267,9 +261,9 @@ function loadQuestion(n, section = 1, force_reload = false) { } thumbnails.append( - "" + - display_n + - ".1Case normal/abnormal
' + + display_n + + '.1Case normal/abnormal
" + - display_n + - ".2Reason
" + - display_n + - ".1" + - current_question.question + - "
' + + display_n + + '.1' + + current_question.question + + '
" + - display_n + - ".1Observations
' + + display_n + + '.1Observations
" + - display_n + - ".2Interpretation
' + + display_n + + '.2Interpretation
" + - display_n + - ".3Principle Diagnosis
' + + display_n + + '.3Principle Diagnosis
" + - display_n + - ".4Differential Diagnosis
' + + display_n + + '.4Differential Diagnosis
" + - display_n + - ".5Management (if appropriate)
' + + display_n + + '.5Management (if appropriate)