]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6182 @2:00 question match
authorsoufiane <soufiane@cubedesigners.com>
Mon, 25 Sep 2023 14:04:53 +0000 (16:04 +0200)
committersoufiane <soufiane@cubedesigners.com>
Mon, 25 Sep 2023 14:04:53 +0000 (16:04 +0200)
js/quiz.match.js
js/quiz.screens.js
style/107-question-match.sass
views/screens/question_match.blade.php

index 5509bcaa608c2398f8eec63dac8f4f2fb58e75aa..93b86799efcbc68182f7d0fe8f947fdbee2e5256 100644 (file)
@@ -1,20 +1,17 @@
 import gsap from "gsap";
 import Swiper from 'swiper';
-import { Navigation, Pagination } from 'swiper/modules';
+import { Navigation, Pagination, Manipulation } from 'swiper/modules';
 import 'swiper/css/navigation';
 import 'swiper/css/pagination';
 
 function QuizMatch(quiz) {
     this.quiz = quiz;
-    this.start()
+    this.init()
 }
 
 QuizMatch.prototype = {
-    start: function() {
+    init: function() {
         const $this = this
-        this.rules = [{top: "10", opacity: ".48"},{top: "39", opacity: ".24"}]
-        this.quiz.screens.currentQuestionAnswers = [];
-
         $(document).on("click", ".move-slide", function () {
             let move = $(this).attr("aria-keyshortcuts")
 
@@ -28,6 +25,17 @@ QuizMatch.prototype = {
         $(document).on("click", ".confirmMatch", function() {
             $this.confirmTheMatch()
         })
+    },
+
+    start: function() {
+        const $this = this
+        this.swiperBottom = false
+        this.rules = [{top: "10", opacity: ".48"},{top: "39", opacity: ".24"}]
+        this.quiz.screens.currentQuestionAnswers = [];
+        this.swiperBottomEl = this.quiz.screens.getActiveScreen().find(".bottom-slider")
+        this.sliderBottomHtml = this.swiperBottomEl.html()
+
+        console.log("screen",)
 
         this.swiperTop = new Swiper('.swiper-container.top-slider', {
             modules: [Navigation, Pagination],
@@ -43,13 +51,20 @@ QuizMatch.prototype = {
             },
         })
 
+        this.initSwiperBottom()
+
+    },
+
+    initSwiperBottom: function() {
+        const $this = this
+        if(this.swiperBottom)
+            this.swiperBottom.destroy()
+
         this.swiperBottom = new Swiper('.swiper-container.bottom-slider', {
-            modules: [Navigation, Pagination],
+            modules: [Navigation, Pagination, Manipulation],
             slidesPerView: "auto",
             //loop: true,
-            watchSlidesProgress: true,
             centeredSlides: true,
-            freeMode: true,
             spaceBetween: 20,
             pagination: {
                 el: '.swiper-pagination-bottom',
@@ -64,7 +79,6 @@ QuizMatch.prototype = {
                 }
             }
         })
-
     },
 
     setRotation: function(swiper) {
@@ -97,8 +111,10 @@ QuizMatch.prototype = {
 
     confirmTheMatch: function() {
         let lastIndex = this.swiperTop.slides.length - 1
-        let answer = this.swiperBottom.activeIndex
-        this.quiz.screens.currentQuestionAnswers.push(answer)
+        let index = this.swiperBottom.activeIndex
+        this.quiz.screens.currentQuestionAnswers.push(index)
+        this.swiperBottom.removeSlide(index)
+        this.swiperBottom.update()
 
         if(this.swiperTop.activeIndex === lastIndex) {
             this.switchMatchValidateButton()
@@ -113,6 +129,14 @@ QuizMatch.prototype = {
             text = this.quiz.l10n.__('Validate answer');
 
         btn.removeClass("confirmMatch").addClass("action validate").find('.text').text(text)
+    },
+
+    reset: function () {
+        this.quiz.screens.currentQuestionAnswers = []
+        this.swiperTop.slideTo(0)
+        this.swiperBottomEl.html(this.sliderBottomHtml)
+        this.initSwiperBottom()
+        this.quiz.screens.toggleScreen(1, 'all');
     }
 }
 
index b3a7374da2f50f6302c9edc52acb2874158cf102..90506525dc345283b7bc8995dc234c7c24fabc30 100644 (file)
@@ -133,6 +133,8 @@ QuizScreens.prototype = {
 
             if ($this.getActiveScreenType() === 'draganddrop') {
                 $this.quiz.draganddrop.start()
+            } else if($this.getActiveScreenType() === 'match') {
+                $this.quiz.match.start()
             }
 
             //
@@ -204,6 +206,8 @@ QuizScreens.prototype = {
             this.getCurrentForm().find("input").prop("checked", false)
         } else if (type === 'draganddrop') {
             this.quiz.draganddrop.reset();
+        } else if(type === 'match') {
+            this.quiz.match.reset();
         }
     },
 
index d1415e35e6947793a0b2e455209e7b4b6117d1fe..be84b8ab1098ebe5cd6577a9fb96cd834f390c1a 100644 (file)
@@ -9,6 +9,7 @@
     .top-slider
         max-width: 596px
         overflow: hidden
+        pointer-events: none
         .swiper-slide
             min-height: 137px
             padding: 38px 24px 18px
@@ -23,6 +24,7 @@
             +radius(16px)
             padding: 15px
             transition: all .3s
+            border: 2px solid transparent
             &-active
                 background-color: $neutral-color
                 border: 2px solid $texts-color
@@ -37,7 +39,6 @@
                 +opacity(.24,background-color,$neutral-color)
 
 
-
     .swiper-pagination-top
         text-align: center
         position: relative
index 09455aa5d8c249c94344afd7e47665d52a794e5a..8e7a18062a09572d799a84b569f7e25a4e2e422f 100644 (file)
@@ -2,6 +2,7 @@
     $propositions = array_map(function($n) { return $n['proposition']; }, $question['answers']);
     $additional_prop = array_map(function($n) { return $n['content']; }, $question['additional_proposition']);
     $propositions = [...$additional_prop,...$propositions];
+    shuffle($propositions);
 @endphp
 
 <div class="container-screen none question-match" data-type="match" data-screen="q-{{$position}}">