From: Vincent Vanwaelscappel Date: Mon, 8 Aug 2022 14:06:20 +0000 (+0200) Subject: wait #5375 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=67cc2e28749c2a6b1b61ffbe511da98e435e2e27;p=fluidbook-toolbox.git wait #5375 @1 --- diff --git a/resources/quiz/js/app.js b/resources/quiz/js/app.js index e52db5cf1..8989ee4a4 100644 --- a/resources/quiz/js/app.js +++ b/resources/quiz/js/app.js @@ -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)); diff --git a/resources/scorm/scorm.js b/resources/scorm/scorm.js index 53e42c1c3..f1092484a 100644 --- a/resources/scorm/scorm.js +++ b/resources/scorm/scorm.js @@ -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; }