]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wait #6295 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Sep 2023 12:16:41 +0000 (14:16 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 20 Sep 2023 12:16:41 +0000 (14:16 +0200)
js/quiz.draganddrop.js
js/quiz.score.js
style/106-question-draganddrop.sass
views/screens/question_draganddrop_area.blade.php

index b9510251c5077e6da6629f3f4205d2ff4fb06449..2e5a2bf2b8e231a2220c891b1814ba865c95a3a7 100644 (file)
@@ -19,9 +19,9 @@ QuizDragAndDrop.prototype = {
             let move = $(this).attr("aria-keyshortcuts"), zone = false;
 
             if (move === "ARROWLEFT") {
-                zone = $this.zone1
+                zone = 'zone-1';
             } else {
-                zone = $this.zone2
+                zone = 'zone-2';
             }
 
             $this.sendCurrentAnswerToArea(zone);
@@ -38,6 +38,7 @@ QuizDragAndDrop.prototype = {
         this.zone2 = this.activeScreen.find(".zone-2 .zone-content")
         this.htmlZone1 = this.zone1.html()
         this.htmlZone2 = this.zone2.html()
+        this.quiz.screens.currentQuestionAnswers = [];
         this.offsetLeftItemDragged = 0
         this.offsetRightItemDragged = 0
 
@@ -48,6 +49,8 @@ QuizDragAndDrop.prototype = {
         if (this.animating === true) {
             return;
         }
+        this.quiz.screens.currentQuestionAnswers.push(area === 'zone-1' ? 1 : 2);
+
         this.animating = true;
         const $this = this;
         const current = this.activeScreen.find(".list-item:first-child");
@@ -206,10 +209,8 @@ QuizDragAndDrop.prototype = {
         let id = "answer-" + target.data("id");
 
         if (!this.quiz.resize.isMobile()) {
-            $(zone).find(".slot:not(.active)").eq(0).addClass("active").append("<h4>" + title + "</h4><p>" + text + "</p>").attr('data-order', target.data("id"))
+            this.getAreaElement(zone).find(".slot:not(.active)").eq(0).addClass("active").append("<h4>" + title + "</h4><p>" + text + "</p>").attr('data-order', target.data("id"))
         }
-
-        $this.saveAnswer(zone, id)
         target.remove()
     },
 
@@ -229,20 +230,28 @@ QuizDragAndDrop.prototype = {
         });
 
         if ($(".zone-content.active").length > 0) {
-            zone = "." + $(".zone-content.active").parent().data("zone")
+            zone = $(".zone-content.active").parent().data("zone")
         }
 
         return zone
     },
 
     getSlotInformations: function (zone) {
-        let x = ($(zone).find(".slot:not(.active)").offset().left - this.list.offset().left),
-            y = ($(zone).find(".slot:not(.active)").offset().top - this.list.offset().top),
-            w = $(zone).find(".slot").innerWidth(), h = $(zone).find(".slot").innerHeight(), el = $(zone).find(".slot")
+
+        let a = this.getAreaElement(zone);
+        let freeSlot = $(a).find('.slot:not(.active)').eq(0);
+        let freeSlotOffset = $(freeSlot).offset();
+
+        let x = (freeSlotOffset.left - this.list.offset().left), y = (freeSlotOffset.top - this.list.offset().top),
+            w = $(a).find(".slot").innerWidth(), h = $(a).find(".slot").innerHeight(), el = $(a).find(".slot")
 
         return {"x": x, "y": y, "w": w, "h": h, "el": el}
     },
 
+    getAreaElement: function (area) {
+        return this.quiz.screens.getActiveScreen().find('[data-zone="' + area + '"]')
+    },
+
     initQuestion: function () {
         //
         const htmlList = this.quiz.draganddrop.listHtml
@@ -259,11 +268,6 @@ QuizDragAndDrop.prototype = {
         let tl = gsap.timeline()
         this.quiz.animations.animateDragAndDropCarrousel(tl)
     },
-
-    saveAnswer: function (zone, id) {
-        $(zone).find("input[id=" + id + "]").prop("checked", true)
-        this.quiz.screens.updateUserAnswers();
-    }
 }
 
 export default QuizDragAndDrop;
index b205d1cac48e14ede9bc8e04bab9573c68e12fba..64f912f54a8758d8ab3060c19e00bf617af626b8 100644 (file)
@@ -85,6 +85,16 @@ QuizScore.prototype = {
                 }
                 ok = this_score >= min_score ? 'ok' : 'nok';
 
+                log.answer = a;
+            } else if (question.type === 'draganddrop') {
+                min_score = this.getMinScore(question);
+                this_score = 0;
+                for (let answerIndex in question.answers) {
+                    const answer = question.answers[answerIndex];
+                    this_score += ((answer.drop_area === userAnswers[answerIndex]) ? 1 : 0);
+                }
+                ok = this_score >= min_score ? 'ok' : 'nok';
+
                 log.answer = a;
             } else {
                 log.answer = $(this).find('input,textarea,select').val();
@@ -121,7 +131,7 @@ QuizScore.prototype = {
             min_score = 0;
             for (const answerIndex in question.answers) {
                 const answer = question.answers[answerIndex];
-                if (answer.correct === 1) {
+                if (answer.correct === 1 || question.type === 'draganddrop' || question.type === 'match') {
                     min_score += answer.score;
                 }
             }
index 793390c8e499ee99810fc2dbd6bb32aee048cca6..5dff60982976f03239a012db9333a581548012f7 100644 (file)
                 left: 0
 
             .zone-content
-                max-width: 95%
+                width: 95%
                 height: auto
                 left: 50%
                 transform: translateX(-50%)
 
                 p
                     font-size: 14px
+                    white-space: pre-line
                     +opacity(.8, color, $texts-color)
 
             .slot
index f76cd72acf375e443c856a4900ef49cc6b4d8f92..bd3104e7161610bc9db9aff83c2d321883e1e70e 100644 (file)
             <p>{{ $question['area_'.$area]['text'] }}</p>
         </div>
         <div class="card-holder">
-            <form>
-                @foreach($question['answers'] as $key => $answer)
-                    <div class="slot">
-                        <input type="checkbox"
-                               id="answer-{{$key}}" class="none" value="{{$key}}">
-                        <h4></h4>
-                        <p></p>
-                    </div>
-                @endforeach
-            </form>
+            @foreach($question['answers'] as $key => $answer)
+                <div class="slot">
+                    <h4></h4>
+                    <p></p>
+                </div>
+            @endforeach
         </div>
     </div>
 </div>