From: Vincent Vanwaelscappel Date: Mon, 5 Nov 2018 15:02:18 +0000 (+0100) Subject: wait #2227 @1.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=248ba81acd524024955511594d85cfc9702aa861;p=fluidbook-html5.git wait #2227 @1.5 --- diff --git a/js/libs/fluidbook/fluidbook.js b/js/libs/fluidbook/fluidbook.js index 94bcb5ac..a5d03154 100644 --- a/js/libs/fluidbook/fluidbook.js +++ b/js/libs/fluidbook/fluidbook.js @@ -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); } diff --git a/js/libs/fluidbook/fluidbook.scorm.js b/js/libs/fluidbook/fluidbook.scorm.js index a640eb9b..651e162a 100644 --- a/js/libs/fluidbook/fluidbook.scorm.js +++ b/js/libs/fluidbook/fluidbook.scorm.js @@ -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) { diff --git a/js/libs/scorm/scorm.js b/js/libs/scorm/scorm.js index 336c5b06..3a39dd03 100644 --- a/js/libs/scorm/scorm.js +++ b/js/libs/scorm/scorm.js @@ -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; }