From 9a0da8614b86c76f07a464195413ad8586af3e5e Mon Sep 17 00:00:00 2001 From: Svein-Tore Griff With Date: Thu, 5 Feb 2015 10:46:55 +0100 Subject: [PATCH] Add helper functions --- js/event-dispatcher.js | 3 -- js/x-api.js | 77 ++++++++++++++++++++++++++---------------- 2 files changed, 48 insertions(+), 32 deletions(-) diff --git a/js/event-dispatcher.js b/js/event-dispatcher.js index 194cec0..70a21cd 100644 --- a/js/event-dispatcher.js +++ b/js/event-dispatcher.js @@ -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); } diff --git a/js/x-api.js b/js/x-api.js index b93437c..a7ecb32 100644 --- a/js/x-api.js +++ b/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); @@ -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' -]; \ No newline at end of file +}; \ No newline at end of file