1
+ /*global EJS*/
1
2
// Will render a Question with multiple choices for answers.
2
3
3
4
// Options format:
@@ -55,6 +56,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
55
56
return new H5P . MultiChoice ( options , contentId , contentData ) ;
56
57
var self = this ;
57
58
this . contentId = contentId ;
59
+ this . contentData = contentData ;
58
60
H5P . Question . call ( self , 'multichoice' ) ;
59
61
var $ = H5P . jQuery ;
60
62
@@ -92,7 +94,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
92
94
checkAnswerButton : 'Check' ,
93
95
showSolutionButton : 'Show solution' ,
94
96
tryAgainButton : 'Try again' ,
95
- scoreBarLabel : 'Score ' ,
97
+ scoreBarLabel : 'You got :num out of :total points ' ,
96
98
tipAvailable : "Tip available" ,
97
99
feedbackAvailable : "Feedback available" ,
98
100
readFeedback : 'Read feedback' ,
@@ -103,11 +105,11 @@ H5P.MultiChoice = function (options, contentId, contentData) {
103
105
behaviour : {
104
106
enableRetry : true ,
105
107
enableSolutionsButton : true ,
108
+ enableCheckButton : true ,
106
109
type : 'auto' ,
107
110
singlePoint : true ,
108
111
randomAnswers : false ,
109
112
showSolutionsRequiresInput : true ,
110
- disableImageZooming : false ,
111
113
autoCheck : false ,
112
114
passPercentage : 100 ,
113
115
showScorePoints : true
@@ -197,21 +199,23 @@ H5P.MultiChoice = function (options, contentId, contentData) {
197
199
* Register the different parts of the task with the H5P.Question structure.
198
200
*/
199
201
self . registerDomElements = function ( ) {
200
- if ( params . media && params . media . library ) {
201
- var type = params . media . library . split ( ' ' ) [ 0 ] ;
202
+ var media = params . media . type ;
203
+ if ( media && media . library ) {
204
+ var type = media . library . split ( ' ' ) [ 0 ] ;
202
205
if ( type === 'H5P.Image' ) {
203
- if ( params . media . params . file ) {
206
+ if ( media . params . file ) {
204
207
// Register task image
205
- self . setImage ( params . media . params . file . path , {
206
- disableImageZooming : params . behaviour . disableImageZooming ,
207
- alt : params . media . params . alt
208
+ self . setImage ( media . params . file . path , {
209
+ disableImageZooming : params . media . disableImageZooming || false ,
210
+ alt : media . params . alt ,
211
+ title : media . params . title
208
212
} ) ;
209
213
}
210
214
}
211
215
else if ( type === 'H5P.Video' ) {
212
- if ( params . media . params . sources ) {
216
+ if ( media . params . sources ) {
213
217
// Register task video
214
- self . setVideo ( params . media ) ;
218
+ self . setVideo ( media ) ;
215
219
}
216
220
}
217
221
}
@@ -505,7 +509,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
505
509
* Hide solution for the given answer(s)
506
510
*
507
511
* @private
508
- * @param {H5P.jQuery } $answer
512
+ * @param {H5P.jQuery } $answer
509
513
*/
510
514
var hideSolution = function ( $answer ) {
511
515
$answer
@@ -575,13 +579,13 @@ H5P.MultiChoice = function (options, contentId, contentData) {
575
579
// Remove all tip dialogs
576
580
removeFeedbackDialog ( ) ;
577
581
578
- self . hideButton ( 'check-answer' ) ;
579
582
if ( params . behaviour . enableSolutionsButton ) {
580
583
self . showButton ( 'show-solution' ) ;
581
584
}
582
585
if ( params . behaviour . enableRetry ) {
583
586
self . showButton ( 'try-again' ) ;
584
587
}
588
+ self . hideButton ( 'check-answer' ) ;
585
589
586
590
self . showCheckSolution ( ) ;
587
591
disableInput ( ) ;
@@ -590,7 +594,6 @@ H5P.MultiChoice = function (options, contentId, contentData) {
590
594
addQuestionToXAPI ( xAPIEvent ) ;
591
595
addResponseToXAPI ( xAPIEvent ) ;
592
596
self . trigger ( xAPIEvent ) ;
593
- self . trigger ( 'resize' ) ;
594
597
} ;
595
598
596
599
/**
@@ -639,7 +642,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
639
642
} , false ) ;
640
643
641
644
// Check solution button
642
- if ( ! params . behaviour . autoCheck || ! params . behaviour . singleAnswer ) {
645
+ if ( params . behaviour . enableCheckButton && ( ! params . behaviour . autoCheck || ! params . behaviour . singleAnswer ) ) {
643
646
self . addButton ( 'check-answer' , params . UI . checkAnswerButton ,
644
647
function ( ) {
645
648
self . answered = true ;
@@ -670,7 +673,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
670
673
self . answered = false ;
671
674
if ( params . behaviour . randomAnswers ) {
672
675
// reshuffle answers
673
- oldIdMap = idMap ;
676
+ var oldIdMap = idMap ;
674
677
idMap = getShuffleMap ( ) ;
675
678
var answersDisplayed = $myDom . find ( '.h5p-answer' ) ;
676
679
// remember tips
@@ -790,27 +793,20 @@ H5P.MultiChoice = function (options, contentId, contentData) {
790
793
// Determine feedback
791
794
var max = self . getMaxScore ( ) ;
792
795
793
- // Show feedback
794
- if ( ! skipFeedback ) {
795
- this . setFeedback ( getFeedbackText ( score , max ) , score , max , params . UI . scoreBarLabel ) ;
796
- }
797
-
798
796
// Disable task if maxscore is achieved
799
797
var fullScore = ( score === max ) ;
798
+
800
799
if ( fullScore ) {
801
- finishedTask ( ) ;
800
+ self . hideButton ( 'check-answer' ) ;
801
+ self . hideButton ( 'try-again' ) ;
802
+ self . hideButton ( 'show-solution' ) ;
802
803
}
803
804
804
- self . trigger ( 'resize' ) ;
805
- } ;
805
+ // Show feedback
806
+ if ( ! skipFeedback ) {
807
+ this . setFeedback ( getFeedbackText ( score , max ) , score , max , params . UI . scoreBarLabel ) ;
808
+ }
806
809
807
- /**
808
- * Method to use when the task is correctly answered, removes all buttons and disables input.
809
- */
810
- var finishedTask = function ( ) {
811
- self . hideButton ( 'check-answer' ) ;
812
- self . hideButton ( 'try-again' ) ;
813
- self . hideButton ( 'show-solution' ) ;
814
810
self . trigger ( 'resize' ) ;
815
811
} ;
816
812
@@ -968,7 +964,6 @@ H5P.MultiChoice = function (options, contentId, contentData) {
968
964
* @return {number[] } map pointing from original answers to shuffled answers
969
965
*/
970
966
var getShuffleMap = function ( ) {
971
- var origOrder = $ . extend ( [ ] , params . answers ) ;
972
967
params . answers = H5P . shuffleArray ( params . answers ) ;
973
968
974
969
// Create a map from the new id to the old one
@@ -977,7 +972,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
977
972
idMap [ i ] = params . answers [ i ] . originalOrder ;
978
973
}
979
974
return idMap ;
980
- }
975
+ } ;
981
976
982
977
// Initialization code
983
978
// Randomize order, if requested
@@ -1099,7 +1094,7 @@ H5P.MultiChoice = function (options, contentId, contentData) {
1099
1094
} ;
1100
1095
1101
1096
this . getTitle = function ( ) {
1102
- return H5P . createTitle ( params . question ) ;
1097
+ return H5P . createTitle ( ( this . contentData && this . contentData . metadata && this . contentData . metadata . title ) ? this . contentData . metadata . title : 'Multiple Choice' ) ;
1103
1098
} ;
1104
1099
} ;
1105
1100
0 commit comments