And again...
This commit is contained in:
97
dist/scorm-again.js
vendored
97
dist/scorm-again.js
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.js.map
vendored
2
dist/scorm-again.js.map
vendored
File diff suppressed because one or more lines are too long
2
dist/scorm-again.min.js
vendored
2
dist/scorm-again.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -3,7 +3,7 @@ import {CMIArray} from './cmi/common';
|
|||||||
import {ValidationError} from './exceptions';
|
import {ValidationError} from './exceptions';
|
||||||
import ErrorCodes from './constants/error_codes';
|
import ErrorCodes from './constants/error_codes';
|
||||||
import APIConstants from './constants/api_constants';
|
import APIConstants from './constants/api_constants';
|
||||||
import {sortFlattenedCMIElements, unflatten} from './utilities';
|
import {unflatten} from './utilities';
|
||||||
import debounce from 'lodash.debounce';
|
import debounce from 'lodash.debounce';
|
||||||
|
|
||||||
const global_constants = APIConstants.global;
|
const global_constants = APIConstants.global;
|
||||||
@@ -848,66 +848,70 @@ export default class BaseAPI {
|
|||||||
* @param {string} CMIElement
|
* @param {string} CMIElement
|
||||||
*/
|
*/
|
||||||
loadFromFlattenedJSON(json, CMIElement) {
|
loadFromFlattenedJSON(json, CMIElement) {
|
||||||
|
console.clear();
|
||||||
if (!this.isNotInitialized()) {
|
if (!this.isNotInitialized()) {
|
||||||
console.error(
|
console.error(
|
||||||
'loadFromFlattenedJSON can only be called before the call to lmsInitialize.');
|
'loadFromFlattenedJSON can only be called before the call to lmsInitialize.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test match pattern.
|
||||||
|
*
|
||||||
|
* @param {string} a
|
||||||
|
* @param {string} c
|
||||||
|
* @param {RegExp} a_pattern
|
||||||
|
* @return {number}
|
||||||
|
*/
|
||||||
|
function testPattern(a, c, a_pattern) {
|
||||||
|
const a_match = a.match(a_pattern);
|
||||||
|
|
||||||
|
if (a_match !== null) {
|
||||||
|
let c_match = c.match(
|
||||||
|
new RegExp(a_match[1] + Number(a_match[2]) + '.(.*)'));
|
||||||
|
if (c_match !== null) {
|
||||||
|
const a_int = Number(a_match[2]);
|
||||||
|
|
||||||
|
if (a_match[3] === 'id') {
|
||||||
|
return -1;
|
||||||
|
} else if (a_match[3] === 'type' && c_match[1] !== 'id') {
|
||||||
|
return -1;
|
||||||
|
} else {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
} else if ((c_match = c.match(a_pattern)) !== null) {
|
||||||
|
return Number(a_match[2]) - Number(c_match[2]);
|
||||||
|
} else {
|
||||||
|
return testPattern(c, a, a_pattern);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const int_pattern = /^(cmi\.interactions\.)(\d+)\.(.*)$/;
|
||||||
|
const obj_pattern = /^(cmi\.objectives\.)(\d+)\.(.*)$/;
|
||||||
|
|
||||||
const result = Object.keys(json).map(function(key) {
|
const result = Object.keys(json).map(function(key) {
|
||||||
return [String(key), json[key]];
|
return [String(key), json[key]];
|
||||||
});
|
});
|
||||||
|
|
||||||
// CMI interactions need to have id and type loaded before any other fields
|
// CMI interactions need to have id and type loaded before any other fields
|
||||||
result.sort(function([a, b], [c, d]) {
|
result.sort(function([a, b], [c, d]) {
|
||||||
/**
|
let test;
|
||||||
* Test match pattern.
|
if ((test = testPattern(a, c, int_pattern)) !== null) {
|
||||||
*
|
return test;
|
||||||
* @param {string} a
|
}
|
||||||
* @param {string} c
|
if ((test = testPattern(a, c, obj_pattern)) !== null) {
|
||||||
* @param {RegExp} a_pattern
|
return test;
|
||||||
* @param {RegExp} c_pattern
|
|
||||||
* @return {number}
|
|
||||||
*/
|
|
||||||
function testPattern(a, c, a_pattern, c_pattern) {
|
|
||||||
if (a.match(c_pattern) && c.match(a_pattern)) {
|
|
||||||
const a1 = Number(a.match(c_pattern)[1]);
|
|
||||||
const c1 = Number(c.match(a_pattern)[1]);
|
|
||||||
if (a1 === c1) return -1;
|
|
||||||
else return 1;
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const int_id_pattern = /^cmi\.interactions\.(\d+)\.id$/;
|
if (a < c) {
|
||||||
const int_type_pattern = /^cmi\.interactions\.(\d+)\.type$/;
|
return -1;
|
||||||
const int_pattern = /^cmi\.interactions\.(\d+)/;
|
|
||||||
const obj_id_pattern = /^cmi\.objectives\.(\d+)\.id$/;
|
|
||||||
const obj_pattern = /^cmi\.objectives\.(\d+)/;
|
|
||||||
|
|
||||||
let id_test = testPattern(a, c, int_id_pattern, int_pattern);
|
|
||||||
if (id_test !== 0) {
|
|
||||||
return id_test;
|
|
||||||
}
|
}
|
||||||
id_test = testPattern(a, c, int_pattern, int_id_pattern);
|
if (a > c) {
|
||||||
if (id_test !== 0) {
|
return 1;
|
||||||
return id_test;
|
|
||||||
}
|
}
|
||||||
id_test = testPattern(a, c, int_type_pattern, int_pattern);
|
|
||||||
if (id_test !== 0) {
|
|
||||||
return id_test;
|
|
||||||
}
|
|
||||||
id_test = testPattern(a, c, int_pattern, int_type_pattern);
|
|
||||||
if (id_test !== 0) {
|
|
||||||
return id_test;
|
|
||||||
}
|
|
||||||
id_test = testPattern(a, c, obj_id_pattern, obj_pattern);
|
|
||||||
if (id_test !== 0) {
|
|
||||||
return id_test;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (a < c) return -1;
|
|
||||||
if (a > c) return 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user