Added xAPI support

pull/1/head
Svein-Tore Griff With 2014-10-13 21:51:36 +02:00
parent 1ebb38b88b
commit f491786c47
1 changed files with 11 additions and 12 deletions

View File

@ -16,6 +16,7 @@ H5P.QuestionSet = function (options, contentId) {
} }
var $ = H5P.jQuery; var $ = H5P.jQuery;
var self = this;
var texttemplate = var texttemplate =
'<% if (introPage.showIntroPage) { %>' + '<% if (introPage.showIntroPage) { %>' +
@ -90,8 +91,7 @@ H5P.QuestionSet = function (options, contentId) {
finishButtonText: 'Finish', finishButtonText: 'Finish',
solutionButtonText: 'Show solution', solutionButtonText: 'Show solution',
showAnimations: false showAnimations: false
}, }
postUserStatistics: (H5P.postUserStatistics === true)
}; };
var template = new EJS({text: texttemplate}); var template = new EJS({text: texttemplate});
@ -109,8 +109,7 @@ H5P.QuestionSet = function (options, contentId) {
// TODO: Render on init, inject in template. // TODO: Render on init, inject in template.
$.extend(question.params, { $.extend(question.params, {
displaySolutionsButton: false, displaySolutionsButton: false
postUserStatistics: false
}); });
questionInstances.push(H5P.newRunnable(question, contentId)); questionInstances.push(H5P.newRunnable(question, contentId));
} }
@ -153,7 +152,7 @@ H5P.QuestionSet = function (options, contentId) {
// Trigger resize on question in case the size of the QS has changed. // Trigger resize on question in case the size of the QS has changed.
var instance = questionInstances[questionNumber]; var instance = questionInstances[questionNumber];
if (instance.$ !== undefined) { if (instance.$ !== undefined) {
instance.$.trigger('resize'); instance.triggerH5PEvent('resize');
} }
// Update progress indicator // Update progress indicator
@ -202,9 +201,7 @@ H5P.QuestionSet = function (options, contentId) {
passed: success passed: success
}; };
var displayResults = function () { var displayResults = function () {
if (params.postUserStatistics === true) { self.triggerH5PxAPIEvent('completed', H5P.getxAPIScoredResult(getScore(), totalScore()));
H5P.setFinished(contentId, getScore(), totalScore());
}
if (!params.endGame.showResultPage) { if (!params.endGame.showResultPage) {
$(returnObject).trigger('h5pQuestionSetFinished', eventData); $(returnObject).trigger('h5pQuestionSetFinished', eventData);
@ -302,9 +299,11 @@ H5P.QuestionSet = function (options, contentId) {
var question = questionInstances[i]; var question = questionInstances[i];
question.attach($('.question-container:eq(' + i + ')', $myDom)); question.attach($('.question-container:eq(' + i + ')', $myDom));
$(question).on('h5pQuestionAnswered', function () { question.registerH5PEventListener('xAPI', function (event) {
$('.progress-dot:eq(' + currentQuestion +')', $myDom).removeClass('unanswered').addClass('answered'); if (event.verb === 'attempted') {
_updateButtons(); $('.progress-dot:eq(' + currentQuestion +')', $myDom).removeClass('unanswered').addClass('answered');
_updateButtons();
}
}); });
if (question.getAnswerGiven()) { if (question.getAnswerGiven()) {
$('.progress-dot:eq(' + i +')' $('.progress-dot:eq(' + i +')'
@ -343,7 +342,7 @@ H5P.QuestionSet = function (options, contentId) {
showSolutions(); showSolutions();
} }
this.$.trigger('resize'); this.triggerH5PEvent('resize');
return this; return this;
}; };