Add helper functions

namespaces
Svein-Tore Griff With 2015-02-05 10:46:55 +01:00
parent c8a2465827
commit 9a0da8614b
2 changed files with 48 additions and 32 deletions

View File

@ -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);
}

View File

@ -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);
@ -111,32 +158,4 @@ H5P.getActor = function() {
'mbox': 'mailto:' + user.mail,
'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'
];
};