From 65a770cb35d3f24a0087d42b20478aaefcc475aa Mon Sep 17 00:00:00 2001 From: otacke Date: Sun, 19 Feb 2017 20:32:10 +0100 Subject: [PATCH 1/3] add randomizing answers on retry --- js/multichoice.js | 48 ++++++++++++++++++++++++++++++++++++----------- language/ar.json | 4 ++++ language/de.json | 4 ++++ language/fr.json | 4 ++++ language/it.json | 4 ++++ language/nb.json | 4 ++++ language/nn.json | 4 ++++ semantics.json | 8 ++++++++ 8 files changed, 69 insertions(+), 11 deletions(-) diff --git a/js/multichoice.js b/js/multichoice.js index 4d2a109a..5bb97460 100644 --- a/js/multichoice.js +++ b/js/multichoice.js @@ -233,8 +233,6 @@ H5P.MultiChoice = function (options, contentId, contentData) { // Create tips: var $answers = $('.h5p-answer', $myDom).each(function (i) { - var $tipContainer = $(this); - var tip = params.answers[i].tipsAndFeedback.tip; if (tip === undefined) { return; // No tip @@ -264,7 +262,9 @@ H5P.MultiChoice = function (options, contentId, contentData) { 'class': 'multichoice-tip', appendTo: $wrap }).click(function () { + $tipContainer = $multichoiceTip.parents('.h5p-answer'); var openFeedback = !$tipContainer.children('.h5p-feedback-dialog').is($feedbackDialog); + removeFeedbackDialog(); // Do not open feedback if it was open @@ -597,7 +597,7 @@ H5P.MultiChoice = function (options, contentId, contentData) { calcScore(); self.showAllSolutions(); } - + }, false); // Check solution button @@ -630,6 +630,22 @@ H5P.MultiChoice = function (options, contentId, contentData) { enableInput(); $myDom.find('.h5p-feedback-available').remove(); self.answered = false; + if (params.behaviour.randomizeOnRetry) { + // reshuffle answers + oldIdMap = idMap; + idMap = getShuffleMap(); + var answersDisplayed = $myDom.find('.h5p-answer'); + // remember tips + var tip = []; + for (i = 0; i < answersDisplayed.length; i++) { + tip[i] = $(answersDisplayed[i]).find('.h5p-multichoice-tipwrap'); + } + // move tips and answers on display + for (i = 0; i < answersDisplayed.length; i++) { + $(answersDisplayed[i]).find('.h5p-alternative-inner').html(params.answers[i].text); + $(tip[i]).detach().appendTo($(answersDisplayed[idMap.indexOf(oldIdMap[i])]).find('.h5p-alternative-container')); + } + } }, false, {}, { confirmationDialog: { enable: params.behaviour.confirmRetryDialog, @@ -908,6 +924,23 @@ H5P.MultiChoice = function (options, contentId, contentData) { xAPIEvent.data.statement.result.response = response; }; + /** + * Create a map pointing from original answers to shuffled answers + * + * @return {number[]} map pointing from original answers to shuffled answers + */ + var getShuffleMap = function() { + var origOrder = $.extend([], params.answers); + params.answers = H5P.shuffleArray(params.answers); + + // Create a map from the new id to the old one + var idMap = []; + for (i = 0; i < params.answers.length; i++) { + idMap[i] = params.answers[i].originalOrder; + } + return idMap; + } + // Initialization code // Randomize order, if requested var idMap; @@ -916,14 +949,7 @@ H5P.MultiChoice = function (options, contentId, contentData) { params.answers[i].originalOrder = i; } if (params.behaviour.randomAnswers) { - var origOrder = $.extend([], params.answers); - params.answers = H5P.shuffleArray(params.answers); - - // Create a map from the new id to the old one - idMap = []; - for (i = 0; i < params.answers.length; i++) { - idMap[i] = params.answers[i].originalOrder; - } + idMap = getShuffleMap(); } // Start with an empty set of user answers. diff --git a/language/ar.json b/language/ar.json index 05134523..0cfcdd47 100644 --- a/language/ar.json +++ b/language/ar.json @@ -148,6 +148,10 @@ "label": "الإجابات بطريقة عشوائية", "description": "تمكين العرض بطريقة عشوائية وترتيب الأسئلة على الشاشة" }, + { + "label": "Randomize on retry", + "description": "Enable to reorder the answers on retry." + }, { "label": "تطلب إدخال المستخدم اجابته قبل أن يتم عرضه الحل" }, diff --git a/language/de.json b/language/de.json index 4add1970..bf2bf5aa 100644 --- a/language/de.json +++ b/language/de.json @@ -153,6 +153,10 @@ "label": "Antworten zufällig anordnen", "description": "Aktivieren, um die Fragen auf dem Bildschirm zufällig anzuordnen." }, + { + "label": "Antworten beim Wiederholen zufällig anordnen", + "description": "Aktivieren, um die Fragen beim Wiederholen erneut zufällig anzuordnen." + }, { "label": "Benutzereingabe erforderlich machen, bevor die Antwort angesehen werden kann" }, diff --git a/language/fr.json b/language/fr.json index ee78840e..499c8386 100644 --- a/language/fr.json +++ b/language/fr.json @@ -153,6 +153,10 @@ "label": "Réponses aléatoires", "description": "Les réponses possibles seront affichées dans l'ordre aléatoire." }, + { + "label": "Randomize on retry", + "description": "Enable to reorder the answers on retry." + }, { "label": "Une réponse est obligatoire pour voir la solution" }, diff --git a/language/it.json b/language/it.json index b80dc50f..dd5c0fe9 100644 --- a/language/it.json +++ b/language/it.json @@ -148,6 +148,10 @@ "label": "Risposte in ordine casuale", "description": "Abilita per rendere casuale l'ordine delle domande visualizzate." }, + { + "label": "Randomize on retry", + "description": "Enable to reorder the answers on retry." + }, { "label": "Richiedere l'immissione dei dati all'utente prima che la soluzione sia visualizzata" }, diff --git a/language/nb.json b/language/nb.json index fb3f4279..e8baef58 100644 --- a/language/nb.json +++ b/language/nb.json @@ -153,6 +153,10 @@ "label": "Tilfeldige svaralternativ", "description": "Slå på for å vise alternativene i tilfeldig rekkefølge." }, + { + "label": "Randomize on retry", + "description": "Enable to reorder the answers on retry." + }, { "label": "Krev svar fra brukeren før fasit gis." }, diff --git a/language/nn.json b/language/nn.json index 8c77fa7f..cb42d8d8 100644 --- a/language/nn.json +++ b/language/nn.json @@ -153,6 +153,10 @@ "label": "Tilfeldige svaralternativ", "description": "Slå på for å vise de mulige svara i tilfeldig rekkefølge." }, + { + "label": "Randomize on retry", + "description": "Enable to reorder the answers on retry." + }, { "label": "Krev svar fra brukeren før fasit gis." }, diff --git a/semantics.json b/semantics.json index 0a9893e3..05e887cb 100644 --- a/semantics.json +++ b/semantics.json @@ -341,6 +341,14 @@ "description": "Enable to randomize the order of questions on display.", "default": true }, + { + "name": "randomizeOnRetry", + "type": "boolean", + "label": "Randomize on retry", + "importance": "low", + "description": "Enable to reorder the answers on retry.", + "default": false + }, { "label": "Require answer before the solution can be viewed", "importance": "low", From 2994b9620095c2aa0de6eaddbf8f6b593ccade57 Mon Sep 17 00:00:00 2001 From: Oliver Tacke Date: Tue, 18 Apr 2017 21:19:53 +0200 Subject: [PATCH 2/3] Update multichoice.js --- js/multichoice.js | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/js/multichoice.js b/js/multichoice.js index 64a07050..499a5627 100644 --- a/js/multichoice.js +++ b/js/multichoice.js @@ -646,13 +646,10 @@ H5P.MultiChoice = function (options, contentId, contentData) { oldIdMap = idMap; idMap = getShuffleMap(); var answersDisplayed = $myDom.find('.h5p-answer'); - // remember tips + // remember tips and move them and answers on display var tip = []; for (i = 0; i < answersDisplayed.length; i++) { tip[i] = $(answersDisplayed[i]).find('.h5p-multichoice-tipwrap'); - } - // move tips and answers on display - for (i = 0; i < answersDisplayed.length; i++) { $(answersDisplayed[i]).find('.h5p-alternative-inner').html(params.answers[i].text); $(tip[i]).detach().appendTo($(answersDisplayed[idMap.indexOf(oldIdMap[i])]).find('.h5p-alternative-container')); } From 0ea7309307681eacb703821f3bc3ceb1258b57ef Mon Sep 17 00:00:00 2001 From: otacke Date: Thu, 20 Apr 2017 21:20:38 +0200 Subject: [PATCH 3/3] remove unnecessary option --- js/multichoice.js | 32 ++++++++++++++++++-------------- language/ar.json | 4 ---- language/de.json | 4 ---- language/fr.json | 4 ---- language/it.json | 4 ---- language/nb.json | 4 ---- language/nn.json | 4 ---- semantics.json | 8 -------- 8 files changed, 18 insertions(+), 46 deletions(-) diff --git a/js/multichoice.js b/js/multichoice.js index 499a5627..3dda4801 100644 --- a/js/multichoice.js +++ b/js/multichoice.js @@ -233,6 +233,7 @@ H5P.MultiChoice = function (options, contentId, contentData) { // Create tips: var $answers = $('.h5p-answer', $myDom).each(function (i) { + var tip = params.answers[i].tipsAndFeedback.tip; if (tip === undefined) { return; // No tip @@ -273,9 +274,8 @@ H5P.MultiChoice = function (options, contentId, contentData) { $multichoiceTip.append(tipIconHtml); $multichoiceTip.click(function () { - $tipContainer = $multichoiceTip.parents('.h5p-answer'); + var $tipContainer = $multichoiceTip.parents('.h5p-answer'); var openFeedback = !$tipContainer.children('.h5p-feedback-dialog').is($feedbackDialog); - removeFeedbackDialog(); // Do not open feedback if it was open @@ -641,19 +641,23 @@ H5P.MultiChoice = function (options, contentId, contentData) { enableInput(); $myDom.find('.h5p-feedback-available').remove(); self.answered = false; - if (params.behaviour.randomizeOnRetry) { + if (params.behaviour.randomAnswers) { // reshuffle answers - oldIdMap = idMap; - idMap = getShuffleMap(); - var answersDisplayed = $myDom.find('.h5p-answer'); - // remember tips and move them and answers on display - var tip = []; - for (i = 0; i < answersDisplayed.length; i++) { - tip[i] = $(answersDisplayed[i]).find('.h5p-multichoice-tipwrap'); - $(answersDisplayed[i]).find('.h5p-alternative-inner').html(params.answers[i].text); - $(tip[i]).detach().appendTo($(answersDisplayed[idMap.indexOf(oldIdMap[i])]).find('.h5p-alternative-container')); - } - } + oldIdMap = idMap; + idMap = getShuffleMap(); + var answersDisplayed = $myDom.find('.h5p-answer'); + // remember tips + var tip = []; + for (i = 0; i < answersDisplayed.length; i++) { + tip[i] = $(answersDisplayed[i]).find('.h5p-multichoice-tipwrap'); + } + // Those two loops cannot be merged or you'll screw up your tips + for (i = 0; i < answersDisplayed.length; i++) { + // move tips and answers on display + $(answersDisplayed[i]).find('.h5p-alternative-inner').html(params.answers[i].text); + $(tip[i]).detach().appendTo($(answersDisplayed[idMap.indexOf(oldIdMap[i])]).find('.h5p-alternative-container')); + } + } }, false, {}, { confirmationDialog: { enable: params.behaviour.confirmRetryDialog, diff --git a/language/ar.json b/language/ar.json index 0cfcdd47..05134523 100644 --- a/language/ar.json +++ b/language/ar.json @@ -148,10 +148,6 @@ "label": "الإجابات بطريقة عشوائية", "description": "تمكين العرض بطريقة عشوائية وترتيب الأسئلة على الشاشة" }, - { - "label": "Randomize on retry", - "description": "Enable to reorder the answers on retry." - }, { "label": "تطلب إدخال المستخدم اجابته قبل أن يتم عرضه الحل" }, diff --git a/language/de.json b/language/de.json index bf2bf5aa..4add1970 100644 --- a/language/de.json +++ b/language/de.json @@ -153,10 +153,6 @@ "label": "Antworten zufällig anordnen", "description": "Aktivieren, um die Fragen auf dem Bildschirm zufällig anzuordnen." }, - { - "label": "Antworten beim Wiederholen zufällig anordnen", - "description": "Aktivieren, um die Fragen beim Wiederholen erneut zufällig anzuordnen." - }, { "label": "Benutzereingabe erforderlich machen, bevor die Antwort angesehen werden kann" }, diff --git a/language/fr.json b/language/fr.json index 499c8386..ee78840e 100644 --- a/language/fr.json +++ b/language/fr.json @@ -153,10 +153,6 @@ "label": "Réponses aléatoires", "description": "Les réponses possibles seront affichées dans l'ordre aléatoire." }, - { - "label": "Randomize on retry", - "description": "Enable to reorder the answers on retry." - }, { "label": "Une réponse est obligatoire pour voir la solution" }, diff --git a/language/it.json b/language/it.json index dd5c0fe9..b80dc50f 100644 --- a/language/it.json +++ b/language/it.json @@ -148,10 +148,6 @@ "label": "Risposte in ordine casuale", "description": "Abilita per rendere casuale l'ordine delle domande visualizzate." }, - { - "label": "Randomize on retry", - "description": "Enable to reorder the answers on retry." - }, { "label": "Richiedere l'immissione dei dati all'utente prima che la soluzione sia visualizzata" }, diff --git a/language/nb.json b/language/nb.json index e8baef58..fb3f4279 100644 --- a/language/nb.json +++ b/language/nb.json @@ -153,10 +153,6 @@ "label": "Tilfeldige svaralternativ", "description": "Slå på for å vise alternativene i tilfeldig rekkefølge." }, - { - "label": "Randomize on retry", - "description": "Enable to reorder the answers on retry." - }, { "label": "Krev svar fra brukeren før fasit gis." }, diff --git a/language/nn.json b/language/nn.json index cb42d8d8..8c77fa7f 100644 --- a/language/nn.json +++ b/language/nn.json @@ -153,10 +153,6 @@ "label": "Tilfeldige svaralternativ", "description": "Slå på for å vise de mulige svara i tilfeldig rekkefølge." }, - { - "label": "Randomize on retry", - "description": "Enable to reorder the answers on retry." - }, { "label": "Krev svar fra brukeren før fasit gis." }, diff --git a/semantics.json b/semantics.json index b8c72a2b..c26b0566 100644 --- a/semantics.json +++ b/semantics.json @@ -341,14 +341,6 @@ "description": "Enable to randomize the order of questions on display.", "default": true }, - { - "name": "randomizeOnRetry", - "type": "boolean", - "label": "Randomize on retry", - "importance": "low", - "description": "Enable to reorder the answers on retry.", - "default": false - }, { "label": "Require answer before the solution can be viewed", "importance": "low",