]> _ Git - fluidbook-toolbox-quiz.git/commitdiff
wip #6363 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Oct 2023 16:35:05 +0000 (18:35 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 3 Oct 2023 16:35:05 +0000 (18:35 +0200)
js/quiz.resize.js
js/quiz.utils.js
style/100-global.sass
views/components/background.blade.php [new file with mode: 0644]
views/index.blade.php

index 625d78246869d89d449d5fb213ccb85300ea2bbe..7c343b700e981ff4bb6436253c3adb289d693e9d 100644 (file)
@@ -37,6 +37,7 @@ QuizResize.prototype = {
 
     resize: function () {
         this.measureSizes();
+        this.updateBackgrounds();
         this.updateViewport();
 
         if (this.isMobile()) {
@@ -114,6 +115,30 @@ QuizResize.prototype = {
         }
     },
 
+    updateBackgrounds: function () {
+        let $this = this;
+        $('[data-bg]').each(function () {
+            var v = $this.isMobile() ? $(this).attr('data-bg-m') : $(this).attr('data-bg-d');
+
+            if ($(this).attr('data-bg') === v) {
+                return;
+            }
+            $this.updateBackground($(this), v);
+        });
+    },
+
+    updateBackground: function (b, v) {
+        let c = '';
+
+        if (v.toLowerCase().indexOf('.json') >= 0) {
+            $(b).html('');
+            this.quiz.animations.load(v, b, undefined, true);
+        } else {
+            $(b).html('<img src="' + v + '" />');
+        }
+        $(b).attr('data-bg', v);
+    },
+
     isMobile: function () {
         return this.ww <= 600 && this.ratio < 0.7;
     },
index 66a32158faf846db1e2f07befeb9294f4f01ab35..805a6a17aba1f852649018c9e9333bf0f4b5bcf2 100644 (file)
@@ -3,6 +3,7 @@ function QuizUtils() {
 }
 
 QuizUtils.prototype = {
+
     isVisible(e) {
         if ($(e).length === 0) {
             return false;
@@ -14,6 +15,7 @@ QuizUtils.prototype = {
 
         return elt.offsetWidth || elt.offsetHeight || elt.getClientRects().length;
     },
+
     isEnabled: function (e) {
         if (!this.isVisible(e)) {
             return false;
index de90351d353077ba7ec7f4ccf8dd6349c91d3786..a22bf75d38cb056c80ab9b64118572e5ec735ed1 100644 (file)
@@ -16,21 +16,16 @@ body
         transition: opacity 200ms
         opacity: 1
 
-    background-color: $background-color
-
-    @if ($background-custom)
-        background-image: url($background-desktop-image)
-        background-repeat: $background-desktop-repeat
-        background-size: $background-desktop-size
-        background-position-x: $background-desktop-position-x
-        background-position-y: $background-desktop-position-y
-
-        .m &
-            background-image: url($background-mobile-image)
-            background-repeat: $background-mobile-repeat
-            background-size: $background-mobile-size
-            background-position-x: $background-mobile-position-x
-            background-position-y: $background-mobile-position-y
+    .bg
+        background-color: $background-color
+
+        @if ($background-custom)
+            object-fit: $background-desktop-size
+            object-position: $background-desktop-position-x $background-desktop-position-y
+
+            .m &
+                object-fit: $background-mobile-size
+                object-position: $background-mobile-position-x $background-mobile-position-y
 
     min-width: 1200px
     max-width: 1200px
@@ -249,3 +244,12 @@ body
     top: 0
     left: 0
     width: 100%
+
+[data-bg]
+    position: absolute
+    display: block
+    top: 0
+    left: 0
+    width: 100%
+    height: 100%
+    pointer-events: none
diff --git a/views/components/background.blade.php b/views/components/background.blade.php
new file mode 100644 (file)
index 0000000..aeb1b21
--- /dev/null
@@ -0,0 +1,9 @@
+@php
+    $d=$data[$name];
+    if(isset($data[$name.'Mobile']) && $data[$name.'Mobile'] && $d!==$data[$name.'Mobile']){
+        $m=$data[$name.'Mobile'];
+    }else{
+        $m=false;
+    }
+@endphp
+<div data-bg="" data-bg-d="{{$d}}" @if($m)data-bg-m="{{$m}}"@endif></div>
index 5111c3c7b9f5c79a2f27a5d56a808e151cf59644..4f085e302d820dda123d0d087164f7d0d526b274 100644 (file)
@@ -17,6 +17,7 @@
 @endphp
 <div class="container">
     <div id="quiz">
+        @include('components.background',['data'=>$data,'name'=>'mainBackground'])
         @include('screens.intro', ['data'=> $data])
         @foreach($data->questions as $key => $question)
             @include('screens.question_'.$question['type'], ['theme' => $data->theme,'data'=> $data, 'question' => $question, 'max' => $totalQuestion, 'position' => $key, 'alphabet' => $alphabet])