Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Harmonize getAnswerGiven with other content types #32

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions scripts/h5p-true-false-answer-group.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ H5P.TrueFalse.AnswerGroup = (function ($, EventDispatcher) {
falseAnswer.on('invert', handleInvert(true, trueAnswer));

// Handle tabbing
var handleTabable = function(other, tabable) {
var handleTabable = function (other, tabable) {
return function () {
// If one of them are checked, that one should get tabfocus
if (!tabable || !self.hasAnswered() || other.isChecked()) {
Expand Down Expand Up @@ -100,6 +100,15 @@ H5P.TrueFalse.AnswerGroup = (function ($, EventDispatcher) {
return answer;
};

/**
* Return current answer
* @method setAnswer
* @param {Boolean|null} answerToSet null if no explicit answer given.
*/
self.setAnswer = function (answerToSet) {
answer = answerToSet;
};

/**
* Check if user has answered question yet
* @method hasAnswered
Expand Down Expand Up @@ -144,7 +153,7 @@ H5P.TrueFalse.AnswerGroup = (function ($, EventDispatcher) {
* @method reveal
*/
self.reveal = function () {
if (self.hasAnswered()) {
if (typeof self.hasAnswered() === 'boolean') {
if (self.isCorrect()) {
correctAnswer.markCorrect();
}
Expand Down
2 changes: 1 addition & 1 deletion scripts/h5p-true-false-answer.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ H5P.TrueFalse.Answer = (function ($, EventDispatcher) {
* @param {String} correctMessage Message read by readspeaker when correct alternative is chosen
* @param {String} wrongMessage Message read by readspeaker when wrong alternative is chosen
*/
function Answer (text, correctMessage, wrongMessage) {
function Answer(text, correctMessage, wrongMessage) {
var self = this;

EventDispatcher.call(self);
Expand Down
19 changes: 11 additions & 8 deletions scripts/h5p-true-false.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,11 @@ H5P.TrueFalse = (function ($, Question) {

// select find container to attach dialogs to
var $container;
if($containerParents.length !== 0) {
if ($containerParents.length !== 0) {
// use parent highest up if any
$container = $containerParents.last();
}
else if($content.length !== 0){
else if ($content.length !== 0) {
$container = $content;
}
else {
Expand Down Expand Up @@ -185,7 +185,7 @@ H5P.TrueFalse = (function ($, Question) {
* @param {XAPIEvent} xAPIEvent
* @private
*/
var addQuestionToXAPI = function(xAPIEvent) {
var addQuestionToXAPI = function (xAPIEvent) {
var definition = xAPIEvent.getVerifiedStatementValue(['object', 'definition']);
definition.description = {
// Remove tags, must wrap in div tag because jQuery 1.9 will crash if the string isn't wrapped in a tag.
Expand Down Expand Up @@ -226,7 +226,7 @@ H5P.TrueFalse = (function ($, Question) {
* @param {H5P.XAPIEvent} xAPIEvent
* The xAPI event we will add a response to
*/
var addResponseToXAPI = function(xAPIEvent) {
var addResponseToXAPI = function (xAPIEvent) {
var isCorrect = answerGroup.isCorrect();
xAPIEvent.setScoredResult(isCorrect ? MAX_SCORE : 0, MAX_SCORE, self, true, isCorrect);
xAPIEvent.data.statement.result.response = (isCorrect ? getCorrectAnswer() : getWrongAnswer());
Expand Down Expand Up @@ -273,6 +273,9 @@ H5P.TrueFalse = (function ($, Question) {
var score = self.getScore();
var scoreText;

//
answerGroup.setAnswer(null);

toggleButtonState(score === MAX_SCORE ? State.FINISHED_CORRECT : State.FINISHED_WRONG);

if (score === MAX_SCORE && params.behaviour.feedbackOnCorrect) {
Expand Down Expand Up @@ -422,7 +425,7 @@ H5P.TrueFalse = (function ($, Question) {
*
* @see contract at {@link https://h5p.org/documentation/developers/contracts#guides-header-6}
*/
self.getXAPIData = function(){
self.getXAPIData = function () {
var xAPIEvent = this.createXAPIEventTemplate('answered');
this.addQuestionToXAPI(xAPIEvent);
this.addResponseToXAPI(xAPIEvent);
Expand All @@ -434,7 +437,7 @@ H5P.TrueFalse = (function ($, Question) {
/**
* Add the question itself to the definition part of an xAPIEvent
*/
self.addQuestionToXAPI = function(xAPIEvent) {
self.addQuestionToXAPI = function (xAPIEvent) {
var definition = xAPIEvent.getVerifiedStatementValue(['object', 'definition']);
$.extend(definition, this.getxAPIDefinition());
};
Expand Down Expand Up @@ -468,12 +471,12 @@ H5P.TrueFalse = (function ($, Question) {

xAPIEvent.setScoredResult(rawUserScore, MAX_SCORE, self, true, isCorrect);

if(self.getCurrentState().answer !== undefined) {
if (self.getCurrentState().answer !== undefined) {
currentResponse += answerGroup.isCorrect() ? getCorrectAnswer() : getWrongAnswer();
}
xAPIEvent.data.statement.result.response = currentResponse;
};
}
}

// Inheritance
TrueFalse.prototype = Object.create(Question.prototype);
Expand Down