MDL-67788 core_h5p: add tracking to player
[moodle.git] / h5p / js / h5p_overrides.js
CommitLineData
9e67f5e3
AN
1H5P._getLibraryPath = H5P.getLibraryPath;
2H5P.getLibraryPath = function (library) {
3 if (H5PIntegration.moodleLibraryPaths) {
4 if (H5PIntegration.moodleLibraryPaths[library]) {
5 return H5PIntegration.moodleLibraryPaths[library];
6 }
7 }
8 return H5P._getLibraryPath(library);
9};
8685c313
FR
10H5P.findInstanceFromId = function (contentId) {
11 if (!contentId) {
12 return H5P.instances[0];
13 }
14 if (H5P.instances !== undefined) {
15 for (var i = 0; i < H5P.instances.length; i++) {
16 if (H5P.instances[i].contentId === contentId) {
17 return H5P.instances[i];
18 }
19 }
20 }
21 return undefined;
22};
23H5P.getXAPIStatements = function (contentId, statement) {
24 var statements = [];
25 var instance = H5P.findInstanceFromId(contentId);
26 if (!instance){
27 return statements;
28 }
29 if (instance.getXAPIData == undefined) {
30 var xAPIData = {
31 statement: statement
32 };
33 } else {
34 var xAPIData = instance.getXAPIData();
35 }
36 if (xAPIData.statement != undefined) {
37 statements.push(xAPIData.statement);
38 }
39 if (xAPIData.children != undefined) {
40 statements = statements.concat(xAPIData.children.map(a => a.statement));
41 }
42 return statements;
43};
44H5P.getMoodleComponent = function () {
45 if (H5PIntegration.moodleComponent) {
46 return H5PIntegration.moodleComponent;
47 }
48 return undefined;
49};