]> _ Git - fluidbook-toolbox.git/commitdiff
wait #5375 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 8 Aug 2022 14:06:20 +0000 (16:06 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 8 Aug 2022 14:06:20 +0000 (16:06 +0200)
resources/quiz/js/app.js
resources/scorm/scorm.js

index e52db5cf1882be7e9b6f3b3b5c68120a09d46246..8989ee4a4bc4fdcebefc9ae088bf854176cb17b7 100644 (file)
@@ -16,23 +16,8 @@ require('../../scorm/scorm');
             if (SCORM_INITED) {
                 return;
             }
-            var scormok = initScorm();
-            var defaultState = {q: 1};
-            var state;
-            if (!scormok) {
-                state = defaultState;
-            } else {
-                var currentLocation = getScormValue('location');
-                try {
-                    state = JSON.parse(currentLocation);
-                } catch (e) {
-                    state = defaultState;
-                }
-                if (state['q'] === undefined || state['q'] === null) {
-                    state = defaultState;
-                }
-            }
-            init(state);
+            initScorm();
+            init(getScormLocation({q: 1}));
         }
 
         $(window).on('resize', resize);
@@ -223,6 +208,7 @@ require('../../scorm/scorm');
         }
 
         function init(state) {
+            console.log(state);
             resize();
             $(document).on('click', ".answer", function () {
                 answer($(this));
index 53e42c1c3767bd006d0279dd9f5855aa56f0b58d..f1092484ac3e5c9744c48a25d520665917ac9fc0 100644 (file)
@@ -132,30 +132,35 @@ window.getScormValue = function (elementName) {
     return SCORM.get(cmi);
 };
 
-window.getScormLocation = function () {
+window.getScormLocation = function (defaultLocation) {
+    if (defaultLocation === undefined) {
+        defaultLocation = {};
+    }
     var res = {};
     if (!SCORM_OK) {
-        return {};
+        return defaultLocation;
     }
     var currentLocation = getScormValue('location');
 
     if (currentLocation.indexOf('[') === -1 && currentLocation.indexOf('{') === -1) {
         // Maybe a zipped string
-        currentLocation = pako.inflate(base64ToBytesArr(currentLocation), {to: 'string'});
+        currentLocation = pako.inflate(base64ToBytesArr(currentLocation), {to: 'string'})
+        console.log(currentLocation);
     }
     if (currentLocation === undefined || currentLocation === null || currentLocation === 'null' || currentLocation === '') {
-        res = {};
+        res = defaultLocation;
     } else {
         try {
             res = JSON.parse(currentLocation);
+            console.log(res);
         } catch (e) {
             console.warn('An error occurred while decoding location. Reseting the value');
-            res = {};
+            res = defaultLocation;
         }
     }
 
-    if (window.savedState === undefined || window.savedState === null || window.savedState === 'null') {
-        res = {};
+    if (res === undefined || res === null || res === 'null') {
+        res = defaultLocation;
     }
     return res;
 }