Moved js files to global directory, added id system to question json

This commit is contained in:
Max Geldner
2018-11-17 13:12:04 +01:00
committed by Nanne Baars
parent 2962ddbb3e
commit 3a7601d348
275 changed files with 7 additions and 31 deletions

View File

@ -19,7 +19,8 @@
</div>
<div class="lesson-page-wrapper">
<script th:src="@{/lesson_js/quiz.js}" language="JavaScript"></script>
<span id="quiz_id" data-quiz_id="cia"></span>
<script th:src="@{/js/quiz.js}" language="JavaScript"></script>
<link rel="import" type="application/json" th:href="@{/lesson_js/questions.json}"/>
<div class="adoc-content" th:replace="doc:CIA_quiz.adoc"></div>
<div class="attack-container">

View File

@ -1,27 +0,0 @@
$(function () {
var json = "";
var client = new XMLHttpRequest();
client.open('GET', '/WebGoat/lesson_js/questions.json');
client.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
json += client.responseText;
console.log("entry");
let questionsJson = json;
var questionsObj = JSON.parse(questionsJson);
let html = "";
jQuery.each(questionsObj, function(i, obj) {
jQuery.each(obj, function(j, quest) {
html += "<div id='question_" + j + "' class='quiz_question' name='question' style='border: solid 1px; padding: 4px; margin: 5px 2px 5px 2px'><p>" + (j+1) + ".&nbsp;" + quest.text + "</p>";
html += "<fieldset>";
jQuery.each(quest.solutions, function(k, solution) {
solution = "Solution " + k + ": " + solution;
html += '<input type="checkbox" name="question_' + j +'_solution" value="' + solution + '">' + solution + '<br>';
});
html += "</fieldset></div>";
});
});
document.getElementById("q_container").innerHTML = html;
}
}
client.send();
});