Skip to content

Commit

Permalink
HFP-3780 Cleanup code #2
Browse files Browse the repository at this point in the history
  • Loading branch information
runarkasp committed May 22, 2024
1 parent d95b40d commit e276b65
Showing 1 changed file with 14 additions and 20 deletions.
34 changes: 14 additions & 20 deletions js/flashcards.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ H5P.Flashcards = (function ($, XapiGenerator) {
results: "Results",
ofCorrect: "@score of @total correct",
showResults: "Show results",
retry : "Retry",
retry: "Retry",
cardAnnouncement: 'Incorrect answer. Correct answer was @answer',
pageAnnouncement: 'Page @current of @total',
correctAnswerAnnouncement: '@answer is correct!'
Expand Down Expand Up @@ -208,7 +208,6 @@ H5P.Flashcards = (function ($, XapiGenerator) {
var $inner = this.$container.html(
'<div class="h5p-description" id="flashcards-description' + '-' + descId + '" title="' + this.options.description + '">' + this.options.description + '</div>' +
'<div class="h5p-progress"></div>' +
// '<div class="h5p-inner" role="region" aria-labelledby="flashcards-description' + '-' + descId + '" aria-roledescription="carousel"></div>' +
'<div class="h5p-inner" role="region" ' + '-' + descId + '></div>' +
'<div class="h5p-navigation">' +
'<button type="button" class="h5p-button h5p-previous h5p-hidden" tabindex="0" title="' + this.options.previous + '" aria-label="' + this.options.previous + '"></button>' +
Expand Down Expand Up @@ -329,7 +328,6 @@ H5P.Flashcards = (function ($, XapiGenerator) {

// Generate a new flashcards html and add it to h5p-inner
var $card = $(
// '<div role="group" aria-roledescription="slide" aria-labelledby="h5p-flashcard-card-' + cardId + '" class="h5p-card h5p-animate' + (index === 0 ? ' h5p-current' : '') + '"> ' +
'<div role="group" id="cardgroup"' + '" class="h5p-card h5p-animate' + (index === 0 ? ' h5p-current' : '') + '"> ' +
'<div class="h5p-cardholder">' +
'<div class="h5p-imageholder">' +
Expand Down Expand Up @@ -569,10 +567,7 @@ H5P.Flashcards = (function ($, XapiGenerator) {
* @param {H5P.jQuery} $card
* Class to add to existing current card.
*/
C.prototype.setCurrent = function ($card) {

this.$prev = this.$current;

C.prototype.setCurrent = function ($card) {
// Remove from existing card.
if (this.$current) {
this.$current.find('.h5p-textinput').attr('tabindex', '-1');
Expand All @@ -581,23 +576,22 @@ H5P.Flashcards = (function ($, XapiGenerator) {
this.$current.find('.h5p-icon-button').attr('tabindex', '-1');
}

// Set new card
// Set new card
this.$current = $card;

/* We can't set focus on anything until the transition is finished.
If we do, iPad will try to center the focused element while the transition
is running, and the card will be misplaced */

// Handle focus shift and screen reader announcement
$card.one('transitionend', function () {
if ($card.hasClass('h5p-current') && !$card.find('.h5p-textinput')[0].disabled) {
$card.find('.h5p-textinput').focus();
}
setTimeout(function () {
this.announceCurrentPage();
}.bind(this), 50); // Adjust the delay as necessary

}.bind(this));
// Handle focus shift and screen reader announcement
$card.one('transitionend', function () {
if ($card.hasClass('h5p-current') && !$card.find('.h5p-textinput')[0].disabled) {
$card.find('.h5p-textinput').focus();
}
setTimeout(function () {
this.announceCurrentPage();
}.bind(this), 50); // Adjust the delay as necessary
}.bind(this));

// Update card classes
$card.removeClass('h5p-previous h5p-next');
Expand All @@ -620,7 +614,7 @@ H5P.Flashcards = (function ($, XapiGenerator) {
$card.find('.h5p-check-button').attr('tabindex', '0');
$card.find('.h5p-icon-button').attr('tabindex', '0');
$card.find('.joubel-tip-container').attr('tabindex', '0');
};
};

/**
* Announces current page to assistive technologies
Expand All @@ -629,7 +623,7 @@ H5P.Flashcards = (function ($, XapiGenerator) {
const pageText = this.options.pageAnnouncement
.replace('@current', this.$current.index() + 1)
.replace('@total', this.options.cards.length.toString());
this.$pageAnnouncer.text(pageText);
this.$pageAnnouncer.text(pageText);
};

/**
Expand Down

0 comments on commit e276b65

Please sign in to comment.