civ/resources/questions/scenarios.js

45 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-06-15 19:28:54 +00:00
window.onload = function(){
addScenario = function(scenario){
2017-06-15 19:28:54 +00:00
2017-06-15 23:16:00 +00:00
let $liElement = $("<li id=\"scenarios-"+scenario.name+"\"></li>")
if(scenario.adult == true){
$adultText = $("<p class=\"adult\">(question for those over the age of 18... or those mature enough)</p>");
$liElement.append($adultText);
}
$description = $("<p>" + scenario.description +"</p>");
2017-06-15 19:28:54 +00:00
$options = $("<ul></ul>");
for(option of scenario.options){
2017-06-15 23:16:00 +00:00
$options.append($("<li><input type=\"radio\" name=\"radio-"+scenario.name+"\">" + option + "</radio></li>"));
}
if (scenario.other){
$options.append("<li>Other... <input type=text></li>");
}
2017-06-15 19:28:54 +00:00
$why = $("<p>Why would you choose this awnser?</p>");
$whyResponse = $("<textArea placeholder=\"Enter response here\"></textArea>")
$liElement.append($description);
$liElement.append($options);
$liElement.append($why);
$liElement.append($whyResponse);
if(scenario.question){
$question = $("<p>" + scenario.question + "</p>");
$questionResponse = $("<textArea placeholder=\"Enter response here\"></textArea>")
$liElement.append($question);
$liElement.append($questionResponse);
}
$("#scenarios").append($liElement);
}
2017-06-15 19:28:54 +00:00
$.getJSON("./resources/questions/scenarios.json", "", function(data){
for(const scenario of data.scenarios){
addScenario(scenario);
}
});
}