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);
}
function init(state) {
+ console.log(state);
resize();
$(document).on('click', ".answer", function () {
answer($(this));
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;
}