diff --git a/js/questionset.js b/js/questionset.js index fcc3e62..b0be1d5 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -135,7 +135,6 @@ H5P.QuestionSet = function (options, contentId, contentData) { var renderSolutions = false; var showingSolutions = false; contentData = contentData || {}; - var answerIndex; // Bring question set up to date when resuming if (contentData.previousState) { @@ -200,20 +199,20 @@ H5P.QuestionSet = function (options, contentId, contentData) { /** * Randomizes elements in an array and updates a map of the order - * @param elements - * @param map - * @return {array} + * @param {array} elements + * @param {array} map + * @return {Object.} elements and indexes */ var randomizeElements = function (elements, map) { // Save the original order of the elements in a nested array [[element1,0],[element2,1]... - var tuples = elements.map(function(object, index) { return [object, index] }); + var elementsAndIndexes = elements.map(function(object, index) { return [object, index] }); - tuples = H5P.shuffleArray(tuples); + elementsAndIndexes = H5P.shuffleArray(elementsAndIndexes); // Retrieve elements and indexes - elements = tuples.map(d => d[0]); - map = tuples.map(d => d[1]); + elements = elementsAndIndexes.map(d => d[0]); + map = elementsAndIndexes.map(d => d[1]); return { elements:elements, @@ -225,6 +224,8 @@ H5P.QuestionSet = function (options, contentId, contentData) { // Randomize questions only on instantiation if (params.randomQuestions && contentData.previousState === undefined) { + $('.question-container.h5p-question', $myDom).attr('class',''); + var result = randomizeElements(questionInstances,questionOrder); questionInstances = result.elements; questionOrder = result.map; @@ -457,6 +458,10 @@ H5P.QuestionSet = function (options, contentId, contentData) { var question = questionInstances[i]; + // Make sure styles are not being added twice + var lastClass = $('.question-container:eq(' + i + ')', $myDom).attr("class").split(' ').pop(); + $('.question-container:eq(' + i + ')', $myDom).removeClass(lastClass); + question.attach($('.question-container:eq(' + i + ')', $myDom)); //Show buttons if necessary