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

HFP-2067 Fix optional solution #63

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
10 changes: 10 additions & 0 deletions css/flashcards.css
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,12 @@
border-radius: 2em 2em 0 0;
}

.h5p-flashcards .h5p-imageholder.h5p-image-only {
margin-bottom: 1em;
border-bottom-left-radius: 2em;
border-bottom-right-radius: 2em;
}

.h5p-flashcards .h5p-card .h5p-clue {
display: block;
padding: 0.5em;
Expand Down Expand Up @@ -230,6 +236,10 @@
border-radius: 0 0 2em 2em;
}

.h5p-flashcards .h5p-foot.h5p-no-answer {
margin-bottom: 0;
}

.h5p-flashcards .h5p-answer {
background: none;
position: relative;
Expand Down
37 changes: 27 additions & 10 deletions js/flashcards.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,11 @@ H5P.Flashcards = (function ($, XapiGenerator) {
* @return {number}
*/
C.prototype.getMaxScore = function () {
return this.options.cards.length;
return this.options.cards
.filter( function (card) {
return typeof card.answer !== 'undefined';
})
.length;
};

/**
Expand Down Expand Up @@ -308,6 +312,18 @@ H5P.Flashcards = (function ($, XapiGenerator) {
'</div>')
.appendTo($inner);

// Cards may not require an answer and thus no extra fields
if (!card.answer) {
$card.find('.h5p-answer').addClass('h5p-hidden');
$card.find('.h5p-foot').addClass('h5p-no-answer');

if (!card.text) {
$card.find('.h5p-imageholder').addClass('h5p-image-only');
$card.find('.h5p-foot').addClass('h5p-hidden');
$card.find('.h5p-flashcard-overlay').addClass('h5p-hidden');
}
}

$card.find('.h5p-imageholder').prepend(this.$images[index]);

$card.prepend($('<div class="h5p-flashcard-overlay"></div>').on('click', function () {
Expand Down Expand Up @@ -378,7 +394,7 @@ H5P.Flashcards = (function ($, XapiGenerator) {
that.$ariaAnnouncer.html(ariaText);
}

done = (that.numAnswered >= that.options.cards.length);
done = (that.numAnswered >= that.getMaxScore());

if (!done) {
that.nextTimer = setTimeout(that.next.bind(that), 3500);
Expand Down Expand Up @@ -483,19 +499,20 @@ H5P.Flashcards = (function ($, XapiGenerator) {

var $resultsAnswer = $('<div/>', {
'class': 'h5p-results-answer',
'text': this.answers[i]
'text': (card.answer) ? this.answers[i] : ''
}).appendTo($listItem);

$resultsAnswer.prepend('<span>' + this.options.answerShortText + ' </span>');

if (!userCorrect) {
if (card.answer && !userCorrect) {
$resultsAnswer.prepend('<span>' + this.options.answerShortText + ' </span>');
$resultsAnswer.append('<span> ' + this.options.showSolutionText + ': </span>');
$resultsAnswer.append('<span class="h5p-correct">' + card.answer + '</span>');
}

$('<div/>', {
'class': 'h5p-results-box'
}).appendTo($listItem);
if (card.answer) {
$('<div/>', {
'class': 'h5p-results-box'
}).appendTo($listItem);
}
}
if (this.getScore() < this.getMaxScore()) {
this.$retryButton.removeClass('h5p-invisible');
Expand Down Expand Up @@ -600,7 +617,7 @@ H5P.Flashcards = (function ($, XapiGenerator) {
that.$prevButton.removeClass('h5p-hidden');
that.setProgress();

if ($next.is(':last-child') && that.numAnswered == that.options.cards.length) {
if ($next.is(':last-child') && that.numAnswered == that.getMaxScore()) {
that.$container.find('.h5p-show-results').show();
}
};
Expand Down