]> _ Git - fluidbook-html5.git/commitdiff
done #3691 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 9 Jun 2020 06:26:43 +0000 (08:26 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 9 Jun 2020 06:26:43 +0000 (08:26 +0200)
js/libs/fluidbook/fluidbook.scorm.js
js/libs/fluidbook/fluidbook.splash.js
js/libs/scorm/apiwrapper.js
js/libs/scorm/scorm.js

index 520758072935466d1cbd9a5f4bd7666ccf42e989..5e3329bc7b4b1b4d8dd6ee94c95781a5bdb70c37 100644 (file)
@@ -9,6 +9,12 @@ FluidbookScorm.prototype = {
     init: function () {
         var $this = this;
 
+        var ok = false;
+
+        if (this.fluidbook.settings.scorm_enable && window.initScorm !== undefined) {
+            ok = initScorm();
+        }
+
         if (this.fluidbook.settings.scorm_variables.linkstocomplete) {
             this.linksToComplete = this.fluidbook.settings.scorm_variables.linkstocomplete.split(',');
         }
@@ -26,13 +32,10 @@ FluidbookScorm.prototype = {
             $this.hideScormLinks();
         });
 
-        if (this.fluidbook.settings.scorm_enable && window.initScorm !== undefined) {
-            initScorm();
-        }
 
         // Mark complete when the user reaches the last page
         $(this.fluidbook).on('fluidbook.page.change.end', function () {
-            if ($this.fluidbook.currentPage == $this.fluidbook.settings.pages && $this.fluidbook.settings.scorm_complete_on_last_page) {
+            if ($this.fluidbook.settings.scorm_complete_on_last_page && $this.fluidbook.currentPage === $this.fluidbook.settings.pages) {
                 scormMarkAsComplete();
             }
         });
@@ -54,7 +57,7 @@ FluidbookScorm.prototype = {
     },
 
     linksCompleted: function () {
-        return (this.linksToComplete.length == 0);
+        return (this.linksToComplete.length === 0);
     },
 
     isActive: function () {
@@ -66,7 +69,7 @@ FluidbookScorm.prototype = {
             return true;
         }
 
-        return pipwerks.SCORM.API.isFound;
+        return SCORM_OK;
     },
 
     openLinkIfCompleteOrDisplayImage: function (openLink, openImage) {
index 722de533adbdbef7e1c88e700f3b8cae80ff3104..7d97f4bd577362b91455d357fc1be56ab06ff866 100644 (file)
@@ -42,7 +42,7 @@ FluidbookSplash.prototype = {
                 this.fluidbook.pagetransitions.flip3d.performancesTest(function () {
                     $this.fluidbook.networkControl.resume();
                     var timeout = $this.hideSplashTimeout;
-                    if (window.SCORM !== undefined && window.SCORM === true) {
+                    if (window.SCORM_OK !== undefined && window.SCORM_OK === true) {
                         timeout += 5;
                     }
                     setTimeout(function () {
index ff91eb2f7a620563cb4dd90be15ef70b0c11fe76..b7f34e288d8c0f3f3d7cae916cdfcc008d499f30 100644 (file)
@@ -75,7 +75,7 @@ pipwerks.SCORM.isAvailable = function () {
 pipwerks.SCORM.API.find = function (win) {\r
     var API = null,\r
         findAttempts = 0,\r
-        findAttemptLimit = 500,\r
+        findAttemptLimit = 12,\r
         traceMsgPrefix = "SCORM.API.find",\r
         trace = pipwerks.UTILS.trace,\r
         scorm = pipwerks.SCORM;\r
index 14c11dc0cd676933de97f9697d05de9e3b592893..f559492c686237a8db7c35f0f6bb423b4aceaaa8 100644 (file)
@@ -11,6 +11,7 @@ SCORM_SUCCESS_SCORE = 0;
 SCORM_EVENTS_INITED = false;
 SCORM_INTERACTIONS_INITED = false;
 SCORM_LOCATION_INITED = false;
+SCORM_OK = false;
 
 var _CMI12 = {
     'location': 'cmi.core.lesson_location',
@@ -35,17 +36,24 @@ function initScorm() {
     console.log('init scorm');
     SCORM_INITED = true;
     try {
-        pipwerks.SCORM.init();
+        if (pipwerks.SCORM.init()) {
+            SCORM_OK = true;
+        }
     } catch (e) {
 
     }
 
-    $(document).on('fluidbook.ready', function () {
-        scormExit();
-        startScormTimer();
-        initScormEvents();
-        initScormInteractions();
-    });
+    if (SCORM_OK) {
+        $(document).on('fluidbook.ready', function () {
+            scormExit();
+            startScormTimer();
+            initScormEvents();
+            initScormInteractions();
+        });
+    }else{
+        console.log('SCORM nok');
+    }
+    return SCORM_OK;
 }
 
 function _cmi(key) {
@@ -65,7 +73,7 @@ function _cmi(key) {
 }
 
 function initScormEvents() {
-    if (SCORM_EVENTS_INITED) {
+    if (!SCORM_OK || SCORM_EVENTS_INITED) {
         return;
     }
     SCORM_EVENTS_INITED = true;
@@ -123,7 +131,7 @@ function initScormEvents() {
     });
 
 
-    // Commit data once a minute
+    // Commit data every 5 seconds
     setInterval(function () {
         fluidbook.networkControl.executeWhenNetwork(function (cb) {
             pipwerks.SCORM.save();
@@ -135,6 +143,9 @@ function initScormEvents() {
 }
 
 function scormSaveCurrentPosition(page, maxPage) {
+    if (!SCORM_OK) {
+        return;
+    }
     if (page === undefined) {
         page = fluidbook.currentPage;
     }
@@ -145,12 +156,18 @@ function scormSaveCurrentPosition(page, maxPage) {
 }
 
 function finishScorm() {
+    if (!SCORM_OK) {
+        return;
+    }
     setSessionTime();
     pipwerks.SCORM.save();
     pipwerks.SCORM.quit();
 }
 
 function scormMarkAsComplete() {
+    if (!SCORM_OK) {
+        return;
+    }
     scormExit();
     setScormValue('status', "completed");
     if (!fluidbook.scorm.manageScore) {
@@ -159,6 +176,9 @@ function scormMarkAsComplete() {
 }
 
 function scormExit() {
+    if (!SCORM_OK) {
+        return;
+    }
     var v = 'suspend';
     if (fluidbook.settings.scorm_force_attempts) {
         if (pipwerks.SCORM.version === '1.2') {
@@ -176,8 +196,11 @@ function startScormTimer() {
 }
 
 function scormComplete() {
-    scormMarkAsComplete();
-    finishScorm();
+    if (SCORM_OK) {
+        scormMarkAsComplete();
+        finishScorm();
+        return;
+    }
     setTimeout(function () {
         parent.close();
         top.close();
@@ -186,6 +209,9 @@ function scormComplete() {
 }
 
 function getScormValue(elementName) {
+    if (!SCORM_OK) {
+        return null;
+    }
     var cmi = _cmi(elementName);
     if (cmi == '') {
         return null;
@@ -195,6 +221,9 @@ function getScormValue(elementName) {
 }
 
 function setScormValue(elementName, value) {
+    if (!SCORM_OK) {
+        return;
+    }
     var cmi = _cmi(elementName);
     if (cmi == '') {
         return false;
@@ -204,6 +233,9 @@ function setScormValue(elementName, value) {
 }
 
 function initScormInteractions() {
+    if (!SCORM_OK) {
+        return;
+    }
     if (SCORM_INTERACTIONS_INITED) {
         return;
     }
@@ -236,7 +268,9 @@ function initScormInteractions() {
 }
 
 function defineScormInteraction(number, id, type, question, correct_response, weighting) {
-
+    if (!SCORM_OK) {
+        return;
+    }
     if (weighting === undefined) {
         weighting = 1;
     }
@@ -273,6 +307,9 @@ function defineScormInteraction(number, id, type, question, correct_response, we
 }
 
 function getLearnerResponseById(id) {
+    if (!SCORM_OK) {
+        return;
+    }
     return getScormValue('cmi.interactions.' + scormIdToN(id) + '.learner_response');
 }
 
@@ -281,6 +318,9 @@ function scormIdToN(id) {
 }
 
 function displayScormInteraction(id) {
+    if (!SCORM_OK) {
+        return;
+    }
     var n = scormIdToN(id);
     var now = new Date();
     if (SCORM_QUESTIONS[n].timestamp !== null) {
@@ -291,6 +331,9 @@ function displayScormInteraction(id) {
 }
 
 function answerScormInteraction(id, learner_response, result, set_latency) {
+    if (!SCORM_OK) {
+        return;
+    }
     var n = scormIdToN(id);
     var currentTime = Math.round(new Date().getTime() / 1000);
     displayScormInteraction(id);
@@ -310,7 +353,8 @@ function answerScormInteraction(id, learner_response, result, set_latency) {
 }
 
 function updateInteractionsScore() {
-    if (!fluidbook.scorm.manageScore) {
+
+    if (!SCORM_OK || !fluidbook.scorm.manageScore) {
         return;
     }
     var score = 0;
@@ -342,6 +386,9 @@ function updateInteractionsScore() {
 }
 
 function setSessionTime() {
+    if (!SCORM_OK) {
+        return;
+    }
     var currentTime = new Date();
     var sessionTime;