@@ -206,7 +206,7 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
206
206
this . lastAnswerIsCorrect = event . data . correct ;
207
207
208
208
if ( ! this . options . behaviour . autoContinue ) {
209
- this . updateDirectionButtons ( ) ;
209
+ this . updateNavigation ( ) ;
210
210
}
211
211
212
212
// Keep track of num correct/wrong answers
@@ -547,6 +547,10 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
547
547
}
548
548
}
549
549
550
+ const navigation = document . createElement ( 'div' ) ;
551
+ navigation . setAttribute ( 'class' , 'h5p-scs-navigation' ) ;
552
+ self . $container . get ( 0 ) . append ( navigation ) ;
553
+
550
554
this . directionButtons . previous = UI . createButton ( {
551
555
'class' : 'h5p-ssc-direction-button previous' ,
552
556
'aria-label' : self . l10n . previousButtonLabel , // TODO: Add l10n
@@ -561,9 +565,15 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
561
565
event . preventDefault ( ) ;
562
566
}
563
567
} ,
564
- appendTo : self . $container
568
+ appendTo : navigation
565
569
} ) . get ( 0 ) ;
566
570
571
+ this . progressDisplay = document . createElement ( 'div' ) ;
572
+ this . progressDisplay . setAttribute ( 'class' , 'h5p-scs-progress-display' ) ;
573
+ // Progress announcement is already handled by the progressbar
574
+ this . progressDisplay . setAttribute ( 'aria-hidden' , 'true' ) ;
575
+ navigation . append ( this . progressDisplay ) ;
576
+
567
577
this . directionButtons . next = UI . createButton ( {
568
578
'class' : 'h5p-ssc-direction-button next' ,
569
579
'aria-label' : self . l10n . nextButtonLabel ,
@@ -578,10 +588,10 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
578
588
event . preventDefault ( ) ;
579
589
}
580
590
} ,
581
- appendTo : self . $container
591
+ appendTo : navigation
582
592
} ) . get ( 0 ) ;
583
593
584
- this . updateDirectionButtons ( ) ;
594
+ this . updateNavigation ( ) ;
585
595
}
586
596
587
597
if ( self . options . behaviour . soundEffectsEnabled ) {
@@ -646,13 +656,19 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
646
656
} ;
647
657
648
658
/**
649
- * Update direction buttons .
659
+ * Update navigation .
650
660
*/
651
- SingleChoiceSet . prototype . updateDirectionButtons = function ( ) {
652
- const shouldShowPreviousButton = this . options . behaviour . backwardsNavigationIsAllowed && this . currentIndex > 0 ;
661
+ SingleChoiceSet . prototype . updateNavigation = function ( ) {
662
+ const shouldShowPreviousButton = this . options . behaviour . backwardsNavigationIsAllowed &&
663
+ this . currentIndex > 0 && this . currentIndex < this . choices . length ;
653
664
654
665
this . toggleDirectionButton ( 'previous' , shouldShowPreviousButton ) ;
655
666
this . toggleDirectionButton ( 'next' , this . choices [ this . currentIndex ] ?. getAnswerGiven ( ) ) ;
667
+
668
+ if ( this . progressDisplay ) {
669
+ this . progressDisplay . innerText = `${ this . currentIndex + 1 } / ${ this . options . choices . length } ` ;
670
+ this . progressDisplay ?. classList . toggle ( 'display-none' , this . currentIndex >= this . choices . length ) ;
671
+ }
656
672
} ;
657
673
658
674
/**
@@ -718,7 +734,7 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
718
734
719
735
self . currentIndex = index ;
720
736
721
- this . updateDirectionButtons ( ) ;
737
+ this . updateNavigation ( ) ;
722
738
} ;
723
739
724
740
/**
@@ -897,6 +913,8 @@ H5P.SingleChoiceSet = (function ($, UI, Question, SingleChoice, SolutionView, Re
897
913
H5P . Transition . onTransitionEnd ( this . $choices , function ( ) {
898
914
self . removeFeedback ( ) ;
899
915
} , 600 ) ;
916
+
917
+ this . updateNavigation ( ) ;
900
918
} ;
901
919
902
920
/**
0 commit comments