-
Notifications
You must be signed in to change notification settings - Fork 27
/
xapi-generator.js
45 lines (37 loc) · 1.12 KB
/
xapi-generator.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
var H5P = H5P || {};
H5P.TextInputField = H5P.TextInputField || {};
/**
* Generate xAPI statements
*/
H5P.TextInputField.XAPIGenerator = (function ($) {
function XAPIGenerator(question) {
// Set up default response object
this.event = {
description: {
'en-US': question // We don't actually know the language of the question
},
type: 'http://adlnet.gov/expapi/activities/cmi.interaction',
interactionType: 'fill-in',
};
}
XAPIGenerator.prototype.constructor = XAPIGenerator;
/**
* Extend xAPI template
* @param {H5P.XAPIEvent} xApiTemplate xAPI event template
* @param {string} answer Text input given
* @return {H5P.XAPIEvent} Extended xAPI event
*/
XAPIGenerator.prototype.generateXApi = function (xApiTemplate, answer) {
let statement = xApiTemplate.data.statement;
statement = $.extend(true, statement, {
result: {
response: answer
}
});
if (statement.object) {
statement.object.definition = $.extend(true, statement.object.definition, this.event);
}
return xApiTemplate;
};
return XAPIGenerator;
})(H5P.jQuery);