2017-06-15 19:28:54 +00:00
|
|
|
|
|
|
|
window.onload = function(){
|
2017-06-16 17:37:58 +00:00
|
|
|
makeScenario = function(scenario){
|
2017-06-15 19:28:54 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//output element, that other elements are attached to
|
|
|
|
let $outputElement = $("<li></li>")
|
|
|
|
$outputElement.attr("id", "scenarios-"+scenario.name);
|
2017-06-15 23:08:23 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//Mature Content rating
|
2017-06-15 23:08:23 +00:00
|
|
|
if(scenario.adult == true){
|
2017-06-16 17:37:58 +00:00
|
|
|
$adultText = $("<p>(question for those over the age of 18... or those mature enough)</p>");
|
|
|
|
$adultText.addClass("adult");
|
|
|
|
|
|
|
|
$outputElement.append($adultText);
|
|
|
|
$outputElement.addClass("adult-scenario");
|
2017-06-15 23:08:23 +00:00
|
|
|
}
|
2017-06-15 19:28:54 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//description
|
|
|
|
$descriptionElement = $("<p>" + scenario.description +"</p>");
|
|
|
|
|
|
|
|
//option list
|
|
|
|
$optionElement = $("<ul></ul>");
|
2017-06-15 23:08:23 +00:00
|
|
|
for(option of scenario.options){
|
2017-06-16 17:37:58 +00:00
|
|
|
//Create radio button
|
|
|
|
$inputTag = $("<input>");
|
|
|
|
$inputTag.attr("type", "radio");
|
|
|
|
$inputTag.attr("name", "radio-"+scenario.name);
|
|
|
|
|
|
|
|
//Populate list element
|
|
|
|
$newOption = $("<li></li>");
|
|
|
|
$newOption.append($inputTag);
|
|
|
|
$newOption.append(option);
|
|
|
|
$optionElement.append($newOption);
|
|
|
|
|
2017-06-15 23:08:23 +00:00
|
|
|
}
|
2017-06-16 17:37:58 +00:00
|
|
|
//Other Question
|
2017-06-15 23:33:36 +00:00
|
|
|
if (scenario.other){
|
2017-06-16 17:37:58 +00:00
|
|
|
$otherElement = $("<li>Other... <input type=text></li>");
|
|
|
|
$optionElement.append($otherElement);
|
2017-06-15 23:33:36 +00:00
|
|
|
}
|
2017-06-15 19:28:54 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//Default question, always shows up
|
|
|
|
$whyElement = $("<p>Why would you choose this awnser?</p>");
|
2017-06-15 23:08:23 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//Awnser space for the default element
|
|
|
|
$whyResponseElement = $("<textArea></textArea>")
|
|
|
|
$whyResponseElement.attr("placeholder", "Enter response here");
|
2017-06-15 23:33:36 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//Populate outputElement
|
|
|
|
$outputElement.append($descriptionElement);
|
|
|
|
$outputElement.append($optionElement);
|
|
|
|
$outputElement.append($whyElement);
|
|
|
|
$outputElement.append($whyResponseElement);
|
|
|
|
|
|
|
|
//Extra Question
|
2017-06-15 23:33:36 +00:00
|
|
|
if(scenario.question){
|
|
|
|
$question = $("<p>" + scenario.question + "</p>");
|
2017-06-16 17:37:58 +00:00
|
|
|
$questionResponse = $("<textArea></textArea>");
|
|
|
|
$questionResponse.attr("placeholder", "Enter response here");
|
|
|
|
|
|
|
|
$outputElement.append($question);
|
|
|
|
$outputElement.append($questionResponse);
|
2017-06-15 23:33:36 +00:00
|
|
|
}
|
2017-06-15 22:23:51 +00:00
|
|
|
|
2017-06-16 17:37:58 +00:00
|
|
|
//Submission button
|
|
|
|
$submitElement = $("<input>");
|
|
|
|
$submitElement.attr("type", "submit");
|
|
|
|
$submitElement.append("Submit");
|
|
|
|
$outputElement.append($("<br /><br />"));
|
|
|
|
$outputElement.append($submitElement);
|
|
|
|
|
|
|
|
return $outputElement;
|
2017-06-15 22:23:51 +00:00
|
|
|
}
|
2017-06-15 19:28:54 +00:00
|
|
|
|
2017-06-15 23:08:23 +00:00
|
|
|
$.getJSON("./resources/questions/scenarios.json", "", function(data){
|
|
|
|
for(const scenario of data.scenarios){
|
2017-06-16 17:37:58 +00:00
|
|
|
$("#scenarios").append(makeScenario(scenario));
|
2017-06-15 23:08:23 +00:00
|
|
|
}
|
2017-06-15 22:35:01 +00:00
|
|
|
});
|
2017-06-15 23:08:23 +00:00
|
|
|
}
|