Stop multiple classes being added to each question

[HFP-56]
pull/4/head^2
Timothy Lim 2016-10-18 15:06:44 +02:00
parent c16422f13d
commit a9d5c9b9a3
1 changed files with 13 additions and 8 deletions

View File

@ -135,7 +135,6 @@ H5P.QuestionSet = function (options, contentId, contentData) {
var renderSolutions = false; var renderSolutions = false;
var showingSolutions = false; var showingSolutions = false;
contentData = contentData || {}; contentData = contentData || {};
var answerIndex;
// Bring question set up to date when resuming // Bring question set up to date when resuming
if (contentData.previousState) { 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 * Randomizes elements in an array and updates a map of the order
* @param elements * @param {array} elements
* @param map * @param {array} map
* @return {array} * @return {Object.<array, array>} elements and indexes
*/ */
var randomizeElements = function (elements, map) { var randomizeElements = function (elements, map) {
// Save the original order of the elements in a nested array [[element1,0],[element2,1]... // 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 // Retrieve elements and indexes
elements = tuples.map(d => d[0]); elements = elementsAndIndexes.map(d => d[0]);
map = tuples.map(d => d[1]); map = elementsAndIndexes.map(d => d[1]);
return { return {
elements:elements, elements:elements,
@ -225,6 +224,8 @@ H5P.QuestionSet = function (options, contentId, contentData) {
// Randomize questions only on instantiation // Randomize questions only on instantiation
if (params.randomQuestions && contentData.previousState === undefined) { if (params.randomQuestions && contentData.previousState === undefined) {
$('.question-container.h5p-question', $myDom).attr('class','');
var result = randomizeElements(questionInstances,questionOrder); var result = randomizeElements(questionInstances,questionOrder);
questionInstances = result.elements; questionInstances = result.elements;
questionOrder = result.map; questionOrder = result.map;
@ -457,6 +458,10 @@ H5P.QuestionSet = function (options, contentId, contentData) {
var question = questionInstances[i]; 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)); question.attach($('.question-container:eq(' + i + ')', $myDom));
//Show buttons if necessary //Show buttons if necessary