From 763d2dd41088419d6d118159f2736ee31e051fb7 Mon Sep 17 00:00:00 2001 From: Tom Arild Jakobsen Date: Mon, 14 Nov 2016 10:05:22 +0100 Subject: [PATCH 1/6] Hotfix --- js/questionset.js | 165 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 115 insertions(+), 50 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 9503447..4c40277 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -126,6 +126,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { var endTemplate = new EJS({text: resulttemplate}); var params = $.extend(true, {}, defaults, options); + var initialParams = $.extend(true, {}, defaults, options); var poolOrder; // Order of questions in a pool var currentQuestion = 0; var questionInstances = []; @@ -184,7 +185,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { questions: questions, questionOrder: newOrder }; - } + }; // Create a pool (a subset) of questions if necessary if (params.poolSize && params.poolSize < params.questions.length) { @@ -477,7 +478,61 @@ H5P.QuestionSet = function (options, contentId, contentData) { //Force the last page to be reRendered rendered = false; - if (params.randomQuestions) { + if(params.poolSize > 0){ + questionInstances = []; + + // Make new pool from params.questions + // Randomize and get the results + var poolResult = randomizeQuestionOrdering(initialParams.questions, poolOrder); + var poolQuestions = poolResult.questions; + poolOrder = poolResult.questionOrder; + + // Discard extra questions + poolQuestions = poolQuestions.slice(0, params.poolSize); + poolOrder = poolOrder.slice(0, params.poolSize); + + // Replace original questions with just the ones in the pool + params.questions = poolQuestions; + + // Create question instances from questions + // Instantiate question instances + for (var i = 0; i < params.questions.length; i++) { + + var question; + // If a previous order exists, use it + if (questionOrder !== undefined) { + question = params.questions[questionOrder[i]]; + } + else { + // Use a generic order when initialzing for the first time + question = params.questions[i]; + } + + if (override) { + // Extend subcontent with the overrided settings. + $.extend(question.params.behaviour, override); + } + + question.params = question.params || {}; + question.params.overrideSettings = question.params.overrideSettings || {}; + question.params.overrideSettings.$confirmationDialogParent = $template.last(); + question.params.overrideSettings.instance = this; + var hasAnswers = contentData.previousState && contentData.previousState.answers; + var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined, + { + previousState: hasAnswers ? contentData.previousState.answers[i] : undefined, + parent: self + }); + questionInstance.on('resize', function () { + up = true; + self.trigger('resize'); + }); + questionInstances.push(questionInstance); + } + + // Update buttons + initializeQuestion(); + } else if (params.randomQuestions) { randomizeQuestions(); } @@ -498,6 +553,11 @@ H5P.QuestionSet = function (options, contentId, contentData) { questionInstances = result.questions; questionOrder = result.questionOrder; + replaceQuestionsInDOM(questionInstances); + }; + + var replaceQuestionsInDOM = function (questionInstances) { + // Find all question containers and detach questions from them $('.question-container', $myDom).each(function (){ $(this).children().detach(); @@ -514,20 +574,22 @@ H5P.QuestionSet = function (options, contentId, contentData) { question.attach($('.question-container:eq(' + i + ')', $myDom)); //Show buttons if necessary + console.log('replaceQuestionsInDOM', questionInstances[0].getAnswerGiven()); + debugger; if(questionInstances[questionInstances.length -1] === question && question.hasButton('finish')) { - question.showButton('finish'); + question.showButton('finish'); } if(questionInstances[questionInstances.length -1] !== question && question.hasButton('next')) { - question.showButton('next'); + question.showButton('next'); } if(questionInstances[0] !== question && question.hasButton('prev') && !params.disableBackwardsNavigation) { - question.showButton('prev'); + question.showButton('prev'); } // Hide relevant buttons since the order has changed @@ -542,10 +604,8 @@ H5P.QuestionSet = function (options, contentId, contentData) { if (questionInstances[questionInstances.length-1] !== question) { question.hideButton('finish'); } - } - - } + }; var moveQuestion = function (direction) { if (params.disableBackwardsNavigation && !questionInstances[currentQuestion].getAnswerGiven()) { @@ -762,47 +822,14 @@ H5P.QuestionSet = function (options, contentId, contentData) { self.trigger('resize'); }; + var registerImageLoadedListener = function (question) { + H5P.on(question, 'imageLoaded', function () { + self.trigger('resize'); + }); + }; + // Function for attaching the multichoice to a DOM element. - this.attach = function (target) { - if (this.isRoot()) { - this.setActivityStarted(); - } - if (typeof(target) === "string") { - $myDom = $('#' + target); - } - else { - $myDom = $(target); - } - - // Render own DOM into target. - $myDom.children().remove(); - $myDom.append($template); - if (params.backgroundImage !== undefined) { - $myDom.css({ - overflow: 'hidden', - background: '#fff url("' + H5P.getPath(params.backgroundImage.path, contentId) + '") no-repeat 50% 50%', - backgroundSize: '100% auto' - }); - } - - if (params.introPage.backgroundImage !== undefined) { - var $intro = $myDom.find('.intro-page'); - if ($intro.length) { - var bgImg = params.introPage.backgroundImage; - var bgImgRatio = (bgImg.height / bgImg.width); - $intro.css({ - background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%', - backgroundSize: 'auto 100%', - minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','') - }); - } - } - var registerImageLoadedListener = function (question) { - H5P.on(question, 'imageLoaded', function () { - self.trigger('resize'); - }); - }; - + function initializeQuestion() { // Attach questions for (var i = 0; i < questionInstances.length; i++) { var question = questionInstances[i]; @@ -838,8 +865,8 @@ H5P.QuestionSet = function (options, contentId, contentData) { question.on('xAPI', function (event) { var shortVerb = event.getVerb(); if (shortVerb === 'interacted' || - shortVerb === 'answered' || - shortVerb === 'attempted') { + shortVerb === 'answered' || + shortVerb === 'attempted') { toggleAnsweredDot(currentQuestion, questionInstances[currentQuestion].getAnswerGiven()); _updateButtons(); @@ -857,6 +884,44 @@ H5P.QuestionSet = function (options, contentId, contentData) { // Mark question if answered toggleAnsweredDot(i, question.getAnswerGiven()); } + } + + this.attach = function (target) { + if (this.isRoot()) { + this.setActivityStarted(); + } + if (typeof(target) === "string") { + $myDom = $('#' + target); + } + else { + $myDom = $(target); + } + + // Render own DOM into target. + $myDom.children().remove(); + $myDom.append($template); + if (params.backgroundImage !== undefined) { + $myDom.css({ + overflow: 'hidden', + background: '#fff url("' + H5P.getPath(params.backgroundImage.path, contentId) + '") no-repeat 50% 50%', + backgroundSize: '100% auto' + }); + } + + if (params.introPage.backgroundImage !== undefined) { + var $intro = $myDom.find('.intro-page'); + if ($intro.length) { + var bgImg = params.introPage.backgroundImage; + var bgImgRatio = (bgImg.height / bgImg.width); + $intro.css({ + background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%', + backgroundSize: 'auto 100%', + minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','') + }); + } + } + + initializeQuestion(); // Allow other libraries to add transitions after the questions have been inited $('.questionset', $myDom).addClass('started'); From 1abac682cbc5c26d708e4cefdd118db11fc91128 Mon Sep 17 00:00:00 2001 From: Tom Arild Jakobsen Date: Mon, 14 Nov 2016 10:05:22 +0100 Subject: [PATCH 2/6] Hotfix. Relates to #HFP-200 --- js/questionset.js | 165 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 115 insertions(+), 50 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 9503447..4c40277 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -126,6 +126,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { var endTemplate = new EJS({text: resulttemplate}); var params = $.extend(true, {}, defaults, options); + var initialParams = $.extend(true, {}, defaults, options); var poolOrder; // Order of questions in a pool var currentQuestion = 0; var questionInstances = []; @@ -184,7 +185,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { questions: questions, questionOrder: newOrder }; - } + }; // Create a pool (a subset) of questions if necessary if (params.poolSize && params.poolSize < params.questions.length) { @@ -477,7 +478,61 @@ H5P.QuestionSet = function (options, contentId, contentData) { //Force the last page to be reRendered rendered = false; - if (params.randomQuestions) { + if(params.poolSize > 0){ + questionInstances = []; + + // Make new pool from params.questions + // Randomize and get the results + var poolResult = randomizeQuestionOrdering(initialParams.questions, poolOrder); + var poolQuestions = poolResult.questions; + poolOrder = poolResult.questionOrder; + + // Discard extra questions + poolQuestions = poolQuestions.slice(0, params.poolSize); + poolOrder = poolOrder.slice(0, params.poolSize); + + // Replace original questions with just the ones in the pool + params.questions = poolQuestions; + + // Create question instances from questions + // Instantiate question instances + for (var i = 0; i < params.questions.length; i++) { + + var question; + // If a previous order exists, use it + if (questionOrder !== undefined) { + question = params.questions[questionOrder[i]]; + } + else { + // Use a generic order when initialzing for the first time + question = params.questions[i]; + } + + if (override) { + // Extend subcontent with the overrided settings. + $.extend(question.params.behaviour, override); + } + + question.params = question.params || {}; + question.params.overrideSettings = question.params.overrideSettings || {}; + question.params.overrideSettings.$confirmationDialogParent = $template.last(); + question.params.overrideSettings.instance = this; + var hasAnswers = contentData.previousState && contentData.previousState.answers; + var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined, + { + previousState: hasAnswers ? contentData.previousState.answers[i] : undefined, + parent: self + }); + questionInstance.on('resize', function () { + up = true; + self.trigger('resize'); + }); + questionInstances.push(questionInstance); + } + + // Update buttons + initializeQuestion(); + } else if (params.randomQuestions) { randomizeQuestions(); } @@ -498,6 +553,11 @@ H5P.QuestionSet = function (options, contentId, contentData) { questionInstances = result.questions; questionOrder = result.questionOrder; + replaceQuestionsInDOM(questionInstances); + }; + + var replaceQuestionsInDOM = function (questionInstances) { + // Find all question containers and detach questions from them $('.question-container', $myDom).each(function (){ $(this).children().detach(); @@ -514,20 +574,22 @@ H5P.QuestionSet = function (options, contentId, contentData) { question.attach($('.question-container:eq(' + i + ')', $myDom)); //Show buttons if necessary + console.log('replaceQuestionsInDOM', questionInstances[0].getAnswerGiven()); + debugger; if(questionInstances[questionInstances.length -1] === question && question.hasButton('finish')) { - question.showButton('finish'); + question.showButton('finish'); } if(questionInstances[questionInstances.length -1] !== question && question.hasButton('next')) { - question.showButton('next'); + question.showButton('next'); } if(questionInstances[0] !== question && question.hasButton('prev') && !params.disableBackwardsNavigation) { - question.showButton('prev'); + question.showButton('prev'); } // Hide relevant buttons since the order has changed @@ -542,10 +604,8 @@ H5P.QuestionSet = function (options, contentId, contentData) { if (questionInstances[questionInstances.length-1] !== question) { question.hideButton('finish'); } - } - - } + }; var moveQuestion = function (direction) { if (params.disableBackwardsNavigation && !questionInstances[currentQuestion].getAnswerGiven()) { @@ -762,47 +822,14 @@ H5P.QuestionSet = function (options, contentId, contentData) { self.trigger('resize'); }; + var registerImageLoadedListener = function (question) { + H5P.on(question, 'imageLoaded', function () { + self.trigger('resize'); + }); + }; + // Function for attaching the multichoice to a DOM element. - this.attach = function (target) { - if (this.isRoot()) { - this.setActivityStarted(); - } - if (typeof(target) === "string") { - $myDom = $('#' + target); - } - else { - $myDom = $(target); - } - - // Render own DOM into target. - $myDom.children().remove(); - $myDom.append($template); - if (params.backgroundImage !== undefined) { - $myDom.css({ - overflow: 'hidden', - background: '#fff url("' + H5P.getPath(params.backgroundImage.path, contentId) + '") no-repeat 50% 50%', - backgroundSize: '100% auto' - }); - } - - if (params.introPage.backgroundImage !== undefined) { - var $intro = $myDom.find('.intro-page'); - if ($intro.length) { - var bgImg = params.introPage.backgroundImage; - var bgImgRatio = (bgImg.height / bgImg.width); - $intro.css({ - background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%', - backgroundSize: 'auto 100%', - minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','') - }); - } - } - var registerImageLoadedListener = function (question) { - H5P.on(question, 'imageLoaded', function () { - self.trigger('resize'); - }); - }; - + function initializeQuestion() { // Attach questions for (var i = 0; i < questionInstances.length; i++) { var question = questionInstances[i]; @@ -838,8 +865,8 @@ H5P.QuestionSet = function (options, contentId, contentData) { question.on('xAPI', function (event) { var shortVerb = event.getVerb(); if (shortVerb === 'interacted' || - shortVerb === 'answered' || - shortVerb === 'attempted') { + shortVerb === 'answered' || + shortVerb === 'attempted') { toggleAnsweredDot(currentQuestion, questionInstances[currentQuestion].getAnswerGiven()); _updateButtons(); @@ -857,6 +884,44 @@ H5P.QuestionSet = function (options, contentId, contentData) { // Mark question if answered toggleAnsweredDot(i, question.getAnswerGiven()); } + } + + this.attach = function (target) { + if (this.isRoot()) { + this.setActivityStarted(); + } + if (typeof(target) === "string") { + $myDom = $('#' + target); + } + else { + $myDom = $(target); + } + + // Render own DOM into target. + $myDom.children().remove(); + $myDom.append($template); + if (params.backgroundImage !== undefined) { + $myDom.css({ + overflow: 'hidden', + background: '#fff url("' + H5P.getPath(params.backgroundImage.path, contentId) + '") no-repeat 50% 50%', + backgroundSize: '100% auto' + }); + } + + if (params.introPage.backgroundImage !== undefined) { + var $intro = $myDom.find('.intro-page'); + if ($intro.length) { + var bgImg = params.introPage.backgroundImage; + var bgImgRatio = (bgImg.height / bgImg.width); + $intro.css({ + background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%', + backgroundSize: 'auto 100%', + minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','') + }); + } + } + + initializeQuestion(); // Allow other libraries to add transitions after the questions have been inited $('.questionset', $myDom).addClass('started'); From a95d0be8e08bca3196fb0496a06a9913511ee0ff Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Mon, 14 Nov 2016 11:31:15 +0100 Subject: [PATCH 3/6] Refactor createion of question pools. Refers to [H5P-56] --- js/questionset.js | 127 +++++++++++++++++++--------------------------- 1 file changed, 51 insertions(+), 76 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 4c40277..f2bd8b4 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -1,4 +1,4 @@ -var H5P = H5P || {}; +H5P = H5P || {}; /** * Will render a Question with multiple choices for answers. @@ -153,7 +153,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { * @param {array} questionOrder * @return {Object.} questionOrdering */ - var randomizeQuestionOrdering = function (questions, questionOrder) { + var randomizeQuestionOrdering = function (questions) { // Save the original order of the questions in a multidimensional array [[question0,0],[question1,1]... var questionOrdering = questions.map(function(questionInstance, index) { return [questionInstance, index] }); @@ -172,7 +172,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { for (var i = 0; i< questionOrdering.length; i++) { // Use a previous order if it exists - if(questionOrder) { + if(contentData.previousState && contentData.previousState.questionOrder) { newOrder[i] = questionOrder[questionOrdering[i][1]]; } else { @@ -180,7 +180,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { } } - // Return the questions in their new order *with* their new order + // Return the questions in their new order *with* their new indexes return { questions: questions, questionOrder: newOrder @@ -188,7 +188,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { }; // Create a pool (a subset) of questions if necessary - if (params.poolSize && params.poolSize < params.questions.length) { + if (params.poolSize > 0) { // If a previous pool exists, recreate it if(contentData.previousState && contentData.previousState.poolOrder) { @@ -205,7 +205,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { } else { // Otherwise create a new pool // Randomize and get the results - var poolResult = randomizeQuestionOrdering(params.questions, poolOrder); + var poolResult = randomizeQuestionOrdering(params.questions); var poolQuestions = poolResult.questions; poolOrder = poolResult.questionOrder; @@ -239,44 +239,54 @@ H5P.QuestionSet = function (options, contentId, contentData) { } } - // Instantiate question instances - for (var i = 0; i < params.questions.length; i++) { + var createQuestionInstancesFromQuestions = function(questions){ - var question; - // If a previous order exists, use it - if (questionOrder !== undefined) { - question = params.questions[questionOrder[i]]; - } - else { - // Use a generic order when initialzing for the first time - question = params.questions[i]; - } + var result = []; + // Create question instances from questions + // Instantiate question instances + for (var i = 0; i < params.questions.length; i++) { - if (override) { - // Extend subcontent with the overrided settings. - $.extend(question.params.behaviour, override); - } + var question; + // If a previous order exists, use it + if (questionOrder !== undefined) { + question = params.questions[questionOrder[i]]; + } + else { + // Use a generic order when initialzing for the first time + question = params.questions[i]; + } - question.params = question.params || {}; - question.params.overrideSettings = question.params.overrideSettings || {}; - question.params.overrideSettings.$confirmationDialogParent = $template.last(); - question.params.overrideSettings.instance = this; - var hasAnswers = contentData.previousState && contentData.previousState.answers; - var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined, - { - previousState: hasAnswers ? contentData.previousState.answers[i] : undefined, - parent: self + if (override) { + // Extend subcontent with the overrided settings. + $.extend(question.params.behaviour, override); + } + + question.params = question.params || {}; + question.params.overrideSettings = question.params.overrideSettings || {}; + question.params.overrideSettings.$confirmationDialogParent = $template.last(); + question.params.overrideSettings.instance = this; + var hasAnswers = contentData.previousState && contentData.previousState.answers; + var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined, + { + previousState: hasAnswers ? contentData.previousState.answers[i] : undefined, + parent: self + }); + questionInstance.on('resize', function () { + up = true; + self.trigger('resize'); }); - questionInstance.on('resize', function () { - up = true; - self.trigger('resize'); - }); - questionInstances.push(questionInstance); + result.push(questionInstance); + } + + return result; } + // Create question instances from questions given by params + questionInstances = createQuestionInstancesFromQuestions(params.questions); + // Randomize questions only on instantiation if (params.randomQuestions && contentData.previousState === undefined) { - var result = randomizeQuestionOrdering(questionInstances,questionOrder); + var result = randomizeQuestionOrdering(questionInstances); questionInstances = result.questions; questionOrder = result.questionOrder; } @@ -479,11 +489,10 @@ H5P.QuestionSet = function (options, contentId, contentData) { rendered = false; if(params.poolSize > 0){ - questionInstances = []; // Make new pool from params.questions // Randomize and get the results - var poolResult = randomizeQuestionOrdering(initialParams.questions, poolOrder); + var poolResult = randomizeQuestionOrdering(initialParams.questions); var poolQuestions = poolResult.questions; poolOrder = poolResult.questionOrder; @@ -494,44 +503,12 @@ H5P.QuestionSet = function (options, contentId, contentData) { // Replace original questions with just the ones in the pool params.questions = poolQuestions; - // Create question instances from questions - // Instantiate question instances - for (var i = 0; i < params.questions.length; i++) { - - var question; - // If a previous order exists, use it - if (questionOrder !== undefined) { - question = params.questions[questionOrder[i]]; - } - else { - // Use a generic order when initialzing for the first time - question = params.questions[i]; - } - - if (override) { - // Extend subcontent with the overrided settings. - $.extend(question.params.behaviour, override); - } - - question.params = question.params || {}; - question.params.overrideSettings = question.params.overrideSettings || {}; - question.params.overrideSettings.$confirmationDialogParent = $template.last(); - question.params.overrideSettings.instance = this; - var hasAnswers = contentData.previousState && contentData.previousState.answers; - var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined, - { - previousState: hasAnswers ? contentData.previousState.answers[i] : undefined, - parent: self - }); - questionInstance.on('resize', function () { - up = true; - self.trigger('resize'); - }); - questionInstances.push(questionInstance); - } + // Recreate the question instances + questionInstances = createQuestionInstancesFromQuestions(params.questions); // Update buttons initializeQuestion(); + } else if (params.randomQuestions) { randomizeQuestions(); } @@ -549,7 +526,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { */ var randomizeQuestions = function () { - var result = randomizeQuestionOrdering(questionInstances,questionOrder); + var result = randomizeQuestionOrdering(questionInstances); questionInstances = result.questions; questionOrder = result.questionOrder; @@ -574,8 +551,6 @@ H5P.QuestionSet = function (options, contentId, contentData) { question.attach($('.question-container:eq(' + i + ')', $myDom)); //Show buttons if necessary - console.log('replaceQuestionsInDOM', questionInstances[0].getAnswerGiven()); - debugger; if(questionInstances[questionInstances.length -1] === question && question.hasButton('finish')) { question.showButton('finish'); From 568e0992e55a20a03043ac300688ffa25341abb3 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Mon, 14 Nov 2016 15:22:43 +0100 Subject: [PATCH 4/6] Add comments and ensure questions are created without previous state. [HFP-56] --- js/questionset.js | 34 ++++++++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 8 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index f2bd8b4..a2bea2e 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -146,11 +146,9 @@ H5P.QuestionSet = function (options, contentId, contentData) { questionOrder = contentData.previousState.order; } - // Create a pool of questions if necessary /** * Randomizes questions in an array and updates an array containing their order * @param {array} questions - * @param {array} questionOrder * @return {Object.} questionOrdering */ var randomizeQuestionOrdering = function (questions) { @@ -239,21 +237,26 @@ H5P.QuestionSet = function (options, contentId, contentData) { } } - var createQuestionInstancesFromQuestions = function(questions){ - + /** + * 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 result = []; // Create question instances from questions // Instantiate question instances - for (var i = 0; i < params.questions.length; i++) { + for (var i = 0; i < questions.length; i++) { var question; // If a previous order exists, use it if (questionOrder !== undefined) { - question = params.questions[questionOrder[i]]; + question = questions[questionOrder[i]]; } else { // Use a generic order when initialzing for the first time - question = params.questions[i]; + question = questions[i]; } if (override) { @@ -451,7 +454,12 @@ H5P.QuestionSet = function (options, contentId, contentData) { * @public */ var resetTask = function () { + + // Clear previous state to ensure questions are created cleanly + contentData.previousState = []; + showingSolutions = false; + for (var i = 0; i < questionInstances.length; i++) { try { questionInstances[i].resetTask(); @@ -533,6 +541,12 @@ H5P.QuestionSet = function (options, contentId, contentData) { 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) { // 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() { // Attach questions for (var i = 0; i < questionInstances.length; i++) { From 163e3140599db7ba6026c7e2280d34ba6e9bdd56 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Mon, 14 Nov 2016 15:53:27 +0100 Subject: [PATCH 5/6] Make sure styles are not being added twice to questions [HFP-56] --- js/questionset.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/js/questionset.js b/js/questionset.js index a2bea2e..97ef90b 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -455,7 +455,7 @@ H5P.QuestionSet = function (options, contentId, contentData) { */ var resetTask = function () { - // Clear previous state to ensure questions are created cleanly + // Clear previous state to ensure questions are created cleanly contentData.previousState = []; showingSolutions = false; @@ -827,6 +827,9 @@ H5P.QuestionSet = function (options, contentId, contentData) { for (var i = 0; i < questionInstances.length; i++) { var question = questionInstances[i]; + // Make sure styles are not being added twice + $('.question-container:eq(' + i + ')', $myDom).attr('class', 'question-container'); + question.attach($('.question-container:eq(' + i + ')', $myDom)); // Listen for image resize From 34c951841a612666a1225d075f03eb08432f0569 Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Tue, 15 Nov 2016 12:44:17 +0100 Subject: [PATCH 6/6] Prepared release --- library.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library.json b/library.json index 1191c1b..7085667 100644 --- a/library.json +++ b/library.json @@ -4,7 +4,7 @@ "contentType": "question", "majorVersion": 1, "minorVersion": 10, - "patchVersion": 0, + "patchVersion": 1, "embedTypes": [ "iframe" ],