Add code to make it easy for others to register for xAPI events

namespaces
Svein-Tore Griff With 2014-11-02 21:37:30 +01:00
parent 5d32c4451c
commit 05d9982070
1 changed files with 19 additions and 1 deletions

View File

@ -129,6 +129,7 @@ H5P.init = function () {
}
instance.on('xAPI', H5P.xAPIListener);
instance.on('xAPI', H5P.xAPIEmitter);
// Resize everything when window is resized.
$window.resize(function () {
@ -155,7 +156,6 @@ H5P.init = function () {
};
H5P.xAPIListener = function(event) {
console.log(event);
if ('verb' in event.statement) {
if (event.statement.verb.id === 'http://adlnet.gov/expapi/verbs/completed') {
var score = event.statement.result.score.raw;
@ -166,6 +166,24 @@ H5P.xAPIListener = function(event) {
}
}
H5P.xAPIEmitter = function (event) {
if (event.statement !== undefined) {
for (var i = 0; i < H5P.xAPIListeners.length; i++) {
H5P.xAPIListeners[i](event.statement)
}
}
}
H5P.xAPIListeners = [];
H5P.onXAPI = function(listener) {
H5P.xAPIListeners.push(listener);
}
H5P.onXAPI(function(statement) {
console.log(statement);
});
/**
* Enable full screen for the given h5p.
*