From 2ebe9ad987936e588c47b37532f5df63c2f2fcc5 Mon Sep 17 00:00:00 2001 From: Timothy Lim Date: Wed, 19 Oct 2016 08:50:04 +0200 Subject: [PATCH] Rename variables in randomize function [HFP-56] --- js/questionset.js | 44 ++++++++++++++++++++------------------------ semantics.json | 2 +- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/js/questionset.js b/js/questionset.js index 9d3abe0..7f0218d 100644 --- a/js/questionset.js +++ b/js/questionset.js @@ -198,37 +198,34 @@ H5P.QuestionSet = function (options, contentId, contentData) { } /** - * Randomizes elements in an array and updates a map of the order - * @param {array} elements - * @param {array} map - * @return {Object.} elements and indexes + * Randomizes questions in an array and updates an array containing their order + * @param {array} questions + * @param {array} questionOrder + * @return {Object.} questionOrdering */ - var randomizeElements = function (elements, map) { + var randomizeQuestionOrdering = function (questions, questionOrder) { - // Save the original order of the elements in a nested array [[element1,0],[element2,1]... - var elementsAndIndexes = elements.map(function(object, index) { return [object, index] }); + // Save the original order of the questions in a nested array [[question0,0],[question1,1]... + var questionOrdering = questions.map(function(object, index) { return [object, index] }); - elementsAndIndexes = H5P.shuffleArray(elementsAndIndexes); + questionOrdering = H5P.shuffleArray(questionOrdering); - // Retrieve elements and indexes - elements = elementsAndIndexes.map(d => d[0]); - map = elementsAndIndexes.map(d => d[1]); + // Retrieve questions and indexes + questions = questionOrdering.map(d => d[0]); + questionOrder = questionOrdering.map(d => d[1]); return { - elements:elements, - map:map + questions:questions, + questionOrder:questionOrder }; } // 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; + var result = randomizeQuestionOrdering(questionInstances,questionOrder); + questionInstances = result.questions; + questionOrder = result.questionOrder; } // Resize all interactions on resize @@ -445,9 +442,9 @@ H5P.QuestionSet = function (options, contentId, contentData) { */ var randomizeQuestions = function () { - var result = randomizeElements(questionInstances,questionOrder); - questionInstances = result.elements; - questionOrder = result.map; + var result = randomizeQuestionOrdering(questionInstances,questionOrder); + questionInstances = result.questions; + questionOrder = result.questionOrder; // Find all question containers and detach questions from them $('.question-container', $myDom).each(function (){ @@ -460,8 +457,7 @@ 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-container:eq(' + i + ')', $myDom).attr('class', 'question-container'); question.attach($('.question-container:eq(' + i + ')', $myDom)); diff --git a/semantics.json b/semantics.json index 91ef9e0..3a174e5 100644 --- a/semantics.json +++ b/semantics.json @@ -207,7 +207,7 @@ "type": "boolean", "label": "Randomize questions", "description": "Enable to randomize the order of questions on display.", - "default": true + "default": false }, { "name": "endGame",