2016-11-14 11:31:15 +01:00
|
|
|
H5P = H5P || {};
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2013-04-26 17:27:35 +02:00
|
|
|
/**
|
|
|
|
* Will render a Question with multiple choices for answers.
|
|
|
|
*
|
|
|
|
* Events provided:
|
|
|
|
* - h5pQuestionSetFinished: Triggered when a question is finished. (User presses Finish-button)
|
|
|
|
*
|
|
|
|
* @param {Array} options
|
|
|
|
* @param {int} contentId
|
2016-09-26 15:19:53 +02:00
|
|
|
* @param {Object} contentData
|
2013-04-26 17:27:35 +02:00
|
|
|
* @returns {H5P.QuestionSet} Instance
|
|
|
|
*/
|
2016-09-26 15:19:53 +02:00
|
|
|
H5P.QuestionSet = function (options, contentId, contentData) {
|
2013-04-26 17:27:35 +02:00
|
|
|
if (!(this instanceof H5P.QuestionSet)) {
|
2016-09-26 15:19:53 +02:00
|
|
|
return new H5P.QuestionSet(options, contentId, contentData);
|
2013-04-26 17:27:35 +02:00
|
|
|
}
|
2015-02-04 16:40:29 +01:00
|
|
|
H5P.EventDispatcher.call(this);
|
2013-04-04 15:44:06 +02:00
|
|
|
var $ = H5P.jQuery;
|
2014-10-13 21:51:36 +02:00
|
|
|
var self = this;
|
2015-02-04 16:40:29 +01:00
|
|
|
this.contentId = contentId;
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2017-08-30 09:04:01 +02:00
|
|
|
var defaults = {
|
|
|
|
initialQuestion: 0,
|
|
|
|
progressType: 'dots',
|
|
|
|
passPercentage: 50,
|
|
|
|
questions: [],
|
|
|
|
introPage: {
|
|
|
|
showIntroPage: false,
|
|
|
|
title: '',
|
|
|
|
introduction: '',
|
|
|
|
startButtonText: 'Start'
|
|
|
|
},
|
|
|
|
texts: {
|
|
|
|
prevButton: 'Previous question',
|
|
|
|
nextButton: 'Next question',
|
|
|
|
finishButton: 'Finish',
|
|
|
|
textualProgress: 'Question: @current of @total questions',
|
|
|
|
jumpToQuestion: 'Question %d of %total',
|
|
|
|
questionLabel: 'Question',
|
|
|
|
readSpeakerProgress: 'Question @current of @total',
|
|
|
|
unansweredText: 'Unanswered',
|
|
|
|
answeredText: 'Answered',
|
|
|
|
currentQuestionText: 'Current question'
|
|
|
|
},
|
|
|
|
endGame: {
|
|
|
|
showResultPage: true,
|
|
|
|
noResultMessage: 'Finished',
|
|
|
|
message: 'Your result:',
|
|
|
|
oldFeedback: {
|
|
|
|
successGreeting: '',
|
|
|
|
successComment: '',
|
|
|
|
failGreeting: '',
|
|
|
|
failComment: ''
|
|
|
|
},
|
|
|
|
overallFeedback: [],
|
|
|
|
finishButtonText: 'Finish',
|
|
|
|
solutionButtonText: 'Show solution',
|
|
|
|
retryButtonText: 'Retry',
|
|
|
|
showAnimations: false,
|
|
|
|
skipButtonText: 'Skip video',
|
|
|
|
showSolutionButton: true
|
|
|
|
},
|
|
|
|
override: {},
|
|
|
|
disableBackwardsNavigation: false
|
|
|
|
};
|
|
|
|
var params = $.extend(true, {}, defaults, options);
|
|
|
|
|
2013-04-26 17:27:35 +02:00
|
|
|
var texttemplate =
|
|
|
|
'<% if (introPage.showIntroPage) { %>' +
|
|
|
|
'<div class="intro-page">' +
|
2014-04-15 14:48:28 +02:00
|
|
|
' <% if (introPage.title) { %>' +
|
2015-11-06 14:24:11 +01:00
|
|
|
' <div class="title"><span><%= introPage.title %></span></div>' +
|
2014-04-15 14:48:28 +02:00
|
|
|
' <% } %>' +
|
2014-04-15 11:33:01 +02:00
|
|
|
' <% if (introPage.introduction) { %>' +
|
|
|
|
' <div class="introduction"><%= introPage.introduction %></div>' +
|
|
|
|
' <% } %>' +
|
2015-08-12 14:46:49 +02:00
|
|
|
' <div class="buttons"><a class="qs-startbutton h5p-joubelui-button h5p-button"><%= introPage.startButtonText %></a></div>' +
|
2013-04-26 17:27:35 +02:00
|
|
|
'</div>' +
|
2013-05-03 10:05:49 +02:00
|
|
|
'<% } %>' +
|
2016-06-27 11:43:00 +02:00
|
|
|
'<div tabindex="-1" class="qs-progress-announcer"></div>' +
|
2013-05-03 10:05:49 +02:00
|
|
|
'<div class="questionset<% if (introPage.showIntroPage) { %> hidden<% } %>">' +
|
2013-04-26 17:27:35 +02:00
|
|
|
' <% for (var i=0; i<questions.length; i++) { %>' +
|
2013-07-16 22:10:07 +02:00
|
|
|
' <div class="question-container"></div>' +
|
2013-04-26 17:27:35 +02:00
|
|
|
' <% } %>' +
|
|
|
|
' <div class="qs-footer">' +
|
|
|
|
' <div class="qs-progress">' +
|
2016-10-03 13:06:01 +02:00
|
|
|
' <% if (progressType == "dots") { %>' +
|
2016-07-04 11:42:56 +02:00
|
|
|
' <ul class="dots-container" role="navigation">' +
|
2013-04-26 17:27:35 +02:00
|
|
|
' <% for (var i=0; i<questions.length; i++) { %>' +
|
2016-10-04 14:18:50 +02:00
|
|
|
' <li class="progress-item">' +
|
|
|
|
' <a href="#" ' +
|
|
|
|
' class="progress-dot unanswered<%' +
|
|
|
|
' if (disableBackwardsNavigation) { %> disabled <% } %>"' +
|
|
|
|
' aria-label="<%=' +
|
|
|
|
' texts.jumpToQuestion.replace("%d", i + 1).replace("%total", questions.length)' +
|
|
|
|
' + ", " + texts.unansweredText %>" tabindex="-1" ' +
|
|
|
|
' <% if (disableBackwardsNavigation) { %> aria-disabled="true" <% } %>' +
|
|
|
|
' ></a>' +
|
|
|
|
' </li>' +
|
2016-07-04 11:29:28 +02:00
|
|
|
' <% } %>' +
|
2013-04-26 17:27:35 +02:00
|
|
|
' </div>' +
|
|
|
|
' <% } else if (progressType == "textual") { %>' +
|
|
|
|
' <span class="progress-text"></span>' +
|
|
|
|
' <% } %>' +
|
|
|
|
' </div>' +
|
|
|
|
' </div>' +
|
|
|
|
'</div>';
|
|
|
|
|
2017-08-30 09:04:01 +02:00
|
|
|
var solutionButtonTemplate = params.endGame.showSolutionButton ?
|
2016-09-28 11:28:53 +02:00
|
|
|
' <button type="button" class="h5p-joubelui-button h5p-button qs-solutionbutton"><%= solutionButtonText %></button>':
|
|
|
|
'';
|
|
|
|
|
2013-04-26 17:27:35 +02:00
|
|
|
var resulttemplate =
|
|
|
|
'<div class="questionset-results">' +
|
2016-04-07 16:23:15 +02:00
|
|
|
' <div class="greeting"><%= message %></div>' +
|
2015-08-18 13:58:33 +02:00
|
|
|
' <div class="feedback-section">' +
|
|
|
|
' <div class="feedback-scorebar"></div>' +
|
|
|
|
' <div class="feedback-text"></div>' +
|
2013-10-31 13:39:51 +01:00
|
|
|
' </div>' +
|
2016-04-07 16:23:15 +02:00
|
|
|
' <% if (comment) { %>' +
|
|
|
|
' <div class="result-header"><%= comment %></div>' +
|
|
|
|
' <% } %>' +
|
2016-05-20 09:33:45 +02:00
|
|
|
' <% if (resulttext) { %>' +
|
2016-04-07 16:23:15 +02:00
|
|
|
' <div class="result-text"><%= resulttext %></div>' +
|
2016-05-20 09:33:45 +02:00
|
|
|
' <% } %>' +
|
2015-08-12 14:46:49 +02:00
|
|
|
' <div class="buttons">' +
|
2016-04-08 15:36:06 +02:00
|
|
|
' <button type="button" class="h5p-joubelui-button h5p-button qs-finishbutton"><%= finishButtonText %></button>' +
|
2016-09-28 11:28:53 +02:00
|
|
|
solutionButtonTemplate +
|
2016-04-08 15:36:06 +02:00
|
|
|
' <button type="button" class="h5p-joubelui-button h5p-button qs-retrybutton"><%= retryButtonText %></button>' +
|
2015-08-12 14:46:49 +02:00
|
|
|
' </div>' +
|
2013-04-26 17:27:35 +02:00
|
|
|
'</div>';
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
var template = new EJS({text: texttemplate});
|
|
|
|
var endTemplate = new EJS({text: resulttemplate});
|
2017-08-30 09:04:01 +02:00
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2016-11-14 10:05:22 +01:00
|
|
|
var initialParams = $.extend(true, {}, defaults, options);
|
2016-10-20 13:36:40 +02:00
|
|
|
var poolOrder; // Order of questions in a pool
|
2013-04-04 15:44:06 +02:00
|
|
|
var currentQuestion = 0;
|
2015-06-19 15:40:35 +02:00
|
|
|
var questionInstances = [];
|
2016-10-17 10:43:07 +02:00
|
|
|
var questionOrder; //Stores order of questions to allow resuming of question set
|
2013-04-04 15:44:06 +02:00
|
|
|
var $myDom;
|
2015-08-18 13:58:33 +02:00
|
|
|
var scoreBar;
|
2015-10-12 09:22:37 +02:00
|
|
|
var up;
|
2016-09-26 11:45:15 +02:00
|
|
|
var renderSolutions = false;
|
2016-10-03 13:06:01 +02:00
|
|
|
var showingSolutions = false;
|
2016-09-26 15:19:53 +02:00
|
|
|
contentData = contentData || {};
|
2016-10-16 11:14:52 +02:00
|
|
|
|
|
|
|
// Bring question set up to date when resuming
|
2016-09-26 15:19:53 +02:00
|
|
|
if (contentData.previousState) {
|
2016-10-14 16:48:03 +02:00
|
|
|
if (contentData.previousState.progress) {
|
|
|
|
currentQuestion = contentData.previousState.progress;
|
|
|
|
}
|
2016-10-16 11:14:52 +02:00
|
|
|
questionOrder = contentData.previousState.order;
|
|
|
|
}
|
|
|
|
|
2016-10-20 13:36:40 +02:00
|
|
|
/**
|
|
|
|
* Randomizes questions in an array and updates an array containing their order
|
|
|
|
* @param {array} questions
|
|
|
|
* @return {Object.<array, array>} questionOrdering
|
|
|
|
*/
|
2016-11-14 11:31:15 +01:00
|
|
|
var randomizeQuestionOrdering = function (questions) {
|
2016-10-20 13:36:40 +02:00
|
|
|
|
2016-10-20 15:45:58 +02:00
|
|
|
// Save the original order of the questions in a multidimensional array [[question0,0],[question1,1]...
|
2017-07-13 15:51:24 +02:00
|
|
|
var questionOrdering = questions.map(function (questionInstance, index) { return [questionInstance, index]; });
|
2016-10-20 13:36:40 +02:00
|
|
|
|
2016-10-20 15:45:58 +02:00
|
|
|
// Shuffle the multidimensional array
|
2016-10-20 13:36:40 +02:00
|
|
|
questionOrdering = H5P.shuffleArray(questionOrdering);
|
|
|
|
|
2016-10-20 15:45:58 +02:00
|
|
|
// Retrieve question objects from the first index
|
2017-07-13 15:51:24 +02:00
|
|
|
questions = [];
|
2016-10-20 15:45:58 +02:00
|
|
|
for (var i = 0; i < questionOrdering.length; i++) {
|
|
|
|
questions[i] = questionOrdering[i][0];
|
2016-10-20 13:36:40 +02:00
|
|
|
}
|
2016-10-20 15:45:58 +02:00
|
|
|
|
|
|
|
// Retrieve the new shuffled order from the second index
|
|
|
|
var newOrder = [];
|
2017-07-13 15:51:24 +02:00
|
|
|
for (var j = 0; j < questionOrdering.length; j++) {
|
2016-10-20 15:45:58 +02:00
|
|
|
|
|
|
|
// Use a previous order if it exists
|
2017-07-13 15:51:24 +02:00
|
|
|
if (contentData.previousState && contentData.previousState.questionOrder) {
|
|
|
|
newOrder[j] = questionOrder[questionOrdering[j][1]];
|
2016-10-20 15:45:58 +02:00
|
|
|
}
|
|
|
|
else {
|
2017-07-13 15:51:24 +02:00
|
|
|
newOrder[j] = questionOrdering[j][1];
|
2016-10-20 15:45:58 +02:00
|
|
|
}
|
2016-10-20 13:36:40 +02:00
|
|
|
}
|
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
// Return the questions in their new order *with* their new indexes
|
2016-10-20 13:36:40 +02:00
|
|
|
return {
|
2016-10-21 14:21:38 +02:00
|
|
|
questions: questions,
|
|
|
|
questionOrder: newOrder
|
2016-10-20 13:36:40 +02:00
|
|
|
};
|
2016-11-14 10:05:22 +01:00
|
|
|
};
|
2016-10-20 13:36:40 +02:00
|
|
|
|
|
|
|
// Create a pool (a subset) of questions if necessary
|
2016-11-14 11:31:15 +01:00
|
|
|
if (params.poolSize > 0) {
|
2016-10-21 08:38:13 +02:00
|
|
|
|
2016-10-20 13:36:40 +02:00
|
|
|
// If a previous pool exists, recreate it
|
2017-07-13 15:51:24 +02:00
|
|
|
if (contentData.previousState && contentData.previousState.poolOrder) {
|
2016-10-20 13:36:40 +02:00
|
|
|
poolOrder = contentData.previousState.poolOrder;
|
|
|
|
|
|
|
|
// Recreate the pool from the saved data
|
|
|
|
var pool = [];
|
|
|
|
for (var i = 0; i < poolOrder.length; i++) {
|
|
|
|
pool[i] = params.questions[poolOrder[i]];
|
|
|
|
}
|
|
|
|
|
|
|
|
// Replace original questions with just the ones in the pool
|
|
|
|
params.questions = pool;
|
|
|
|
}
|
2016-10-21 14:21:38 +02:00
|
|
|
else { // Otherwise create a new pool
|
2016-10-20 13:36:40 +02:00
|
|
|
// Randomize and get the results
|
2016-11-14 11:31:15 +01:00
|
|
|
var poolResult = randomizeQuestionOrdering(params.questions);
|
2016-10-21 14:21:38 +02:00
|
|
|
var poolQuestions = poolResult.questions;
|
2016-10-20 13:36:40 +02:00
|
|
|
poolOrder = poolResult.questionOrder;
|
|
|
|
|
|
|
|
// Discard extra questions
|
2016-10-21 14:21:38 +02:00
|
|
|
|
|
|
|
poolQuestions = poolQuestions.slice(0, params.poolSize);
|
|
|
|
poolOrder = poolOrder.slice(0, params.poolSize);
|
2016-10-20 13:36:40 +02:00
|
|
|
|
|
|
|
// Replace original questions with just the ones in the pool
|
|
|
|
params.questions = poolQuestions;
|
|
|
|
}
|
2016-09-26 15:19:53 +02:00
|
|
|
}
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2016-10-20 13:36:40 +02:00
|
|
|
// Create the html template for the question container
|
2016-04-21 15:51:43 +02:00
|
|
|
var $template = $(template.render(params));
|
2016-10-20 13:36:40 +02:00
|
|
|
|
2016-04-04 15:50:41 +02:00
|
|
|
// Set overrides for questions
|
2017-06-12 11:07:31 +02:00
|
|
|
var override;
|
|
|
|
if (params.override.showSolutionButton || params.override.retryButton) {
|
|
|
|
override = {};
|
|
|
|
if (params.override.showSolutionButton) {
|
|
|
|
// Force "Show solution" button to be on or off for all interactions
|
|
|
|
override.enableSolutionsButton =
|
|
|
|
(params.override.showSolutionButton === 'on' ? true : false);
|
|
|
|
}
|
2017-06-02 14:02:27 +02:00
|
|
|
|
2017-06-12 11:07:31 +02:00
|
|
|
if (params.override.retryButton) {
|
|
|
|
// Force "Retry" button to be on or off for all interactions
|
|
|
|
override.enableRetry =
|
|
|
|
(params.override.retryButton === 'on' ? true : false);
|
|
|
|
}
|
2016-04-04 15:50:41 +02:00
|
|
|
}
|
|
|
|
|
2016-11-14 15:22:43 +01:00
|
|
|
/**
|
|
|
|
* Generates question instances from H5P objects
|
|
|
|
*
|
|
|
|
* @param {object} questions H5P content types to be created as instances
|
|
|
|
* @return {array} Array of questions instances
|
|
|
|
*/
|
2017-07-13 15:51:24 +02:00
|
|
|
var createQuestionInstancesFromQuestions = function (questions) {
|
2016-11-14 11:31:15 +01:00
|
|
|
var result = [];
|
|
|
|
// Create question instances from questions
|
|
|
|
// Instantiate question instances
|
2016-11-14 15:22:43 +01:00
|
|
|
for (var i = 0; i < questions.length; i++) {
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
var question;
|
|
|
|
// If a previous order exists, use it
|
|
|
|
if (questionOrder !== undefined) {
|
2016-11-14 15:22:43 +01:00
|
|
|
question = questions[questionOrder[i]];
|
2016-11-14 11:31:15 +01:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Use a generic order when initialzing for the first time
|
2016-11-14 15:22:43 +01:00
|
|
|
question = questions[i];
|
2016-11-14 11:31:15 +01:00
|
|
|
}
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
if (override) {
|
|
|
|
// Extend subcontent with the overrided settings.
|
|
|
|
$.extend(question.params.behaviour, override);
|
|
|
|
}
|
2016-04-21 15:51:43 +02:00
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
question.params = question.params || {};
|
|
|
|
var hasAnswers = contentData.previousState && contentData.previousState.answers;
|
|
|
|
var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined,
|
|
|
|
{
|
|
|
|
previousState: hasAnswers ? contentData.previousState.answers[i] : undefined,
|
|
|
|
parent: self
|
|
|
|
});
|
|
|
|
questionInstance.on('resize', function () {
|
|
|
|
up = true;
|
|
|
|
self.trigger('resize');
|
2016-09-26 15:19:53 +02:00
|
|
|
});
|
2016-11-14 11:31:15 +01:00
|
|
|
result.push(questionInstance);
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
2017-05-08 13:59:38 +02:00
|
|
|
};
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
// Create question instances from questions given by params
|
|
|
|
questionInstances = createQuestionInstancesFromQuestions(params.questions);
|
|
|
|
|
2016-10-16 11:14:52 +02:00
|
|
|
// Randomize questions only on instantiation
|
|
|
|
if (params.randomQuestions && contentData.previousState === undefined) {
|
2016-11-14 11:31:15 +01:00
|
|
|
var result = randomizeQuestionOrdering(questionInstances);
|
2016-10-19 08:50:04 +02:00
|
|
|
questionInstances = result.questions;
|
|
|
|
questionOrder = result.questionOrder;
|
2013-04-04 15:44:06 +02:00
|
|
|
}
|
|
|
|
|
2015-08-12 14:46:49 +02:00
|
|
|
// Resize all interactions on resize
|
|
|
|
self.on('resize', function () {
|
2015-10-12 09:22:37 +02:00
|
|
|
if (up) {
|
|
|
|
// Prevent resizing the question again.
|
|
|
|
up = false;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2015-08-12 14:46:49 +02:00
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
|
|
|
questionInstances[i].trigger('resize');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
// Update button state.
|
|
|
|
var _updateButtons = function () {
|
2016-10-03 13:06:01 +02:00
|
|
|
// Verify that current question is answered when backward nav is disabled
|
|
|
|
if (params.disableBackwardsNavigation) {
|
2017-07-13 15:51:24 +02:00
|
|
|
if (questionInstances[currentQuestion].getAnswerGiven() &&
|
|
|
|
questionInstances.length-1 !== currentQuestion) {
|
2016-10-03 13:06:01 +02:00
|
|
|
questionInstances[currentQuestion].showButton('next');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
questionInstances[currentQuestion].hideButton('next');
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
var answered = true;
|
|
|
|
for (var i = questionInstances.length - 1; i >= 0; i--) {
|
|
|
|
answered = answered && (questionInstances[i]).getAnswerGiven();
|
|
|
|
}
|
|
|
|
|
2016-06-28 12:29:15 +02:00
|
|
|
if (currentQuestion === (params.questions.length - 1) &&
|
2015-09-25 10:57:16 +02:00
|
|
|
questionInstances[currentQuestion]) {
|
2016-06-28 12:29:15 +02:00
|
|
|
if (answered) {
|
|
|
|
questionInstances[currentQuestion].showButton('finish');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
questionInstances[currentQuestion].hideButton('finish');
|
|
|
|
}
|
2013-04-04 15:44:06 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-11-18 09:38:44 +01:00
|
|
|
var _stopQuestion = function (questionNumber) {
|
|
|
|
if (questionInstances[questionNumber]) {
|
2015-11-18 09:59:45 +01:00
|
|
|
pauseMedia(questionInstances[questionNumber]);
|
2015-11-18 09:38:44 +01:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-07-04 11:54:28 +02:00
|
|
|
var _showQuestion = function (questionNumber, preventAnnouncement) {
|
2013-04-04 15:44:06 +02:00
|
|
|
// Sanitize input.
|
2013-04-26 17:27:35 +02:00
|
|
|
if (questionNumber < 0) {
|
|
|
|
questionNumber = 0;
|
|
|
|
}
|
|
|
|
if (questionNumber >= params.questions.length) {
|
|
|
|
questionNumber = params.questions.length - 1;
|
|
|
|
}
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2015-12-01 14:42:04 +01:00
|
|
|
currentQuestion = questionNumber;
|
|
|
|
|
2017-05-09 10:27:50 +02:00
|
|
|
handleAutoPlay(currentQuestion);
|
|
|
|
|
2015-09-25 10:57:16 +02:00
|
|
|
// Hide all questions
|
2013-05-06 16:58:24 +02:00
|
|
|
$('.question-container', $myDom).hide().eq(questionNumber).show();
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2015-09-25 10:57:16 +02:00
|
|
|
if (questionInstances[questionNumber]) {
|
|
|
|
// Trigger resize on question in case the size of the QS has changed.
|
|
|
|
var instance = questionInstances[questionNumber];
|
2015-11-27 20:40:48 +01:00
|
|
|
instance.setActivityStarted();
|
2015-09-25 10:57:16 +02:00
|
|
|
if (instance.$ !== undefined) {
|
|
|
|
instance.trigger('resize');
|
|
|
|
}
|
2013-07-19 13:44:34 +02:00
|
|
|
}
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
// Update progress indicator
|
|
|
|
// Test if current has been answered.
|
2013-04-26 17:27:35 +02:00
|
|
|
if (params.progressType === 'textual') {
|
2013-04-04 15:44:06 +02:00
|
|
|
$('.progress-text', $myDom).text(params.texts.textualProgress.replace("@current", questionNumber+1).replace("@total", params.questions.length));
|
2013-04-26 17:27:35 +02:00
|
|
|
}
|
|
|
|
else {
|
2013-04-04 15:44:06 +02:00
|
|
|
// Set currentNess
|
2016-07-04 11:29:28 +02:00
|
|
|
var previousQuestion = $('.progress-dot.current', $myDom).parent().index();
|
2016-06-28 15:07:05 +02:00
|
|
|
if (previousQuestion >= 0) {
|
|
|
|
toggleCurrentDot(previousQuestion, false);
|
|
|
|
toggleAnsweredDot(previousQuestion, questionInstances[previousQuestion].getAnswerGiven());
|
2016-06-28 12:29:15 +02:00
|
|
|
}
|
2016-06-28 15:07:05 +02:00
|
|
|
toggleCurrentDot(questionNumber, true);
|
2013-04-04 15:44:06 +02:00
|
|
|
}
|
|
|
|
|
2016-07-04 11:54:28 +02:00
|
|
|
if (!preventAnnouncement) {
|
|
|
|
// Announce question number of total, must use timeout because of buttons logic
|
|
|
|
setTimeout(function () {
|
|
|
|
var humanizedProgress = params.texts.readSpeakerProgress
|
|
|
|
.replace('@current', (currentQuestion + 1).toString())
|
|
|
|
.replace('@total', questionInstances.length.toString());
|
2016-06-27 11:43:00 +02:00
|
|
|
|
2016-07-04 11:54:28 +02:00
|
|
|
$('.qs-progress-announcer', $myDom)
|
|
|
|
.html(humanizedProgress)
|
2016-07-05 09:50:41 +02:00
|
|
|
.show().focus();
|
2016-06-27 15:42:31 +02:00
|
|
|
|
2016-07-04 11:54:28 +02:00
|
|
|
if (instance && instance.readFeedback) {
|
|
|
|
instance.readFeedback();
|
|
|
|
}
|
|
|
|
}, 0);
|
|
|
|
}
|
2016-06-27 11:43:00 +02:00
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
// Remember where we are
|
|
|
|
_updateButtons();
|
2015-02-04 16:40:29 +01:00
|
|
|
self.trigger('resize');
|
2013-04-04 15:44:06 +02:00
|
|
|
return currentQuestion;
|
|
|
|
};
|
|
|
|
|
2017-05-09 10:27:50 +02:00
|
|
|
/**
|
|
|
|
* Handle autoplays, limit to one at a time
|
2017-06-07 14:44:42 +02:00
|
|
|
*
|
|
|
|
* @param {number} currentQuestionIndex
|
2017-05-09 10:27:50 +02:00
|
|
|
*/
|
2017-06-07 14:44:42 +02:00
|
|
|
var handleAutoPlay = function (currentQuestionIndex) {
|
2017-05-09 10:27:50 +02:00
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
|
|
|
questionInstances[i].pause();
|
|
|
|
}
|
|
|
|
|
2017-06-07 14:44:42 +02:00
|
|
|
var currentQuestion = params.questions[currentQuestionIndex];
|
|
|
|
|
2017-07-13 15:51:24 +02:00
|
|
|
var hasAutoPlay = currentQuestion &&
|
|
|
|
currentQuestion.params.media &&
|
|
|
|
currentQuestion.params.media.params &&
|
|
|
|
currentQuestion.params.media.params.playback &&
|
|
|
|
currentQuestion.params.media.params.playback.autoplay;
|
2017-05-09 10:27:50 +02:00
|
|
|
|
2017-07-03 15:09:49 +02:00
|
|
|
if (hasAutoPlay && typeof questionInstances[currentQuestionIndex].play === 'function') {
|
2017-06-07 14:44:42 +02:00
|
|
|
questionInstances[currentQuestionIndex].play();
|
2017-05-09 10:27:50 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2017-07-03 15:09:49 +02:00
|
|
|
|
|
|
|
|
2014-11-27 11:01:47 +01:00
|
|
|
/**
|
|
|
|
* Show solutions for subcontent, and hide subcontent buttons.
|
|
|
|
* Used for contracts with integrated content.
|
|
|
|
* @public
|
|
|
|
*/
|
2013-05-03 10:05:49 +02:00
|
|
|
var showSolutions = function () {
|
2016-10-03 13:06:01 +02:00
|
|
|
showingSolutions = true;
|
2013-05-03 10:05:49 +02:00
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
2016-10-03 13:06:01 +02:00
|
|
|
|
|
|
|
// Enable back and forth navigation in solution mode
|
2016-10-04 11:43:12 +02:00
|
|
|
toggleDotsNavigation(true);
|
2016-10-03 13:06:01 +02:00
|
|
|
if (i < questionInstances.length - 1) {
|
|
|
|
questionInstances[i].showButton('next');
|
|
|
|
}
|
|
|
|
if (i > 0) {
|
|
|
|
questionInstances[i].showButton('prev');
|
|
|
|
}
|
|
|
|
|
2014-11-27 11:01:47 +01:00
|
|
|
try {
|
2016-06-27 15:42:31 +02:00
|
|
|
// Do not read answers
|
|
|
|
questionInstances[i].toggleReadSpeaker(true);
|
2014-11-27 11:01:47 +01:00
|
|
|
questionInstances[i].showSolutions();
|
2016-06-27 15:42:31 +02:00
|
|
|
questionInstances[i].toggleReadSpeaker(false);
|
2014-11-27 11:01:47 +01:00
|
|
|
}
|
|
|
|
catch(error) {
|
2015-08-20 16:14:29 +02:00
|
|
|
H5P.error("subcontent does not contain a valid showSolutions function");
|
2015-08-20 16:16:02 +02:00
|
|
|
H5P.error(error);
|
2014-11-27 11:01:47 +01:00
|
|
|
}
|
2013-05-03 10:05:49 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-10-04 11:43:12 +02:00
|
|
|
/**
|
|
|
|
* Toggles whether dots are enabled for navigation
|
|
|
|
*/
|
|
|
|
var toggleDotsNavigation = function (enable) {
|
|
|
|
$('.progress-dot', $myDom).each(function () {
|
2016-10-04 14:18:50 +02:00
|
|
|
$(this).toggleClass('disabled', !enable);
|
2016-10-04 11:43:12 +02:00
|
|
|
$(this).attr('aria-disabled', enable ? 'false' : 'true');
|
2016-10-04 14:18:50 +02:00
|
|
|
// Remove tabindex
|
|
|
|
if (!enable) {
|
|
|
|
$(this).attr('tabindex', '-1');
|
|
|
|
}
|
2016-10-04 11:43:12 +02:00
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2014-11-27 11:01:47 +01:00
|
|
|
/**
|
|
|
|
* Resets the task and every subcontent task.
|
|
|
|
* Used for contracts with integrated content.
|
|
|
|
* @public
|
|
|
|
*/
|
|
|
|
var resetTask = function () {
|
2016-11-14 15:22:43 +01:00
|
|
|
|
2016-11-14 15:53:27 +01:00
|
|
|
// Clear previous state to ensure questions are created cleanly
|
2016-11-14 15:22:43 +01:00
|
|
|
contentData.previousState = [];
|
|
|
|
|
2016-10-03 13:06:01 +02:00
|
|
|
showingSolutions = false;
|
2016-11-14 15:22:43 +01:00
|
|
|
|
2014-11-27 11:01:47 +01:00
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
|
|
|
try {
|
|
|
|
questionInstances[i].resetTask();
|
2016-10-03 13:06:01 +02:00
|
|
|
|
|
|
|
// Hide back and forth navigation in normal mode
|
|
|
|
if (params.disableBackwardsNavigation) {
|
2016-10-04 11:43:12 +02:00
|
|
|
toggleDotsNavigation(false);
|
|
|
|
|
2016-10-03 13:06:01 +02:00
|
|
|
// Check if first question is answered by default
|
|
|
|
if (i === 0 && questionInstances[i].getAnswerGiven()) {
|
|
|
|
questionInstances[i].showButton('next');
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
questionInstances[i].hideButton('next');
|
|
|
|
}
|
|
|
|
|
|
|
|
questionInstances[i].hideButton('prev');
|
|
|
|
}
|
2014-11-27 11:01:47 +01:00
|
|
|
}
|
|
|
|
catch(error) {
|
2015-08-20 16:14:29 +02:00
|
|
|
H5P.error("subcontent does not contain a valid resetTask function");
|
2015-08-20 16:16:02 +02:00
|
|
|
H5P.error(error);
|
2014-11-27 11:01:47 +01:00
|
|
|
}
|
2013-05-03 10:05:49 +02:00
|
|
|
}
|
2015-08-12 14:46:49 +02:00
|
|
|
|
|
|
|
// Hide finish button
|
|
|
|
questionInstances[questionInstances.length - 1].hideButton('finish');
|
|
|
|
|
2016-05-30 15:04:24 +02:00
|
|
|
// Mark all tasks as unanswered:
|
2016-06-28 15:07:05 +02:00
|
|
|
$('.progress-dot').each(function (idx) {
|
|
|
|
toggleAnsweredDot(idx, false);
|
|
|
|
});
|
2016-05-30 15:04:24 +02:00
|
|
|
|
2014-11-27 11:01:47 +01:00
|
|
|
//Force the last page to be reRendered
|
|
|
|
rendered = false;
|
2016-10-07 15:15:42 +02:00
|
|
|
|
2017-07-13 15:51:24 +02:00
|
|
|
if (params.poolSize > 0) {
|
2016-11-14 10:05:22 +01:00
|
|
|
|
|
|
|
// Make new pool from params.questions
|
|
|
|
// Randomize and get the results
|
2016-11-14 11:31:15 +01:00
|
|
|
var poolResult = randomizeQuestionOrdering(initialParams.questions);
|
2016-11-14 10:05:22 +01:00
|
|
|
var poolQuestions = poolResult.questions;
|
|
|
|
poolOrder = poolResult.questionOrder;
|
|
|
|
|
|
|
|
// Discard extra questions
|
|
|
|
poolQuestions = poolQuestions.slice(0, params.poolSize);
|
|
|
|
poolOrder = poolOrder.slice(0, params.poolSize);
|
|
|
|
|
|
|
|
// Replace original questions with just the ones in the pool
|
|
|
|
params.questions = poolQuestions;
|
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
// Recreate the question instances
|
|
|
|
questionInstances = createQuestionInstancesFromQuestions(params.questions);
|
2016-11-14 10:05:22 +01:00
|
|
|
|
|
|
|
// Update buttons
|
|
|
|
initializeQuestion();
|
2016-11-14 11:31:15 +01:00
|
|
|
|
2016-11-14 10:05:22 +01:00
|
|
|
} else if (params.randomQuestions) {
|
2016-10-17 10:43:07 +02:00
|
|
|
randomizeQuestions();
|
2016-10-16 11:14:52 +02:00
|
|
|
}
|
|
|
|
|
2013-05-03 10:05:49 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
var rendered = false;
|
|
|
|
|
2015-02-04 16:40:29 +01:00
|
|
|
this.reRender = function () {
|
2013-05-03 10:05:49 +02:00
|
|
|
rendered = false;
|
|
|
|
};
|
|
|
|
|
2016-10-17 10:43:07 +02:00
|
|
|
/**
|
|
|
|
* Randomizes question instances
|
|
|
|
*/
|
2016-10-07 15:15:42 +02:00
|
|
|
var randomizeQuestions = function () {
|
|
|
|
|
2016-11-14 11:31:15 +01:00
|
|
|
var result = randomizeQuestionOrdering(questionInstances);
|
2016-10-19 08:50:04 +02:00
|
|
|
questionInstances = result.questions;
|
|
|
|
questionOrder = result.questionOrder;
|
2016-10-07 15:15:42 +02:00
|
|
|
|
2016-11-14 10:05:22 +01:00
|
|
|
replaceQuestionsInDOM(questionInstances);
|
|
|
|
};
|
|
|
|
|
2016-11-14 15:22:43 +01:00
|
|
|
/**
|
|
|
|
* Empty the DOM of all questions, attach new questions and update buttons
|
|
|
|
*
|
|
|
|
* @param {type} questionInstances Array of questions to be attached to the DOM
|
|
|
|
*/
|
2016-11-14 10:05:22 +01:00
|
|
|
var replaceQuestionsInDOM = function (questionInstances) {
|
|
|
|
|
2016-10-07 15:15:42 +02:00
|
|
|
// Find all question containers and detach questions from them
|
2017-07-13 15:51:24 +02:00
|
|
|
$('.question-container', $myDom).each(function () {
|
2016-10-07 15:15:42 +02:00
|
|
|
$(this).children().detach();
|
|
|
|
});
|
|
|
|
|
|
|
|
// Reattach questions and their buttons in the new order
|
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
2016-10-17 10:43:07 +02:00
|
|
|
|
2016-10-07 15:15:42 +02:00
|
|
|
var question = questionInstances[i];
|
|
|
|
|
2016-10-18 15:06:44 +02:00
|
|
|
// Make sure styles are not being added twice
|
2016-10-19 08:50:04 +02:00
|
|
|
$('.question-container:eq(' + i + ')', $myDom).attr('class', 'question-container');
|
2016-10-18 15:06:44 +02:00
|
|
|
|
2016-10-07 15:15:42 +02:00
|
|
|
question.attach($('.question-container:eq(' + i + ')', $myDom));
|
|
|
|
|
2016-10-17 10:43:07 +02:00
|
|
|
//Show buttons if necessary
|
2017-07-13 15:51:24 +02:00
|
|
|
if (questionInstances[questionInstances.length -1] === question &&
|
|
|
|
question.hasButton('finish')) {
|
2016-11-14 10:05:22 +01:00
|
|
|
question.showButton('finish');
|
2016-10-07 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 15:51:24 +02:00
|
|
|
if (questionInstances[questionInstances.length -1] !== question &&
|
|
|
|
question.hasButton('next')) {
|
2016-11-14 10:05:22 +01:00
|
|
|
question.showButton('next');
|
2016-10-07 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
2017-07-13 15:51:24 +02:00
|
|
|
if (questionInstances[0] !== question &&
|
|
|
|
question.hasButton('prev') &&
|
|
|
|
!params.disableBackwardsNavigation) {
|
2016-11-14 10:05:22 +01:00
|
|
|
question.showButton('prev');
|
2016-10-07 15:15:42 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
// Hide relevant buttons since the order has changed
|
|
|
|
if (questionInstances[0] === question) {
|
|
|
|
question.hideButton('prev');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (questionInstances[questionInstances.length-1] === question) {
|
|
|
|
question.hideButton('next');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (questionInstances[questionInstances.length-1] !== question) {
|
|
|
|
question.hideButton('finish');
|
|
|
|
}
|
|
|
|
}
|
2016-11-14 10:05:22 +01:00
|
|
|
};
|
2016-10-07 15:15:42 +02:00
|
|
|
|
2016-03-17 14:09:13 +01:00
|
|
|
var moveQuestion = function (direction) {
|
2016-10-03 13:06:01 +02:00
|
|
|
if (params.disableBackwardsNavigation && !questionInstances[currentQuestion].getAnswerGiven()) {
|
|
|
|
questionInstances[currentQuestion].hideButton('next');
|
|
|
|
questionInstances[currentQuestion].hideButton('finish');
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-03-17 14:09:13 +01:00
|
|
|
_stopQuestion(currentQuestion);
|
|
|
|
if (currentQuestion + direction >= questionInstances.length) {
|
|
|
|
_displayEndGame();
|
|
|
|
}
|
2016-10-03 13:06:01 +02:00
|
|
|
else {
|
2016-09-26 11:45:15 +02:00
|
|
|
// Allow movement if backward navigation enabled or answer given
|
2016-03-17 14:09:13 +01:00
|
|
|
_showQuestion(currentQuestion + direction);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-06-28 15:07:05 +02:00
|
|
|
/**
|
|
|
|
* Toggle answered state of dot at given index
|
|
|
|
* @param {number} dotIndex Index of dot
|
|
|
|
* @param {boolean} isAnswered True if is answered, False if not answered
|
|
|
|
*/
|
2017-07-13 15:51:24 +02:00
|
|
|
var toggleAnsweredDot = function (dotIndex, isAnswered) {
|
2016-06-28 15:07:05 +02:00
|
|
|
var $el = $('.progress-dot:eq(' + dotIndex +')', $myDom);
|
|
|
|
|
|
|
|
// Skip current button
|
|
|
|
if ($el.hasClass('current')) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2016-07-04 13:05:38 +02:00
|
|
|
// Ensure boolean
|
|
|
|
isAnswered = !!isAnswered;
|
|
|
|
|
2016-06-30 09:47:24 +02:00
|
|
|
var label = params.texts.jumpToQuestion
|
|
|
|
.replace('%d', (dotIndex + 1).toString())
|
|
|
|
.replace('%total', $('.progress-dot', $myDom).length) +
|
2016-06-28 15:07:05 +02:00
|
|
|
', ' +
|
2016-06-30 09:47:24 +02:00
|
|
|
(isAnswered ? params.texts.answeredText : params.texts.unansweredText);
|
2016-06-28 15:07:05 +02:00
|
|
|
|
|
|
|
$el.toggleClass('unanswered', !isAnswered)
|
|
|
|
.toggleClass('answered', isAnswered)
|
|
|
|
.attr('aria-label', label);
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Toggle current state of dot at given index
|
|
|
|
* @param dotIndex
|
|
|
|
* @param isCurrent
|
|
|
|
*/
|
|
|
|
var toggleCurrentDot = function (dotIndex, isCurrent) {
|
|
|
|
var $el = $('.progress-dot:eq(' + dotIndex +')', $myDom);
|
|
|
|
var texts = params.texts;
|
2016-06-30 09:47:24 +02:00
|
|
|
var label = texts.jumpToQuestion
|
|
|
|
.replace('%d', (dotIndex + 1).toString())
|
|
|
|
.replace('%total', $('.progress-dot', $myDom).length);
|
2016-06-28 15:07:05 +02:00
|
|
|
|
|
|
|
if (!isCurrent) {
|
|
|
|
var isAnswered = $el.hasClass('answered');
|
2016-07-04 11:29:28 +02:00
|
|
|
label += ', ' + (isAnswered ? texts.answeredText : texts.unansweredText);
|
2016-06-30 09:47:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2016-07-04 11:29:28 +02:00
|
|
|
label += ', ' + texts.currentQuestionText;
|
2016-06-28 15:07:05 +02:00
|
|
|
}
|
|
|
|
|
2016-10-04 14:18:50 +02:00
|
|
|
var disabledTabindex = params.disableBackwardsNavigation && !showingSolutions;
|
2016-06-28 15:07:05 +02:00
|
|
|
$el.toggleClass('current', isCurrent)
|
2016-07-04 11:29:28 +02:00
|
|
|
.attr('aria-label', label)
|
2016-10-04 14:18:50 +02:00
|
|
|
.attr('tabindex', isCurrent && !disabledTabindex ? 0 : -1);
|
2016-06-28 15:07:05 +02:00
|
|
|
};
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
var _displayEndGame = function () {
|
2016-07-26 14:31:29 +02:00
|
|
|
$('.progress-dot.current', $myDom).removeClass('current');
|
2013-05-03 10:05:49 +02:00
|
|
|
if (rendered) {
|
|
|
|
$myDom.children().hide().filter('.questionset-results').show();
|
2015-07-08 11:01:20 +02:00
|
|
|
self.trigger('resize');
|
2013-05-03 10:05:49 +02:00
|
|
|
return;
|
|
|
|
}
|
2014-11-27 11:01:47 +01:00
|
|
|
//Remove old score screen.
|
|
|
|
$myDom.children().hide().filter('.questionset-results').remove();
|
2013-05-03 10:05:49 +02:00
|
|
|
rendered = true;
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
// Get total score.
|
2015-02-04 16:40:29 +01:00
|
|
|
var finals = self.getScore();
|
2016-10-10 11:21:06 +02:00
|
|
|
var totals = self.getMaxScore();
|
2017-07-03 15:09:49 +02:00
|
|
|
|
|
|
|
var scoreString = H5P.Question.determineOverallFeedback(params.endGame.overallFeedback, finals / totals).replace('@score', finals).replace('@total', totals);
|
2013-04-04 15:44:06 +02:00
|
|
|
var success = ((100 * finals / totals) >= params.passPercentage);
|
2016-04-08 15:36:06 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes our buttons behave like other buttons.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {string} classSelector
|
|
|
|
* @param {function} handler
|
|
|
|
*/
|
|
|
|
var hookUpButton = function (classSelector, handler) {
|
|
|
|
$(classSelector, $myDom).click(handler).keypress(function (e) {
|
|
|
|
if (e.which === 32) {
|
|
|
|
handler();
|
|
|
|
e.preventDefault();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
var displayResults = function () {
|
2016-10-10 11:21:06 +02:00
|
|
|
self.triggerXAPICompleted(self.getScore(), self.getMaxScore(), success);
|
2013-11-07 11:43:52 +01:00
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
var eparams = {
|
2016-05-20 09:33:45 +02:00
|
|
|
message: params.endGame.showResultPage ? params.endGame.message : params.endGame.noResultMessage,
|
2017-07-13 15:51:24 +02:00
|
|
|
comment: params.endGame.showResultPage ? (success ? params.endGame.oldFeedback.successGreeting : params.endGame.oldFeedback.failGreeting) : undefined,
|
|
|
|
resulttext: params.endGame.showResultPage ? (success ? params.endGame.oldFeedback.successComment : params.endGame.oldFeedback.failComment) : undefined,
|
2013-05-03 10:05:49 +02:00
|
|
|
finishButtonText: params.endGame.finishButtonText,
|
2016-04-08 15:36:06 +02:00
|
|
|
solutionButtonText: params.endGame.solutionButtonText,
|
|
|
|
retryButtonText: params.endGame.retryButtonText
|
2013-04-04 15:44:06 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
// Show result page.
|
|
|
|
$myDom.children().hide();
|
|
|
|
$myDom.append(endTemplate.render(eparams));
|
2016-04-08 15:36:06 +02:00
|
|
|
|
2016-05-25 09:51:23 +02:00
|
|
|
if (params.endGame.showResultPage) {
|
|
|
|
hookUpButton('.qs-solutionbutton', function () {
|
|
|
|
showSolutions();
|
|
|
|
$myDom.children().hide().filter('.questionset').show();
|
2016-04-15 09:49:50 +02:00
|
|
|
_showQuestion(params.initialQuestion);
|
2016-05-25 09:51:23 +02:00
|
|
|
});
|
|
|
|
hookUpButton('.qs-retrybutton', function () {
|
|
|
|
resetTask();
|
|
|
|
$myDom.children().hide();
|
|
|
|
|
|
|
|
var $intro = $('.intro-page', $myDom);
|
|
|
|
if ($intro.length) {
|
|
|
|
// Show intro
|
|
|
|
$('.intro-page', $myDom).show();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
// Show first question
|
|
|
|
$('.questionset', $myDom).show();
|
|
|
|
_showQuestion(params.initialQuestion);
|
|
|
|
}
|
|
|
|
});
|
2015-08-18 13:58:33 +02:00
|
|
|
|
2016-05-20 09:33:45 +02:00
|
|
|
if (scoreBar === undefined) {
|
|
|
|
scoreBar = H5P.JoubelUI.createScoreBar(totals);
|
|
|
|
}
|
|
|
|
scoreBar.appendTo($('.feedback-scorebar', $myDom));
|
|
|
|
$('.feedback-text', $myDom).html(scoreString);
|
2016-07-05 09:50:41 +02:00
|
|
|
|
|
|
|
// Announce that the question set is complete
|
|
|
|
setTimeout(function () {
|
|
|
|
$('.qs-progress-announcer', $myDom)
|
|
|
|
.html(eparams.message + '.' +
|
|
|
|
scoreString + '.' +
|
|
|
|
eparams.comment + '.' +
|
|
|
|
eparams.resulttext)
|
|
|
|
.show().focus();
|
2017-08-04 12:03:30 +02:00
|
|
|
scoreBar.setScore(finals);
|
2016-07-05 09:50:41 +02:00
|
|
|
}, 0);
|
2015-08-18 13:58:33 +02:00
|
|
|
}
|
2016-05-25 09:51:23 +02:00
|
|
|
else {
|
|
|
|
// Remove buttons and feedback section
|
|
|
|
$('.qs-finishbutton, .qs-solutionbutton, .qs-retrybutton, .feedback-section', $myDom).remove();
|
|
|
|
}
|
2016-05-09 15:30:22 +02:00
|
|
|
|
|
|
|
self.trigger('resize');
|
2013-04-04 15:44:06 +02:00
|
|
|
};
|
|
|
|
|
2013-05-02 14:41:39 +02:00
|
|
|
if (params.endGame.showAnimations) {
|
|
|
|
var videoData = success ? params.endGame.successVideo : params.endGame.failVideo;
|
2013-04-04 15:44:06 +02:00
|
|
|
if (videoData) {
|
2013-05-03 15:24:17 +02:00
|
|
|
$myDom.children().hide();
|
2013-04-26 17:27:35 +02:00
|
|
|
var $videoContainer = $('<div class="video-container"></div>').appendTo($myDom);
|
|
|
|
|
|
|
|
var video = new H5P.Video({
|
2015-02-17 11:14:49 +01:00
|
|
|
sources: videoData,
|
2013-04-26 17:27:35 +02:00
|
|
|
fitToWrapper: true,
|
|
|
|
controls: false,
|
2013-07-19 10:24:13 +02:00
|
|
|
autoplay: false
|
2013-06-27 14:13:00 +02:00
|
|
|
}, contentId);
|
2015-02-17 11:14:49 +01:00
|
|
|
video.on('stateChange', function (event) {
|
|
|
|
if (event.data === H5P.Video.ENDED) {
|
|
|
|
displayResults();
|
|
|
|
$videoContainer.hide();
|
|
|
|
}
|
|
|
|
});
|
2013-04-26 17:27:35 +02:00
|
|
|
video.attach($videoContainer);
|
2015-07-08 11:01:20 +02:00
|
|
|
// Resize on video loaded
|
|
|
|
video.on('loaded', function () {
|
|
|
|
self.trigger('resize');
|
|
|
|
});
|
2013-07-19 10:24:13 +02:00
|
|
|
video.play();
|
2013-04-26 17:27:35 +02:00
|
|
|
|
2016-09-28 11:10:32 +02:00
|
|
|
if (params.endGame.skippable) {
|
2015-08-12 14:46:49 +02:00
|
|
|
$('<a class="h5p-joubelui-button h5p-button skip">' + params.endGame.skipButtonText + '</a>').click(function () {
|
2015-02-17 11:14:49 +01:00
|
|
|
video.pause();
|
2013-04-26 17:27:35 +02:00
|
|
|
$videoContainer.hide();
|
|
|
|
displayResults();
|
|
|
|
}).appendTo($videoContainer);
|
|
|
|
}
|
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Trigger finished event.
|
|
|
|
displayResults();
|
2015-02-18 18:08:57 +01:00
|
|
|
self.trigger('resize');
|
2013-04-04 15:44:06 +02:00
|
|
|
};
|
|
|
|
|
2016-11-14 10:05:22 +01:00
|
|
|
var registerImageLoadedListener = function (question) {
|
|
|
|
H5P.on(question, 'imageLoaded', function () {
|
|
|
|
self.trigger('resize');
|
|
|
|
});
|
|
|
|
};
|
2015-09-24 13:16:54 +02:00
|
|
|
|
2016-11-14 15:22:43 +01:00
|
|
|
/**
|
|
|
|
* Initialize a question and attach it to the DOM
|
|
|
|
*
|
|
|
|
*/
|
2016-11-14 10:05:22 +01:00
|
|
|
function initializeQuestion() {
|
2013-04-04 15:44:06 +02:00
|
|
|
// Attach questions
|
2013-04-26 17:27:35 +02:00
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
2013-04-04 15:44:06 +02:00
|
|
|
var question = questionInstances[i];
|
2013-05-06 16:58:24 +02:00
|
|
|
|
2016-11-14 15:53:27 +01:00
|
|
|
// Make sure styles are not being added twice
|
|
|
|
$('.question-container:eq(' + i + ')', $myDom).attr('class', 'question-container');
|
|
|
|
|
2013-05-06 16:58:24 +02:00
|
|
|
question.attach($('.question-container:eq(' + i + ')', $myDom));
|
2015-08-12 14:46:49 +02:00
|
|
|
|
2015-09-24 13:16:54 +02:00
|
|
|
// Listen for image resize
|
|
|
|
registerImageLoadedListener(question);
|
|
|
|
|
2016-10-17 10:43:07 +02:00
|
|
|
// Add finish button
|
|
|
|
question.addButton('finish', params.texts.finishButton,
|
|
|
|
moveQuestion.bind(this, 1), false);
|
2015-08-12 14:46:49 +02:00
|
|
|
|
2016-10-17 10:43:07 +02:00
|
|
|
// Add next button
|
|
|
|
question.addButton('next', '', moveQuestion.bind(this, 1),
|
|
|
|
!params.disableBackwardsNavigation || !!question.getAnswerGiven(), {
|
2016-04-08 12:40:28 +02:00
|
|
|
href: '#', // Use href since this is a navigation button
|
2016-04-08 16:06:36 +02:00
|
|
|
'aria-label': params.texts.nextButton
|
2015-08-12 14:46:49 +02:00
|
|
|
});
|
|
|
|
|
2016-10-17 10:43:07 +02:00
|
|
|
// Add previous button
|
2016-10-03 13:06:01 +02:00
|
|
|
question.addButton('prev', '', moveQuestion.bind(this, -1),
|
|
|
|
!(questionInstances[0] === question || params.disableBackwardsNavigation), {
|
2016-04-08 12:40:28 +02:00
|
|
|
href: '#', // Use href since this is a navigation button
|
2016-04-08 16:06:36 +02:00
|
|
|
'aria-label': params.texts.prevButton
|
2015-08-12 14:46:49 +02:00
|
|
|
});
|
|
|
|
|
2016-10-17 10:43:07 +02:00
|
|
|
// Hide next button if it is the last question
|
2017-07-13 15:51:24 +02:00
|
|
|
if (questionInstances[questionInstances.length -1] === question) {
|
2016-10-17 10:43:07 +02:00
|
|
|
question.hideButton('next');
|
2015-08-12 14:46:49 +02:00
|
|
|
}
|
|
|
|
|
2015-02-04 16:40:29 +01:00
|
|
|
question.on('xAPI', function (event) {
|
2015-07-10 13:41:16 +02:00
|
|
|
var shortVerb = event.getVerb();
|
2015-08-13 10:35:55 +02:00
|
|
|
if (shortVerb === 'interacted' ||
|
2016-11-14 10:05:22 +01:00
|
|
|
shortVerb === 'answered' ||
|
|
|
|
shortVerb === 'attempted') {
|
2016-06-28 15:07:05 +02:00
|
|
|
toggleAnsweredDot(currentQuestion,
|
|
|
|
questionInstances[currentQuestion].getAnswerGiven());
|
2014-10-13 21:51:36 +02:00
|
|
|
_updateButtons();
|
|
|
|
}
|
2015-07-10 13:41:16 +02:00
|
|
|
if (shortVerb === 'completed') {
|
|
|
|
// An activity within this activity is not allowed to send completed events
|
|
|
|
event.setVerb('answered');
|
|
|
|
}
|
2015-11-28 21:00:16 +01:00
|
|
|
if (event.data.statement.context.extensions === undefined) {
|
2016-06-16 10:15:06 +02:00
|
|
|
event.data.statement.context.extensions = {};
|
2015-11-28 21:00:16 +01:00
|
|
|
}
|
|
|
|
event.data.statement.context.extensions['http://id.tincanapi.com/extension/ending-point'] = currentQuestion + 1;
|
2013-04-04 15:44:06 +02:00
|
|
|
});
|
2016-09-26 15:19:53 +02:00
|
|
|
|
|
|
|
// Mark question if answered
|
|
|
|
toggleAnsweredDot(i, question.getAnswerGiven());
|
2013-04-04 15:44:06 +02:00
|
|
|
}
|
2016-11-14 10:05:22 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
this.attach = function (target) {
|
|
|
|
if (this.isRoot()) {
|
|
|
|
this.setActivityStarted();
|
|
|
|
}
|
|
|
|
if (typeof(target) === "string") {
|
|
|
|
$myDom = $('#' + target);
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
$myDom = $(target);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Render own DOM into target.
|
|
|
|
$myDom.children().remove();
|
|
|
|
$myDom.append($template);
|
|
|
|
if (params.backgroundImage !== undefined) {
|
|
|
|
$myDom.css({
|
|
|
|
overflow: 'hidden',
|
|
|
|
background: '#fff url("' + H5P.getPath(params.backgroundImage.path, contentId) + '") no-repeat 50% 50%',
|
|
|
|
backgroundSize: '100% auto'
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.introPage.backgroundImage !== undefined) {
|
|
|
|
var $intro = $myDom.find('.intro-page');
|
|
|
|
if ($intro.length) {
|
|
|
|
var bgImg = params.introPage.backgroundImage;
|
|
|
|
var bgImgRatio = (bgImg.height / bgImg.width);
|
|
|
|
$intro.css({
|
|
|
|
background: '#fff url("' + H5P.getPath(bgImg.path, contentId) + '") no-repeat 50% 50%',
|
|
|
|
backgroundSize: 'auto 100%',
|
|
|
|
minHeight: bgImgRatio * +window.getComputedStyle($intro[0]).width.replace('px','')
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
initializeQuestion();
|
2013-05-06 14:54:24 +02:00
|
|
|
|
2013-05-06 01:47:53 +02:00
|
|
|
// Allow other libraries to add transitions after the questions have been inited
|
|
|
|
$('.questionset', $myDom).addClass('started');
|
2013-04-04 15:44:06 +02:00
|
|
|
|
2013-05-03 10:05:49 +02:00
|
|
|
$('.qs-startbutton', $myDom).click(function () {
|
2013-04-04 15:44:06 +02:00
|
|
|
$(this).parents('.intro-page').hide();
|
2016-04-15 09:49:50 +02:00
|
|
|
$('.questionset', $myDom).show();
|
|
|
|
_showQuestion(params.initialQuestion);
|
2013-04-04 15:44:06 +02:00
|
|
|
});
|
|
|
|
|
2016-07-04 11:29:28 +02:00
|
|
|
/**
|
|
|
|
* Triggers changing the current question.
|
|
|
|
*
|
|
|
|
* @private
|
|
|
|
* @param {Object} [event]
|
|
|
|
*/
|
|
|
|
var handleProgressDotClick = function (event) {
|
2016-10-03 13:06:01 +02:00
|
|
|
// Disable dots when backward nav disabled
|
|
|
|
event.preventDefault();
|
|
|
|
if (params.disableBackwardsNavigation && !showingSolutions) {
|
|
|
|
return;
|
|
|
|
}
|
2015-11-18 09:38:44 +01:00
|
|
|
_stopQuestion(currentQuestion);
|
2016-07-04 11:29:28 +02:00
|
|
|
_showQuestion($(this).parent().index());
|
|
|
|
};
|
|
|
|
|
|
|
|
// Set event listeners.
|
|
|
|
$('.progress-dot', $myDom).click(handleProgressDotClick).keydown(function (event) {
|
|
|
|
var $this = $(this);
|
|
|
|
switch (event.which) {
|
|
|
|
case 13: // Enter
|
|
|
|
case 32: // Space
|
|
|
|
handleProgressDotClick.call(this, event);
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 37: // Left Arrow
|
|
|
|
case 38: // Up Arrow
|
|
|
|
// Go to previous dot
|
|
|
|
var $prev = $this.parent().prev();
|
|
|
|
if ($prev.length) {
|
|
|
|
$prev.children('a').attr('tabindex', '0').focus();
|
|
|
|
$this.attr('tabindex', '-1');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case 39: // Right Arrow
|
|
|
|
case 40: // Down Arrow
|
|
|
|
// Go to next dot
|
|
|
|
var $next = $this.parent().next();
|
|
|
|
if ($next.length) {
|
|
|
|
$next.children('a').attr('tabindex', '0').focus();
|
|
|
|
$this.attr('tabindex', '-1');
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2013-04-04 15:44:06 +02:00
|
|
|
});
|
|
|
|
|
2016-07-04 11:29:28 +02:00
|
|
|
|
|
|
|
|
2016-09-26 15:19:53 +02:00
|
|
|
// Hide all but current question
|
|
|
|
_showQuestion(currentQuestion, true);
|
2013-05-03 10:05:49 +02:00
|
|
|
|
|
|
|
if (renderSolutions) {
|
|
|
|
showSolutions();
|
|
|
|
}
|
2016-09-26 15:19:53 +02:00
|
|
|
// Update buttons in case they have changed (restored user state)
|
|
|
|
_updateButtons();
|
2015-06-19 15:40:35 +02:00
|
|
|
|
2014-10-26 22:14:26 +01:00
|
|
|
this.trigger('resize');
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2013-04-04 15:44:06 +02:00
|
|
|
return this;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get current score for questionset.
|
2015-02-04 16:40:29 +01:00
|
|
|
this.getScore = function () {
|
2013-04-04 15:44:06 +02:00
|
|
|
var score = 0;
|
|
|
|
for (var i = questionInstances.length - 1; i >= 0; i--) {
|
|
|
|
score += questionInstances[i].getScore();
|
|
|
|
}
|
|
|
|
return score;
|
|
|
|
};
|
|
|
|
|
|
|
|
// Get total score possible for questionset.
|
2016-10-10 11:21:06 +02:00
|
|
|
this.getMaxScore = function () {
|
2013-04-04 15:44:06 +02:00
|
|
|
var score = 0;
|
|
|
|
for (var i = questionInstances.length - 1; i >= 0; i--) {
|
2013-04-26 17:27:35 +02:00
|
|
|
score += questionInstances[i].getMaxScore();
|
2013-04-04 15:44:06 +02:00
|
|
|
}
|
|
|
|
return score;
|
|
|
|
};
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2016-10-10 11:21:06 +02:00
|
|
|
/**
|
|
|
|
* @deprecated since version 1.9.2
|
|
|
|
* @returns {number}
|
|
|
|
*/
|
|
|
|
this.totalScore = function () {
|
|
|
|
return this.getMaxScore();
|
|
|
|
};
|
|
|
|
|
2014-03-21 09:37:39 +01:00
|
|
|
/**
|
|
|
|
* Gather copyright information for the current content.
|
|
|
|
*
|
|
|
|
* @returns {H5P.ContentCopyrights}
|
|
|
|
*/
|
2015-02-04 16:40:29 +01:00
|
|
|
this.getCopyrights = function () {
|
2014-03-21 09:37:39 +01:00
|
|
|
var info = new H5P.ContentCopyrights();
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2014-03-21 09:37:39 +01:00
|
|
|
// Background
|
2014-04-02 00:10:30 +02:00
|
|
|
if (params.backgroundImage !== undefined && params.backgroundImage.copyright !== undefined) {
|
2014-03-21 09:37:39 +01:00
|
|
|
var background = new H5P.MediaCopyright(params.backgroundImage.copyright);
|
|
|
|
background.setThumbnail(new H5P.Thumbnail(H5P.getPath(params.backgroundImage.path, contentId), params.backgroundImage.width, params.backgroundImage.height));
|
|
|
|
info.addMedia(background);
|
|
|
|
}
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2014-03-21 09:37:39 +01:00
|
|
|
// Questions
|
2015-06-19 15:40:35 +02:00
|
|
|
var questionCopyrights;
|
2014-03-21 09:37:39 +01:00
|
|
|
for (var i = 0; i < questionInstances.length; i++) {
|
2015-06-19 15:40:35 +02:00
|
|
|
var instance = questionInstances[i];
|
|
|
|
var qParams = params.questions[i].params;
|
|
|
|
questionCopyrights = undefined;
|
|
|
|
|
|
|
|
if (instance.getCopyrights !== undefined) {
|
|
|
|
// Use the instance's own copyright generator
|
|
|
|
questionCopyrights = instance.getCopyrights();
|
|
|
|
}
|
|
|
|
if (questionCopyrights === undefined) {
|
|
|
|
// Create a generic flat copyright list
|
|
|
|
questionCopyrights = new H5P.ContentCopyrights();
|
|
|
|
H5P.findCopyrights(questionCopyrights, qParams, contentId);
|
2014-03-21 09:37:39 +01:00
|
|
|
}
|
2015-06-19 15:40:35 +02:00
|
|
|
|
|
|
|
// Determine label
|
2016-03-17 14:09:13 +01:00
|
|
|
var label = (params.texts.questionLabel + ' ' + (i + 1));
|
2015-06-19 15:40:35 +02:00
|
|
|
if (qParams.contentName !== undefined) {
|
|
|
|
label += ': ' + qParams.contentName;
|
|
|
|
}
|
|
|
|
else if (instance.getTitle !== undefined) {
|
|
|
|
label += ': ' + instance.getTitle();
|
|
|
|
}
|
|
|
|
questionCopyrights.setLabel(label);
|
|
|
|
|
|
|
|
// Add info
|
|
|
|
info.addContent(questionCopyrights);
|
2014-03-21 09:37:39 +01:00
|
|
|
}
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2014-03-21 09:37:39 +01:00
|
|
|
// Success video
|
2015-06-19 15:40:35 +02:00
|
|
|
var video;
|
2014-04-02 00:10:30 +02:00
|
|
|
if (params.endGame.successVideo !== undefined && params.endGame.successVideo.length > 0) {
|
2015-06-19 15:40:35 +02:00
|
|
|
video = params.endGame.successVideo[0];
|
2014-04-02 00:10:30 +02:00
|
|
|
if (video.copyright !== undefined) {
|
|
|
|
info.addMedia(new H5P.MediaCopyright(video.copyright));
|
|
|
|
}
|
2014-03-21 09:37:39 +01:00
|
|
|
}
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2014-03-21 09:37:39 +01:00
|
|
|
// Fail video
|
2014-04-02 00:10:30 +02:00
|
|
|
if (params.endGame.failVideo !== undefined && params.endGame.failVideo.length > 0) {
|
|
|
|
video = params.endGame.failVideo[0];
|
|
|
|
if (video.copyright !== undefined) {
|
|
|
|
info.addMedia(new H5P.MediaCopyright(video.copyright));
|
|
|
|
}
|
2014-03-21 09:37:39 +01:00
|
|
|
}
|
2014-11-14 15:06:07 +01:00
|
|
|
|
2014-03-21 09:37:39 +01:00
|
|
|
return info;
|
2014-06-26 16:23:12 +02:00
|
|
|
};
|
2017-07-13 15:51:24 +02:00
|
|
|
this.getQuestions = function () {
|
2015-02-04 16:40:29 +01:00
|
|
|
return questionInstances;
|
2013-04-04 15:44:06 +02:00
|
|
|
};
|
2017-07-13 15:51:24 +02:00
|
|
|
this.showSolutions = function () {
|
2015-02-04 16:40:29 +01:00
|
|
|
renderSolutions = true;
|
2015-06-19 15:40:35 +02:00
|
|
|
};
|
2015-11-18 09:38:44 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Stop the given element's playback if any.
|
|
|
|
*
|
|
|
|
* @param {object} instance
|
|
|
|
*/
|
|
|
|
var pauseMedia = function (instance) {
|
|
|
|
try {
|
|
|
|
if (instance.pause !== undefined &&
|
|
|
|
(instance.pause instanceof Function ||
|
|
|
|
typeof instance.pause === 'function')) {
|
|
|
|
instance.pause();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
// Prevent crashing, log error.
|
|
|
|
H5P.error(err);
|
|
|
|
}
|
|
|
|
};
|
2016-09-26 15:19:53 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns the complete state of question set and sub-content
|
|
|
|
*
|
2016-10-07 13:38:39 +02:00
|
|
|
* @returns {Object} current state
|
2016-09-26 15:19:53 +02:00
|
|
|
*/
|
|
|
|
this.getCurrentState = function () {
|
2016-10-07 13:38:39 +02:00
|
|
|
return {
|
|
|
|
progress: showingSolutions ? questionInstances.length - 1 : currentQuestion,
|
2016-09-26 15:19:53 +02:00
|
|
|
answers: questionInstances.map(function (qi) {
|
|
|
|
return qi.getCurrentState();
|
2016-10-07 15:15:42 +02:00
|
|
|
}),
|
2016-10-20 13:36:40 +02:00
|
|
|
order: questionOrder,
|
|
|
|
poolOrder: poolOrder
|
2016-09-26 15:19:53 +02:00
|
|
|
};
|
|
|
|
};
|
2016-11-23 10:19:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Generate xAPI object definition used in xAPI statements.
|
|
|
|
* @return {Object}
|
|
|
|
*/
|
|
|
|
var getxAPIDefinition = function () {
|
|
|
|
var definition = {};
|
|
|
|
|
|
|
|
definition.interactionType = 'compound';
|
|
|
|
definition.type = 'http://adlnet.gov/expapi/activities/cmi.interaction';
|
|
|
|
definition.description = {
|
2016-11-24 17:29:47 +01:00
|
|
|
'en-US': ''
|
2016-11-23 10:19:32 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
return definition;
|
|
|
|
};
|
2016-09-26 15:19:53 +02:00
|
|
|
|
2016-11-23 10:19:32 +01:00
|
|
|
/**
|
|
|
|
* Add the question itself to the definition part of an xAPIEvent
|
|
|
|
*/
|
2017-07-13 15:51:24 +02:00
|
|
|
var addQuestionToXAPI = function (xAPIEvent) {
|
2016-11-23 10:19:32 +01:00
|
|
|
var definition = xAPIEvent.getVerifiedStatementValue(['object', 'definition']);
|
|
|
|
$.extend(definition, getxAPIDefinition());
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get xAPI data from sub content types
|
|
|
|
*
|
|
|
|
* @param {Object} metaContentType
|
2016-11-24 17:29:47 +01:00
|
|
|
* @returns {array}
|
2016-11-23 10:19:32 +01:00
|
|
|
*/
|
2017-07-13 15:51:24 +02:00
|
|
|
var getXAPIDataFromChildren = function (metaContentType) {
|
|
|
|
return metaContentType.getQuestions().map(function (question) {
|
2016-11-23 10:19:32 +01:00
|
|
|
return question.getXAPIData();
|
|
|
|
});
|
2016-11-24 17:29:47 +01:00
|
|
|
};
|
2016-11-23 10:19:32 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get xAPI data.
|
|
|
|
* Contract used by report rendering engine.
|
|
|
|
*
|
|
|
|
* @see contract at {@link https://h5p.org/documentation/developers/contracts#guides-header-6}
|
|
|
|
*/
|
2017-07-13 15:51:24 +02:00
|
|
|
this.getXAPIData = function () {
|
2016-11-23 10:19:32 +01:00
|
|
|
var xAPIEvent = this.createXAPIEventTemplate('answered');
|
2016-11-24 17:29:47 +01:00
|
|
|
addQuestionToXAPI(xAPIEvent);
|
|
|
|
xAPIEvent.setScoredResult(this.getScore(),
|
|
|
|
this.getMaxScore(),
|
|
|
|
this,
|
|
|
|
true,
|
|
|
|
this.getScore() === this.getMaxScore()
|
|
|
|
);
|
2016-11-23 10:19:32 +01:00
|
|
|
return {
|
|
|
|
statement: xAPIEvent.data.statement,
|
2016-11-24 17:29:47 +01:00
|
|
|
children: getXAPIDataFromChildren(this)
|
2017-07-13 15:51:24 +02:00
|
|
|
};
|
2016-09-26 15:19:53 +02:00
|
|
|
};
|
2014-02-24 16:26:07 +01:00
|
|
|
};
|
2015-11-18 10:00:44 +01:00
|
|
|
|
2015-02-04 16:40:29 +01:00
|
|
|
H5P.QuestionSet.prototype = Object.create(H5P.EventDispatcher.prototype);
|
2015-06-19 15:40:35 +02:00
|
|
|
H5P.QuestionSet.prototype.constructor = H5P.QuestionSet;
|