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 * @param {...*} args
*/ */
self.trigger = function (type, event) { self.trigger = function (type, event) {
console.log('triggering');
if (self.debug !== undefined) { if (self.debug !== undefined) {
// Class has debug enabled. Log events. // Class has debug enabled. Log events.
console.log(self.debug + ' - Firing event "' + type + '", ' + (triggers[type] === undefined ? 0 : triggers[type].length) + ' listeners.', getArgs(arguments, 1)); 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) { if (event === null) {
event = new H5P.Event(); event = new H5P.Event();
} }
console.log(triggers);
if (triggers[type] === undefined) { if (triggers[type] === undefined) {
return; return;
} }
@ -152,7 +150,6 @@ H5P.EventDispatcher = (function () {
// Call all listeners // Call all listeners
console.log(triggers);
for (var i = 0; i < triggers[type].length; i++) { for (var i = 0; i < triggers[type].length; i++) {
triggers[type][i].apply(self, args); triggers[type][i].apply(self, args);
} }

View File

@ -77,6 +77,53 @@ H5P.XAPIEvent.prototype.setActor = function() {
this.statement.actor = H5P.getActor(); 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) { H5P.EventDispatcher.prototype.triggerXAPI = function(verb, extra) {
var event = this.createXAPIEventTemplate(verb, extra); var event = this.createXAPIEventTemplate(verb, extra);
this.trigger('xAPI', event); this.trigger('xAPI', event);
@ -112,31 +159,3 @@ H5P.getActor = function() {
'objectType': 'Agent' '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'
];