]> _ Git - fluidbook-html5.git/commitdiff
wait #2227 @1.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Nov 2018 15:02:18 +0000 (16:02 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 5 Nov 2018 15:02:18 +0000 (16:02 +0100)
js/libs/fluidbook/fluidbook.js
js/libs/fluidbook/fluidbook.scorm.js
js/libs/scorm/scorm.js

index 94bcb5ac3254b1bacb81b8f6c6294a697ca8df3e..a5d03154c2927bfff8678be19c06aee78d025889 100644 (file)
@@ -205,6 +205,7 @@ Fluidbook.prototype = {
 
         $(this).trigger('fluidbookready');
         $(this).trigger('fluidbook.ready');
+        $(document).trigger('fluidbook.ready');
     },
     loadPlugins: function () {
         $.each(this.datas.plugins, function (k, plugin) {
@@ -415,9 +416,7 @@ Fluidbook.prototype = {
         return;
     },
     pageTransition: function (pageNr) {
-
         $(this).trigger('fluidbook.beforePageTransition');
-
         this.tooltip.hideTooltip();
 
         if (pageNr == undefined) {
@@ -427,7 +426,7 @@ Fluidbook.prototype = {
             }
         }
         pageNr = this.normalizePage(pageNr);
-        if (this.firstTransition || pageNr === this.normalizePage(this.currentPage) || this.currentPage === -1 || !this.support.transitions2d || this.datas.mobileTransitions === 'none') {
+        if ($('#splash').length > 0 || this.firstTransition || pageNr === this.normalizePage(this.currentPage) || this.currentPage === -1 || !this.support.transitions2d || this.datas.mobileTransitions === 'none') {
             this.firstTransition = false;
             return this.pageTransition1D(pageNr);
         }
index a640eb9b9e18d7a612ce58c29a268ef5cab9f4ae..651e162ae0df36545a72766b7e08627239a333eb 100644 (file)
@@ -25,6 +25,10 @@ FluidbookScorm.prototype = {
         $(this.fluidbook).on('fluidbook.links.ready', function () {
             $this.hideScormLinks();
         });
+
+        if (this.fluidbook.datas.scorm_enable && window.initScorm !== undefined) {
+            initScorm();
+        }
     },
 
     hideScormLinks: function () {
@@ -51,15 +55,11 @@ FluidbookScorm.prototype = {
             return false;
         }
         if (undefined !== window.FORCE_SCORM
-               && window.FORCE_SCORM) {
-            return true;
-        }
-        if(!pipwerks.SCORM.API.isFound){
-            pipwerks.SCORM.API.get();
-            return pipwerks.SCORM.API.isFound;
-        }else{
+            && window.FORCE_SCORM) {
             return true;
         }
+
+        return pipwerks.SCORM.API.isFound;
     },
 
     openLinkIfCompleteOrDisplayImage: function (openLink, openImage) {
index 336c5b06174f15cb2f28a473032c51dce4e06e8f..3a39dd0380f36e782a1517efc5194bab0c283e48 100644 (file)
@@ -8,6 +8,9 @@ SCORM_WEIGHTING = 0;
 SCORM_QUESTIONS = [];
 SCORM_SUCCESS_STATUS = 'unknown';
 SCORM_SUCCESS_SCORE = 0;
+SCORM_EVENTS_INITED = false;
+SCORM_INTERACTIONS_INITED = false;
+SCORM_LOCATION_INITED = false;
 
 var _CMI12 = {
     'location': 'cmi.core.lesson_location',
@@ -25,30 +28,20 @@ var _CMI2004 = {
     'exit': 'cmi.exit',
 }
 
-$(function () {
-    if (fluidbook) {
-        initScorm();
-    } else {
-        for (var i = 1; i <= 5; i++) {
-            setTimeout(function () {
-                initScorm();
-            }, 2000 * i);
-        }
-    }
-});
-
 function initScorm() {
     if (SCORM_INITED) {
         return;
     }
-    console.log('init scrom');
+    console.log('init scorm');
     SCORM_INITED = true;
     pipwerks.SCORM.init();
-    pipwerks.SCORM.API.get();
     setScormValue('exit', 'suspend');
     startScormTimer();
-    initScormEvents();
-    initScormInteractions();
+
+    $(document).on('fluidbook.ready', function () {
+        initScormEvents();
+        initScormInteractions();
+    });
 }
 
 function _cmi(key) {
@@ -68,39 +61,47 @@ function _cmi(key) {
 }
 
 function initScormEvents() {
+    if (SCORM_EVENTS_INITED) {
+        return;
+    }
+    SCORM_EVENTS_INITED = true;
+
+    console.log('init scorm events');
     $(window).on('unload', function () {
         finishScorm();
     });
 
-    $(fluidbook).on('fluidbook.splash.hide', function () {
-        console.log('init scorm events');
-        var currentLocation = getScormValue('location');
-        try {
-            if (currentLocation.indexOf('page_') === 0) {
-                var e = currentPage.split('_');
-                if (e.length == 2 && e[0] == 'page') {
-                    fluidbook.setCurrentPage(e[1]);
-                }
-            } else if (currentLocation.indexOf('{') === 0) {
-                var location = JSON.parse(currentLocation);
-                if (location.maxPage) {
-                    fluidbook.contentlock.setMaxPage(location.maxPage, true);
-                }
-                if (location.page) {
-                    fluidbook.setCurrentPage(location.page);
-                }
+    if (SCORM_LOCATION_INITED) {
+        return;
+    }
+    SCORM_LOCATION_INITED = true;
+    var currentLocation = getScormValue('location');
+    try {
+        if (currentLocation.indexOf('page_') === 0) {
+            var e = currentPage.split('_');
+            if (e.length == 2 && e[0] == 'page') {
+                fluidbook.setCurrentPage(e[1]);
+            }
+        } else if (currentLocation.indexOf('{') === 0) {
+            var location = JSON.parse(currentLocation);
+            if (location.maxPage) {
+                fluidbook.contentlock.setMaxPage(location.maxPage, true);
+            }
+            if (location.page) {
+                fluidbook.setCurrentPage(location.page);
             }
-        } catch (err) {
-            console.log(err);
         }
+    } catch (err) {
+        console.log(err);
+    }
 
-        $(fluidbook).on('fluidbook.page.navigation', function (e, page) {
-            scormSaveCurrentPosition(page);
-        });
 
-        $(fluidbook).on('fluidbook.maxpage.set', function (e, page) {
-            scormSaveCurrentPosition(undefined, page);
-        });
+    $(fluidbook).on('fluidbook.page.navigation', function (e, page) {
+        scormSaveCurrentPosition(page);
+    });
+
+    $(fluidbook).on('fluidbook.maxpage.set', function (e, page) {
+        scormSaveCurrentPosition(undefined, page);
     });
 
 
@@ -163,6 +164,10 @@ function setScormValue(elementName, value) {
 }
 
 function initScormInteractions() {
+    if (SCORM_INTERACTIONS_INITED) {
+        return;
+    }
+    SCORM_INTERACTIONS_INITED = true;
     if (fluidbook.datas.scorm_quizdata === '') {
         return;
     }