Add comments and ensure questions are created without previous state. [HFP-56]
parent
a95d0be8e0
commit
568e0992e5
|
@ -146,11 +146,9 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
questionOrder = contentData.previousState.order;
|
questionOrder = contentData.previousState.order;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create a pool of questions if necessary
|
|
||||||
/**
|
/**
|
||||||
* Randomizes questions in an array and updates an array containing their order
|
* Randomizes questions in an array and updates an array containing their order
|
||||||
* @param {array} questions
|
* @param {array} questions
|
||||||
* @param {array} questionOrder
|
|
||||||
* @return {Object.<array, array>} questionOrdering
|
* @return {Object.<array, array>} questionOrdering
|
||||||
*/
|
*/
|
||||||
var randomizeQuestionOrdering = function (questions) {
|
var randomizeQuestionOrdering = function (questions) {
|
||||||
|
@ -239,21 +237,26 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generates question instances from H5P objects
|
||||||
|
*
|
||||||
|
* @param {object} questions H5P content types to be created as instances
|
||||||
|
* @return {array} Array of questions instances
|
||||||
|
*/
|
||||||
var createQuestionInstancesFromQuestions = function(questions) {
|
var createQuestionInstancesFromQuestions = function(questions) {
|
||||||
|
|
||||||
var result = [];
|
var result = [];
|
||||||
// Create question instances from questions
|
// Create question instances from questions
|
||||||
// Instantiate question instances
|
// Instantiate question instances
|
||||||
for (var i = 0; i < params.questions.length; i++) {
|
for (var i = 0; i < questions.length; i++) {
|
||||||
|
|
||||||
var question;
|
var question;
|
||||||
// If a previous order exists, use it
|
// If a previous order exists, use it
|
||||||
if (questionOrder !== undefined) {
|
if (questionOrder !== undefined) {
|
||||||
question = params.questions[questionOrder[i]];
|
question = questions[questionOrder[i]];
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
// Use a generic order when initialzing for the first time
|
// Use a generic order when initialzing for the first time
|
||||||
question = params.questions[i];
|
question = questions[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (override) {
|
if (override) {
|
||||||
|
@ -451,7 +454,12 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
* @public
|
* @public
|
||||||
*/
|
*/
|
||||||
var resetTask = function () {
|
var resetTask = function () {
|
||||||
|
|
||||||
|
// Clear previous state to ensure questions are created cleanly
|
||||||
|
contentData.previousState = [];
|
||||||
|
|
||||||
showingSolutions = false;
|
showingSolutions = false;
|
||||||
|
|
||||||
for (var i = 0; i < questionInstances.length; i++) {
|
for (var i = 0; i < questionInstances.length; i++) {
|
||||||
try {
|
try {
|
||||||
questionInstances[i].resetTask();
|
questionInstances[i].resetTask();
|
||||||
|
@ -533,6 +541,12 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
replaceQuestionsInDOM(questionInstances);
|
replaceQuestionsInDOM(questionInstances);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Empty the DOM of all questions, attach new questions and update buttons
|
||||||
|
*
|
||||||
|
* @param {type} questionInstances Array of questions to be attached to the DOM
|
||||||
|
*/
|
||||||
var replaceQuestionsInDOM = function (questionInstances) {
|
var replaceQuestionsInDOM = function (questionInstances) {
|
||||||
|
|
||||||
// Find all question containers and detach questions from them
|
// Find all question containers and detach questions from them
|
||||||
|
@ -803,7 +817,11 @@ H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
// Function for attaching the multichoice to a DOM element.
|
|
||||||
|
/**
|
||||||
|
* Initialize a question and attach it to the DOM
|
||||||
|
*
|
||||||
|
*/
|
||||||
function initializeQuestion() {
|
function initializeQuestion() {
|
||||||
// Attach questions
|
// Attach questions
|
||||||
for (var i = 0; i < questionInstances.length; i++) {
|
for (var i = 0; i < questionInstances.length; i++) {
|
||||||
|
|
Loading…
Reference in New Issue