Merge branch 'master' of github.com:h5p/h5p-question-set
commit
747e9dcb1a
|
@ -8,11 +8,12 @@ var H5P = H5P || {};
|
||||||
*
|
*
|
||||||
* @param {Array} options
|
* @param {Array} options
|
||||||
* @param {int} contentId
|
* @param {int} contentId
|
||||||
|
* @param {Object} contentData
|
||||||
* @returns {H5P.QuestionSet} Instance
|
* @returns {H5P.QuestionSet} Instance
|
||||||
*/
|
*/
|
||||||
H5P.QuestionSet = function (options, contentId) {
|
H5P.QuestionSet = function (options, contentId, contentData) {
|
||||||
if (!(this instanceof H5P.QuestionSet)) {
|
if (!(this instanceof H5P.QuestionSet)) {
|
||||||
return new H5P.QuestionSet(options, contentId);
|
return new H5P.QuestionSet(options, contentId, contentData);
|
||||||
}
|
}
|
||||||
H5P.EventDispatcher.call(this);
|
H5P.EventDispatcher.call(this);
|
||||||
var $ = H5P.jQuery;
|
var $ = H5P.jQuery;
|
||||||
|
@ -38,7 +39,7 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
' <% } %>' +
|
' <% } %>' +
|
||||||
' <div class="qs-footer">' +
|
' <div class="qs-footer">' +
|
||||||
' <div class="qs-progress">' +
|
' <div class="qs-progress">' +
|
||||||
' <% if (progressType == "dots") { %>' +
|
' <% if (progressType == "dots" && !disableBackwardsNavigation) { %>' +
|
||||||
' <ul class="dots-container" role="navigation">' +
|
' <ul class="dots-container" role="navigation">' +
|
||||||
' <% for (var i=0; i<questions.length; i++) { %>' +
|
' <% for (var i=0; i<questions.length; i++) { %>' +
|
||||||
' <li class="progress-item"><a href="#" class="progress-dot unanswered" ' +
|
' <li class="progress-item"><a href="#" class="progress-dot unanswered" ' +
|
||||||
|
@ -113,7 +114,8 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
retryButtonText: 'Retry',
|
retryButtonText: 'Retry',
|
||||||
showAnimations: false,
|
showAnimations: false,
|
||||||
skipButtonText: 'Skip video'
|
skipButtonText: 'Skip video'
|
||||||
}
|
},
|
||||||
|
disableBackwardsNavigation: false
|
||||||
};
|
};
|
||||||
|
|
||||||
var template = new EJS({text: texttemplate});
|
var template = new EJS({text: texttemplate});
|
||||||
|
@ -125,7 +127,11 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
var $myDom;
|
var $myDom;
|
||||||
var scoreBar;
|
var scoreBar;
|
||||||
var up;
|
var up;
|
||||||
renderSolutions = false;
|
var renderSolutions = false;
|
||||||
|
contentData = contentData || {};
|
||||||
|
if (contentData.previousState) {
|
||||||
|
currentQuestion = contentData.previousState.progress;
|
||||||
|
}
|
||||||
|
|
||||||
var $template = $(template.render(params));
|
var $template = $(template.render(params));
|
||||||
// Set overrides for questions
|
// Set overrides for questions
|
||||||
|
@ -158,8 +164,11 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
question.params.overrideSettings = question.params.overrideSettings || {};
|
question.params.overrideSettings = question.params.overrideSettings || {};
|
||||||
question.params.overrideSettings.$confirmationDialogParent = $template.last();
|
question.params.overrideSettings.$confirmationDialogParent = $template.last();
|
||||||
question.params.overrideSettings.instance = this;
|
question.params.overrideSettings.instance = this;
|
||||||
|
var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined,
|
||||||
var questionInstance = H5P.newRunnable(question, contentId, undefined, undefined, {parent: self});
|
{
|
||||||
|
previousState: contentData.previousState ? contentData.previousState.answers[i] : undefined,
|
||||||
|
parent: self
|
||||||
|
});
|
||||||
questionInstance.on('resize', function () {
|
questionInstance.on('resize', function () {
|
||||||
up = true;
|
up = true;
|
||||||
self.trigger('resize');
|
self.trigger('resize');
|
||||||
|
@ -325,9 +334,13 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
_displayEndGame();
|
_displayEndGame();
|
||||||
|
|
||||||
}
|
}
|
||||||
else {
|
else if (!params.disableBackwardsNavigation || questionInstances[currentQuestion].getAnswerGiven()) {
|
||||||
|
// Allow movement if backward navigation enabled or answer given
|
||||||
_showQuestion(currentQuestion + direction);
|
_showQuestion(currentQuestion + direction);
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
//TODO: Give an error message ? or disable/grey out previous button when not allowed
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -511,7 +524,7 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
});
|
});
|
||||||
video.play();
|
video.play();
|
||||||
|
|
||||||
if (params.endGame.skipButtonText) {
|
if (params.endGame.skippable) {
|
||||||
$('<a class="h5p-joubelui-button h5p-button skip">' + params.endGame.skipButtonText + '</a>').click(function () {
|
$('<a class="h5p-joubelui-button h5p-button skip">' + params.endGame.skipButtonText + '</a>').click(function () {
|
||||||
video.pause();
|
video.pause();
|
||||||
$videoContainer.hide();
|
$videoContainer.hide();
|
||||||
|
@ -594,7 +607,7 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Add previous question button
|
// Add previous question button
|
||||||
if (questionInstances[0] !== question) {
|
if (questionInstances[0] !== question && !params.disableBackwardsNavigation) {
|
||||||
question.addButton('prev', '', moveQuestion.bind(this, -1), true, {
|
question.addButton('prev', '', moveQuestion.bind(this, -1), true, {
|
||||||
href: '#', // Use href since this is a navigation button
|
href: '#', // Use href since this is a navigation button
|
||||||
'aria-label': params.texts.prevButton
|
'aria-label': params.texts.prevButton
|
||||||
|
@ -619,6 +632,9 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
}
|
}
|
||||||
event.data.statement.context.extensions['http://id.tincanapi.com/extension/ending-point'] = currentQuestion + 1;
|
event.data.statement.context.extensions['http://id.tincanapi.com/extension/ending-point'] = currentQuestion + 1;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Mark question if answered
|
||||||
|
toggleAnsweredDot(i, question.getAnswerGiven());
|
||||||
}
|
}
|
||||||
|
|
||||||
// Allow other libraries to add transitions after the questions have been inited
|
// Allow other libraries to add transitions after the questions have been inited
|
||||||
|
@ -675,12 +691,14 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Hide all but initial Question.
|
// Hide all but current question
|
||||||
_showQuestion(params.initialQuestion, true);
|
_showQuestion(currentQuestion, true);
|
||||||
|
|
||||||
if (renderSolutions) {
|
if (renderSolutions) {
|
||||||
showSolutions();
|
showSolutions();
|
||||||
}
|
}
|
||||||
|
// Update buttons in case they have changed (restored user state)
|
||||||
|
_updateButtons();
|
||||||
|
|
||||||
this.trigger('resize');
|
this.trigger('resize');
|
||||||
|
|
||||||
|
@ -795,6 +813,22 @@ H5P.QuestionSet = function (options, contentId) {
|
||||||
H5P.error(err);
|
H5P.error(err);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the complete state of question set and sub-content
|
||||||
|
*
|
||||||
|
* @returns {Object}
|
||||||
|
*/
|
||||||
|
this.getCurrentState = function () {
|
||||||
|
var state = {
|
||||||
|
progress: currentQuestion,
|
||||||
|
answers: questionInstances.map(function (qi) {
|
||||||
|
return qi.getCurrentState();
|
||||||
|
})
|
||||||
|
};
|
||||||
|
|
||||||
|
return state;
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
H5P.QuestionSet.prototype = Object.create(H5P.EventDispatcher.prototype);
|
H5P.QuestionSet.prototype = Object.create(H5P.EventDispatcher.prototype);
|
||||||
|
|
|
@ -103,6 +103,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Disable backwards navigation",
|
||||||
|
"description": "This option will only allow you to move forward in Question Set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "انتهاء المسابقة",
|
"label": "انتهاء المسابقة",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
|
@ -108,6 +108,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Disable backwards navigation",
|
||||||
|
"description": "This option will only allow you to move forward in Question Set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Quiz beendet",
|
"label": "Quiz beendet",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
|
@ -108,6 +108,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Disable backwards navigation",
|
||||||
|
"description": "This option will only allow you to move forward in Question Set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Quiz terminé",
|
"label": "Quiz terminé",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
|
@ -103,6 +103,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Disable backwards navigation",
|
||||||
|
"description": "This option will only allow you to move forward in Question Set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Quiz terminato",
|
"label": "Quiz terminato",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
|
@ -105,6 +105,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Slå av bakoverknapp",
|
||||||
|
"description": "Slå på for å nekte å gå tilbake i Question Set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Spørsmålssett avslutning",
|
"label": "Spørsmålssett avslutning",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
|
@ -105,6 +105,10 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"label": "Slå av bakoverknapp",
|
||||||
|
"description": "Slå på for å nekte å gå tilbake i Question Set"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"label": "Spørsmålssett avslutning",
|
"label": "Spørsmålssett avslutning",
|
||||||
"fields": [
|
"fields": [
|
||||||
|
|
|
@ -4,7 +4,7 @@
|
||||||
"contentType": "question",
|
"contentType": "question",
|
||||||
"majorVersion": 1,
|
"majorVersion": 1,
|
||||||
"minorVersion": 9,
|
"minorVersion": 9,
|
||||||
"patchVersion": 0,
|
"patchVersion": 1,
|
||||||
"embedTypes": [
|
"embedTypes": [
|
||||||
"iframe"
|
"iframe"
|
||||||
],
|
],
|
||||||
|
@ -41,7 +41,7 @@
|
||||||
{
|
{
|
||||||
"machineName": "H5P.Video",
|
"machineName": "H5P.Video",
|
||||||
"majorVersion": 1,
|
"majorVersion": 1,
|
||||||
"minorVersion": 2
|
"minorVersion": 3
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"machineName": "H5P.JoubelUI",
|
"machineName": "H5P.JoubelUI",
|
||||||
|
@ -53,7 +53,7 @@
|
||||||
{
|
{
|
||||||
"machineName": "H5PEditor.VerticalTabs",
|
"machineName": "H5PEditor.VerticalTabs",
|
||||||
"majorVersion": 1,
|
"majorVersion": 1,
|
||||||
"minorVersion": 1
|
"minorVersion": 2
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"machineName": "H5PEditor.QuestionSetTextualEditor",
|
"machineName": "H5PEditor.QuestionSetTextualEditor",
|
||||||
|
|
|
@ -110,9 +110,9 @@
|
||||||
"label": "Question type",
|
"label": "Question type",
|
||||||
"description": "Library for this question.",
|
"description": "Library for this question.",
|
||||||
"options": [
|
"options": [
|
||||||
"H5P.MultiChoice 1.7",
|
"H5P.MultiChoice 1.8",
|
||||||
"H5P.DragQuestion 1.7",
|
"H5P.DragQuestion 1.7",
|
||||||
"H5P.Blanks 1.6",
|
"H5P.Blanks 1.7",
|
||||||
"H5P.MarkTheWords 1.6",
|
"H5P.MarkTheWords 1.6",
|
||||||
"H5P.DragText 1.5"
|
"H5P.DragText 1.5"
|
||||||
]
|
]
|
||||||
|
@ -193,6 +193,14 @@
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "disableBackwardsNavigation",
|
||||||
|
"type": "boolean",
|
||||||
|
"label": "Disable backwards navigation",
|
||||||
|
"description": "This option will only allow you to move forward in Question Set",
|
||||||
|
"optional": true,
|
||||||
|
"default": false
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "endGame",
|
"name": "endGame",
|
||||||
"type": "group",
|
"type": "group",
|
||||||
|
|
Loading…
Reference in New Issue