Merge branch 'master' into randomize-questions

# Conflicts:
#	js/questionset.js
pull/4/head^2
thomasmars 2016-10-14 16:14:37 +02:00
commit 6d4a915de1
4 changed files with 60 additions and 18 deletions

3
.gitignore vendored
View File

@ -1,2 +1,3 @@
*~
/nbproject/private/
/nbproject/private/
.idea

View File

@ -52,7 +52,12 @@
background: #fff;
background: #cecece;
}
.progress-dot:hover {
.progress-dot.disabled {
cursor: default;
}
.progress-dot:not(.disabled):hover {
box-shadow: 0 0 0.5em #c7c7c7;
}
.progress-dot.answered {
@ -61,6 +66,11 @@
.progress-dot.current {
background: #285585;
}
.progress-dot.disabled:focus {
outline: none
}
.progress-dot:focus {
outline-color: rgb(40, 130, 211);
outline-width: thin;

View File

@ -42,11 +42,16 @@ H5P.QuestionSet = function (options, contentId, contentData) {
' <% if (progressType == "dots") { %>' +
' <ul class="dots-container" role="navigation">' +
' <% for (var i=0; i<questions.length; i++) { %>' +
' <li class="progress-item"><a href="#" class="progress-dot unanswered" ' +
' aria-label="<%=' +
' texts.jumpToQuestion.replace("%d", i + 1).replace("%total", questions.length)' +
' + ", " + texts.unansweredText' +
' %>" tabindex="-1"></a></li>' +
' <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>' +
' <% } %>' +
' </div>' +
' <% } else if (progressType == "textual") { %>' +
@ -131,7 +136,7 @@ H5P.QuestionSet = function (options, contentId, contentData) {
var showingSolutions = false;
contentData = contentData || {};
var answerIndex;
if (contentData.previousState) {
if (contentData.previousState && contentData.previousState.progress) {
currentQuestion = contentData.previousState.progress;
answerIndex = contentData.previousState.order;
}
@ -332,6 +337,7 @@ H5P.QuestionSet = function (options, contentId, contentData) {
for (var i = 0; i < questionInstances.length; i++) {
// Enable back and forth navigation in solution mode
toggleDotsNavigation(true);
if (i < questionInstances.length - 1) {
questionInstances[i].showButton('next');
}
@ -352,6 +358,20 @@ H5P.QuestionSet = function (options, contentId, contentData) {
}
};
/**
* Toggles whether dots are enabled for navigation
*/
var toggleDotsNavigation = function (enable) {
$('.progress-dot', $myDom).each(function () {
$(this).toggleClass('disabled', !enable);
$(this).attr('aria-disabled', enable ? 'false' : 'true');
// Remove tabindex
if (!enable) {
$(this).attr('tabindex', '-1');
}
});
};
/**
* Resets the task and every subcontent task.
* Used for contracts with integrated content.
@ -365,6 +385,8 @@ H5P.QuestionSet = function (options, contentId, contentData) {
// Hide back and forth navigation in normal mode
if (params.disableBackwardsNavigation) {
toggleDotsNavigation(false);
// Check if first question is answered by default
if (i === 0 && questionInstances[i].getAnswerGiven()) {
questionInstances[i].showButton('next');
@ -550,9 +572,10 @@ H5P.QuestionSet = function (options, contentId, contentData) {
label += ', ' + texts.currentQuestionText;
}
var disabledTabindex = params.disableBackwardsNavigation && !showingSolutions;
$el.toggleClass('current', isCurrent)
.attr('aria-label', label)
.attr('tabindex', isCurrent ? 0 : -1);
.attr('tabindex', isCurrent && !disabledTabindex ? 0 : -1);
};
var _displayEndGame = function () {
@ -568,7 +591,7 @@ H5P.QuestionSet = function (options, contentId, contentData) {
// Get total score.
var finals = self.getScore();
var totals = self.totalScore();
var totals = self.getMaxScore();
var scoreString = params.endGame.scoreString.replace("@score", finals).replace("@total", totals);
var success = ((100 * finals / totals) >= params.passPercentage);
var eventData = {
@ -593,7 +616,7 @@ H5P.QuestionSet = function (options, contentId, contentData) {
};
var displayResults = function () {
self.triggerXAPICompleted(self.getScore(), self.totalScore(), success);
self.triggerXAPICompleted(self.getScore(), self.getMaxScore(), success);
var eparams = {
message: params.endGame.showResultPage ? params.endGame.message : params.endGame.noResultMessage,
@ -878,7 +901,7 @@ H5P.QuestionSet = function (options, contentId, contentData) {
};
// Get total score possible for questionset.
this.totalScore = function () {
this.getMaxScore = function () {
var score = 0;
for (var i = questionInstances.length - 1; i >= 0; i--) {
score += questionInstances[i].getMaxScore();
@ -886,6 +909,15 @@ H5P.QuestionSet = function (options, contentId, contentData) {
return score;
};
/**
* @deprecated since version 1.9.2
* @returns {number}
*/
this.totalScore = function () {
return this.getMaxScore();
};
/**
* Gather copyright information for the current content.
*
@ -980,18 +1012,16 @@ H5P.QuestionSet = function (options, contentId, contentData) {
/**
* Returns the complete state of question set and sub-content
*
* @returns {Object}
* @returns {Object} current state
*/
this.getCurrentState = function () {
var state = {
progress: currentQuestion,
return {
progress: showingSolutions ? questionInstances.length - 1 : currentQuestion,
answers: questionInstances.map(function (qi) {
return qi.getCurrentState();
}),
order: idMap
};
return state;
};
};

View File

@ -114,7 +114,8 @@
"H5P.DragQuestion 1.7",
"H5P.Blanks 1.7",
"H5P.MarkTheWords 1.6",
"H5P.DragText 1.5"
"H5P.DragText 1.5",
"H5P.TrueFalse 1.0"
]
}
},