Add helper functions
parent
c8a2465827
commit
9a0da8614b
|
@ -133,7 +133,6 @@ H5P.EventDispatcher = (function () {
|
|||
* @param {...*} args
|
||||
*/
|
||||
self.trigger = function (type, event) {
|
||||
console.log('triggering');
|
||||
if (self.debug !== undefined) {
|
||||
// Class has debug enabled. Log events.
|
||||
console.log(self.debug + ' - Firing event "' + type + '", ' + (triggers[type] === undefined ? 0 : triggers[type].length) + ' listeners.', getArgs(arguments, 1));
|
||||
|
@ -142,7 +141,6 @@ H5P.EventDispatcher = (function () {
|
|||
if (event === null) {
|
||||
event = new H5P.Event();
|
||||
}
|
||||
console.log(triggers);
|
||||
if (triggers[type] === undefined) {
|
||||
return;
|
||||
}
|
||||
|
@ -152,7 +150,6 @@ H5P.EventDispatcher = (function () {
|
|||
|
||||
|
||||
// Call all listeners
|
||||
console.log(triggers);
|
||||
for (var i = 0; i < triggers[type].length; i++) {
|
||||
triggers[type][i].apply(self, args);
|
||||
}
|
||||
|
|
75
js/x-api.js
75
js/x-api.js
|
@ -77,6 +77,53 @@ H5P.XAPIEvent.prototype.setActor = function() {
|
|||
this.statement.actor = H5P.getActor();
|
||||
};
|
||||
|
||||
H5P.XAPIEvent.prototype.getMaxScore = function() {
|
||||
return this.getVerifiedStatementValue(['result', 'score', 'max']);
|
||||
};
|
||||
|
||||
H5P.XAPIEvent.prototype.getScore = function() {
|
||||
return this.getVerifiedStatementValue(['result', 'score', 'raw']);
|
||||
};
|
||||
|
||||
H5P.XAPIEvent.prototype.getVerifiedStatementValue = function(keys) {
|
||||
var val = this.statement;
|
||||
for (var i in keys) {
|
||||
if (val[keys[i]] === undefined) {
|
||||
return null;
|
||||
}
|
||||
val = val[keys[i]];
|
||||
}
|
||||
return val;
|
||||
}
|
||||
|
||||
H5P.XAPIEvent.allowedXAPIVerbs = [
|
||||
'answered',
|
||||
'asked',
|
||||
'attempted',
|
||||
'attended',
|
||||
'commented',
|
||||
'completed',
|
||||
'exited',
|
||||
'experienced',
|
||||
'failed',
|
||||
'imported',
|
||||
'initialized',
|
||||
'interacted',
|
||||
'launched',
|
||||
'mastered',
|
||||
'passed',
|
||||
'preferred',
|
||||
'progressed',
|
||||
'registered',
|
||||
'responded',
|
||||
'resumed',
|
||||
'scored',
|
||||
'shared',
|
||||
'suspended',
|
||||
'terminated',
|
||||
'voided'
|
||||
];
|
||||
|
||||
H5P.EventDispatcher.prototype.triggerXAPI = function(verb, extra) {
|
||||
var event = this.createXAPIEventTemplate(verb, extra);
|
||||
this.trigger('xAPI', event);
|
||||
|
@ -112,31 +159,3 @@ H5P.getActor = function() {
|
|||
'objectType': 'Agent'
|
||||
};
|
||||
};
|
||||
|
||||
H5P.XAPIEvent.allowedXAPIVerbs = [
|
||||
'answered',
|
||||
'asked',
|
||||
'attempted',
|
||||
'attended',
|
||||
'commented',
|
||||
'completed',
|
||||
'exited',
|
||||
'experienced',
|
||||
'failed',
|
||||
'imported',
|
||||
'initialized',
|
||||
'interacted',
|
||||
'launched',
|
||||
'mastered',
|
||||
'passed',
|
||||
'preferred',
|
||||
'progressed',
|
||||
'registered',
|
||||
'responded',
|
||||
'resumed',
|
||||
'scored',
|
||||
'shared',
|
||||
'suspended',
|
||||
'terminated',
|
||||
'voided'
|
||||
];
|
Loading…
Reference in New Issue