Fixed issue #2397891 (drupal.org), and made jshint a little happier

namespaces
Pål Jørgensen 2014-12-30 10:54:26 +01:00
parent cc455f2b2d
commit ec4678bf0b
2 changed files with 23 additions and 23 deletions

View File

@ -90,7 +90,7 @@ var H5P = H5P || (function () {
loadContent(contentId, h5ps[i]); loadContent(contentId, h5ps[i]);
contentId++; contentId++;
} }
}; }
/** /**
* Return integration object * Return integration object

View File

@ -164,21 +164,21 @@ H5P.xAPIListener = function(event) {
H5P.setFinished(contentId, score, maxScore); H5P.setFinished(contentId, score, maxScore);
} }
} }
} };
H5P.xAPIEmitter = function (event) { H5P.xAPIEmitter = function (event) {
if (event.statement !== undefined) { if (event.statement !== undefined) {
for (var i = 0; i < H5P.xAPIListeners.length; i++) { for (var i = 0; i < H5P.xAPIListeners.length; i++) {
H5P.xAPIListeners[i](event.statement) H5P.xAPIListeners[i](event.statement);
}
} }
} }
};
H5P.xAPIListeners = []; H5P.xAPIListeners = [];
H5P.onXAPI = function(listener) { H5P.onXAPI = function(listener) {
H5P.xAPIListeners.push(listener); H5P.xAPIListeners.push(listener);
} };
H5P.onXAPI(function(statement) { H5P.onXAPI(function(statement) {
console.log(statement); console.log(statement);
@ -449,7 +449,7 @@ H5P.EventEnabled.prototype.on = function(type, listener) {
} }
this.listeners[type].push(listener); this.listeners[type].push(listener);
} }
} };
H5P.EventEnabled.prototype.off = function (type, listener) { H5P.EventEnabled.prototype.off = function (type, listener) {
if (this.listeners[type] !== undefined) { if (this.listeners[type] !== undefined) {
@ -458,7 +458,7 @@ H5P.EventEnabled.prototype.off = function (type, listener) {
listeners[type].splice(removeIndex, 1); listeners[type].splice(removeIndex, 1);
} }
} }
} };
H5P.EventEnabled.prototype.trigger = function (type, event) { H5P.EventEnabled.prototype.trigger = function (type, event) {
if (event === null) { if (event === null) {
@ -469,16 +469,16 @@ H5P.EventEnabled.prototype.trigger = function (type, event) {
this.listeners[type][i](event); this.listeners[type][i](event);
} }
} }
} };
H5P.Event = function() { H5P.Event = function() {
// We're going to add bubbling, propagation and other features here later // We're going to add bubbling, propagation and other features here later
} };
H5P.XAPIEvent = function() { H5P.XAPIEvent = function() {
H5P.Event.call(this); H5P.Event.call(this);
this.statement = {}; this.statement = {};
} };
H5P.XAPIEvent.prototype = Object.create(H5P.Event.prototype); H5P.XAPIEvent.prototype = Object.create(H5P.Event.prototype);
H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent; H5P.XAPIEvent.prototype.constructor = H5P.XAPIEvent;
@ -490,8 +490,8 @@ H5P.XAPIEvent.prototype.setScoredResult = function(score, maxScore) {
'max': maxScore, 'max': maxScore,
'raw': score 'raw': score
} }
} };
} };
H5P.XAPIEvent.prototype.setVerb = function(verb) { H5P.XAPIEvent.prototype.setVerb = function(verb) {
if (H5P.jQuery.inArray(verb, H5P.XAPIEvent.allowedXAPIVerbs) !== -1) { if (H5P.jQuery.inArray(verb, H5P.XAPIEvent.allowedXAPIVerbs) !== -1) {
@ -500,13 +500,13 @@ H5P.XAPIEvent.prototype.setVerb = function(verb) {
'display': { 'display': {
'en-US': verb 'en-US': verb
} }
} };
} }
else { else {
console.log('illegal verb'); console.log('illegal verb');
} }
// Else: Fail silently... // Else: Fail silently...
} };
H5P.XAPIEvent.prototype.setObject = function(instance) { H5P.XAPIEvent.prototype.setObject = function(instance) {
this.statement.object = { this.statement.object = {
@ -514,17 +514,17 @@ H5P.XAPIEvent.prototype.setObject = function(instance) {
'id': window.location.origin + Drupal.settings.basePath + 'node/' + instance.contentId, 'id': window.location.origin + Drupal.settings.basePath + 'node/' + instance.contentId,
//'contentId': instance.contentId, //'contentId': instance.contentId,
'objectType': 'Activity' 'objectType': 'Activity'
} };
} };
H5P.XAPIEvent.prototype.setActor = function() { H5P.XAPIEvent.prototype.setActor = function() {
this.statement.actor = H5P.getActor(); this.statement.actor = H5P.getActor();
} };
H5P.EventEnabled.prototype.triggerXAPI = function(verb, extra) { H5P.EventEnabled.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);
} };
H5P.EventEnabled.prototype.createXAPIEventTemplate = function(verb, extra) { H5P.EventEnabled.prototype.createXAPIEventTemplate = function(verb, extra) {
var event = new H5P.XAPIEvent(); var event = new H5P.XAPIEvent();
@ -540,17 +540,17 @@ H5P.EventEnabled.prototype.createXAPIEventTemplate = function(verb, extra) {
event.setObject(this); event.setObject(this);
} }
return event; return event;
} };
H5P.getActor = function() { H5P.getActor = function() {
var user = H5PIntegration.getUser(); var user = H5PIntegration.getUser();
return { return {
'name': user.name, 'name': user.name,
'mbox': 'mailto:' . user.mail, 'mbox': 'mailto:' + user.mail,
'objectType': 'Agent' 'objectType': 'Agent'
} };
} };
H5P.XAPIEvent.allowedXAPIVerbs = [ H5P.XAPIEvent.allowedXAPIVerbs = [
'answered', 'answered',
@ -578,7 +578,7 @@ H5P.XAPIEvent.allowedXAPIVerbs = [
'suspended', 'suspended',
'terminated', 'terminated',
'voided' 'voided'
] ];
/** /**
* Used to print useful error messages. * Used to print useful error messages.