mirror of
https://github.com/jspsych/jsPsych.git
synced 2025-05-12 08:38:11 +00:00
Add some comment
This commit is contained in:
parent
a30088fe48
commit
ee4755fcaa
@ -79,6 +79,7 @@ var schema = {
|
|||||||
var type = question.type;
|
var type = question.type;
|
||||||
var value;
|
var value;
|
||||||
switch (type) {
|
switch (type) {
|
||||||
|
// codes for select component
|
||||||
case "select":
|
case "select":
|
||||||
|
|
||||||
// check answer
|
// check answer
|
||||||
@ -103,6 +104,8 @@ var schema = {
|
|||||||
}
|
}
|
||||||
// check required field
|
// check required field
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// codes for toggle type component
|
||||||
case "checkbox":
|
case "checkbox":
|
||||||
case "radio":
|
case "radio":
|
||||||
case "switch":
|
case "switch":
|
||||||
@ -145,13 +148,15 @@ var schema = {
|
|||||||
// check required field
|
// check required field
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
// codes for other type questions
|
||||||
default:
|
default:
|
||||||
|
|
||||||
// check answer
|
// check answer
|
||||||
if (question.correct == undefined)
|
if (question.correct == undefined)
|
||||||
value = document.getElementById(question.id).value;
|
value = document.getElementById(question.id).value;
|
||||||
else {
|
else {
|
||||||
// standardize
|
// standardize the inputs to string
|
||||||
var tempVal = "{0}".format(document.getElementById(question.id).value);
|
var tempVal = "{0}".format(document.getElementById(question.id).value);
|
||||||
var correct = "{0}".format(question.correct);
|
var correct = "{0}".format(question.correct);
|
||||||
|
|
||||||
@ -511,6 +516,7 @@ var schema = {
|
|||||||
} else
|
} else
|
||||||
this.star = "";
|
this.star = "";
|
||||||
|
|
||||||
|
// processing question_description
|
||||||
this.question_description = item.question_description || "";
|
this.question_description = item.question_description || "";
|
||||||
this.question_description_size = item.question_description_size || "14px";
|
this.question_description_size = item.question_description_size || "14px";
|
||||||
this.question_description_color = item.question_description_color || "grey-600";
|
this.question_description_color = item.question_description_color || "grey-600";
|
||||||
@ -1232,6 +1238,7 @@ Dropdown.prototype._option_factory = function() {
|
|||||||
item.correctAnswers = item.correctAnswers || [];
|
item.correctAnswers = item.correctAnswers || [];
|
||||||
Tag.call(this, parent_id, item);
|
Tag.call(this, parent_id, item);
|
||||||
|
|
||||||
|
// Process for standardizing item.values. Details are in the above comment
|
||||||
for (var i in item.labels) {
|
for (var i in item.labels) {
|
||||||
if (item.values.length < item.labels.length)
|
if (item.values.length < item.labels.length)
|
||||||
item.values.push(item.labels[i]);
|
item.values.push(item.labels[i]);
|
||||||
@ -1246,8 +1253,13 @@ Dropdown.prototype._option_factory = function() {
|
|||||||
item.values.push(item.images[i]);
|
item.values.push(item.images[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// end of process for standardizing item.values
|
||||||
|
|
||||||
this.values = item.values;
|
this.values = item.values;
|
||||||
this.labels = item.labels;
|
this.labels = item.labels;
|
||||||
|
|
||||||
|
// check if user chooses the correct answer
|
||||||
|
// Here is the initializtion
|
||||||
this.correctAnswers = {};
|
this.correctAnswers = {};
|
||||||
for (var i = 0; i < item.correctAnswers.length; i++)
|
for (var i = 0; i < item.correctAnswers.length; i++)
|
||||||
this.correctAnswers[item.correctAnswers[i]] = true;
|
this.correctAnswers[item.correctAnswers[i]] = true;
|
||||||
@ -1260,9 +1272,13 @@ Dropdown.prototype._option_factory = function() {
|
|||||||
item.label = this.labels[i];
|
item.label = this.labels[i];
|
||||||
item.value = this.values[i];
|
item.value = this.values[i];
|
||||||
item.id = ""; // initialize item.id
|
item.id = ""; // initialize item.id
|
||||||
|
|
||||||
|
// check if user chooses the correct answer
|
||||||
|
// Here does the check by if object this.correctAnswers has the key whose name == item.value
|
||||||
if (this.correctAnswers[item.value] == undefined)
|
if (this.correctAnswers[item.value] == undefined)
|
||||||
this.correctAnswers[item.value] = false;
|
this.correctAnswers[item.value] = false;
|
||||||
item.correct = this.correctAnswers[item.value];
|
item.correct = this.correctAnswers[item.value];
|
||||||
|
|
||||||
product = factory(this.parent_id, item);
|
product = factory(this.parent_id, item);
|
||||||
this.products.push(product);
|
this.products.push(product);
|
||||||
this.html += product.html + "\n";
|
this.html += product.html + "\n";
|
||||||
|
Loading…
Reference in New Issue
Block a user