adding some strings
[moodle-linuxchix.git] / mod / hotpot / template / v6 / jmix6.js_
blob52dbd73ac612b4acfcbbf098b943f357f2e8f1d9
1 [inclScorm1.2]
2 //JMIX-SPECIFIC SCORM-RELATED JAVASCRIPT CODE
4 function SetScormScore(){
5 //Reports the current score and any other information back to the LMS
6         if (API != null){
7                 API.LMSSetValue('cmi.core.score.raw', Score);
8                 
9 //Now send a detailed reports on the item
10                 var ItemLabel = 'Item_1';
11                 API.LMSSetValue('cmi.objectives.0.id', 'obj'+ItemLabel);
12                 API.LMSSetValue('cmi.interactions.0.id', 'int'+ItemLabel);
13                 if (Finished == true){
14                         API.LMSSetValue('cmi.objectives.0.status', 'completed');
15                 }
16                 else{
17                         API.LMSSetValue('cmi.objectives.0.status', 'incomplete');
18                 }
19                                 
20                 API.LMSSetValue('cmi.objectives.0.score.min', '0');
21                 API.LMSSetValue('cmi.objectives.0.score.max', '100');
22                 API.LMSSetValue('cmi.objectives.0.score.raw', Score);
23 //We can only use the performance type, because we're storing multiple responses of various types.
24                 API.LMSSetValue('cmi.interactions.0.type', 'performance');
25                 API.LMSSetValue('cmi.interactions.0.student_response', AnswersTried);
26                 
27                 API.LMSCommit('');
28         }
30 [/inclScorm1.2]
32 //JMIX STANDARD OUTPUT FORMAT CODE
34 var CorrectResponse = '[strGuessCorrect]';
35 var IncorrectResponse = '[strGuessIncorrect]';
36 var TheseAnswersToo = '[strTheseAnswersToo]';
37 var ThisMuchCorrect = '[strThisMuch]';
38 var NextCorrect = '[strNextCorrect]';
39 var YourScoreIs = '[strYourScoreIs]';
40 var CapitalizeFirst = [boolCapitalizeFirst];
41 var Penalties = 0;
42 var Finished = false;
43 var TimeOver = false;
44 var Score = 0;
45 var strInstructions = '';
46 var AnswersTried = '';
49 var SegmentTemplate = '&nbsp; &nbsp;<a class="ExSegment" href="javascript:void(0)" onclick="AddSegment([SegmentNumber])" title="[strClickToAdd]">[CurrentSegment]</a>&nbsp; &nbsp;';
51 var Exercise = '';
53 var Punctuation = '[strPunctuation]';
55 var Openers = '[strOpenPunctuation]';
57 var Guesses = new Array();
58 var Remaining = new Array();
59 var CorrectParts = new Array();
61 var ClosestMatch = 0;
63 var LowerString='';
64 var UpperString='';
66 var Output = '';
68 var Segments = new Array();
69 [SegmentArray]
71 var GuessSequence = new Array();
73 var Answers = new Array();
74 [AnswerArray]
76 function WriteToGuess(Feedback) {
77         document.getElementById('GuessDiv').innerHTML = Feedback;
78 [inclPreloadImages]
79         RefreshImages();
80 [/inclPreloadImages]
83 function Undo(){
84         if (GuessSequence.length < 1){
85                 return;
86         }
87         GuessSequence.length = GuessSequence.length - 1;
88         BuildCurrGuess();
89         BuildExercise();
90         DisplayExercise(Exercise);
91 //Following line modified for 6.0.4.44 -- "remaining words" message removed, no longer needed
92         WriteToGuess('<span class="Answer">' + Output + '</span>');
95 function AddSegment(SegNum){
96 [inclTimer]
97         if (TimeOver == true){return;}
98 [/inclTimer]
99         GuessSequence[GuessSequence.length] = SegNum;
100         BuildCurrGuess();
101         WriteToGuess('<span class="Answer">' + Output + '</span>');
102         BuildExercise();
103         DisplayExercise(Exercise);
106 function BuildCurrGuess(){
108         var i = 0;
109         var j = 0;
110         var NewSeg = '';
112 //first, create arrays of all the segments guessed so far and those not yet used
113         GuessSegs = new Array();
114         GuessSegs.length = 0;
116 //set the "used" markers all to 0
117         for (i=0; i<Segments.length; i++){
118                 Segments[i][2] = 0;
119         }
121         for (i=0; i<GuessSequence.length; i++){
122                 for (j=0; j<Segments.length; j++){
123                         if ((Segments[j][1] == GuessSequence[i])&&(Segments[j][2] == 0)){
124                                 GuessSegs[GuessSegs.length] = Segments[j][0];
125                                 Segments[j][2] = 1;
126                                 break;
127                         }
128                 }
129         }
131 //Create the list of unused segments
132         RemainingList = '';
133         for (i=0; i<Segments.length; i++){
134                 if (Segments[i][2] == 0){
135                         RemainingList += Segments[i][0] + '&nbsp; &nbsp;&nbsp;';
136                 }
137         }
138         
139 //now concatenate the segments, adding spaces where appropriate;
140         Output = CompileString(GuessSequence);
143 function CompileString(InArray){
144         var OutString = '';
145         var i = 0;
146         OutArray = new Array();
148         for (i=0; i<InArray.length; i++){
149                 OutArray[OutArray.length] = FindSegment(InArray[i]);
150         }
152         if (OutArray.length > 0){
153                 OutString = OutArray[0];
154         }
155         else{
156                 OutString = '';
157         }
158         var Spacer = '';
160         for (i=1; i<OutArray.length; i++){
161                 Spacer = ' ';
162                 if ((Openers.indexOf(OutString.charAt(OutString.length-1)) > -1)||(Punctuation.indexOf(OutArray[i].charAt(0)) > -1)){
163                         Spacer = '';
164                 }
165                 OutString = OutString + Spacer + OutArray[i];           
166         }
168 //Capitalize the first letter if necessary
169         if (CapitalizeFirst == true){
170                 i = 0;
171                 if ((Openers.indexOf(OutString.charAt(i))>-1)||(OutString.charAt(i) == ' ')){
172                         i++;
173                 }
174                 if ((Openers.indexOf(OutString.charAt(i))>-1)||(OutString.charAt(i) == ' ')){
175                         i++;
176                 }
177                 var Temp = OutString.charAt(i);
178                 Temp = Temp.toUpperCase();
179                 OutString = OutString.substring(0, i) + Temp + OutString.substring(i+1, OutString.length);
180         }
181         return OutString;
183 function CheckAnswer(CheckType){
185         if (GuessSequence.length < 1){
186                 if (CheckType == 1){
187                         ShowMessage(NextCorrect + '<br /><span class="Answer">' + FindSegment(Answers[0][0]) + '</span>');
188                         Penalties++;
189                 }
190                 return;
191         }
193         var i = 0;
194         var j = 0;
195         var k = 0;
196         var WellDone = '';
197         var WhichCorrect = -1;
198         var TryAgain = '';
199         var LongestCorrectBit = '';
200         TempCorrect = new Array();
201         LongestCorrect = new Array();
202         var TempHint = '';
203         var HintToReturn = 1;
204         var OtherAnswers = '';
205         var AllDone = false;
207         for (i=0; i<Answers.length; i++){
208                 TempCorrect.length = 0;
209                 for (j=0; j<Answers[i].length; j++){
210                         if (Answers[i][j] == GuessSequence[j]){
211                                 TempCorrect[j] = GuessSequence[j];
212                         }
213                         else{
214                                 TempHint = Answers[i][j];
215                                 break;
216                         }
217                 }
218                 if ((TempCorrect.length == GuessSequence.length)&&(TempCorrect.length == Answers[i].length)){
220                         WhichCorrect = i;
221                         break;
222                 }
223                 else{
224                         if (TempCorrect.length > LongestCorrect.length){
225                                 LongestCorrect.length = 0;
226                                 for (k=0; k<TempCorrect.length; k++){
227                                         LongestCorrect[k] = TempCorrect[k];
228                                 }
229                                 HintToReturn = TempHint;
230                         } 
231                 }       
232         }
233         if (WhichCorrect > -1){
234                 AllDone = true;
235                 for (i=0; i<Answers.length; i++){
236                         if (i!=WhichCorrect){
237                                 OtherAnswers += '<br />' + CompileString(Answers[i]);
238                         }
239                 }
241                 WellDone = '<span class="Answer">' + Output + '</span><br /><br />' + CorrectResponse + '<br />';
243                 if (AnswersTried.length > 0){AnswersTried += ' | ';}
244                 AnswersTried += Output;
245                 
246 //Do score calculation here
247                 Score = Math.floor(((Segments.length-Penalties) * 100)/Segments.length);
248                 WellDone += YourScoreIs + ' ' + Score + '%.<br />';
250 [inclAlsoCorrect]
251                 if (OtherAnswers.length > 0){
252                         WellDone += TheseAnswersToo + '<span class="Answer">' + OtherAnswers + '</span>';
253                 }
254 [/inclAlsoCorrect]
256                 WriteToGuess(WellDone);
257                 ShowMessage(WellDone);
258         }
260         else{
261                 var WrongGuess = CompileString(GuessSequence);
262                 if (AnswersTried.length > 0){AnswersTried += ' | ';}
263                 AnswersTried += WrongGuess;
264                 TryAgain = '<span class="Answer">' + WrongGuess + '</span><br /><br />';
265                 if (CheckType == 0){
266                         TryAgain += IncorrectResponse + '<br />';
267                 }
269                 if (LongestCorrect.length > 0){
271                         LongestCorrectBit = CompileString(LongestCorrect);
272                         GuessSequence.length = LongestCorrect.length;
273                         TryAgain += ThisMuchCorrect + '<br /><span class="Answer">' + LongestCorrectBit + '</span><br />';
275 //These lines added for 6.0.3.44
276                         WriteToGuess('<span class="Answer">' + LongestCorrectBit + '</span>');
277                 }
278                 else{
279                         GuessSequence.length = 0;
280                         WriteToGuess('');
281                 }
283                 if (CheckType == 1){
284                         TryAgain += NextCorrect + '<br /><span class="Answer">' + FindSegment(HintToReturn) + '</span>';
285                 }
287                 BuildCurrGuess();
288                 BuildExercise();
289                 DisplayExercise(Exercise);
290                 ShowMessage(TryAgain);
291                 Penalties++; //Penalty for inaccurate check
292                 
293 [inclTimer]
294                 if (TimeOver == true){
295                         Score = Math.floor(((LongestCorrect.length-Penalties) * 100)/Segments.length);
296                         if (Score < 0){Score = 0;}
297                         ShowMessage(YourScoreIs + ' ' + Score + '%.<br />');
298                 }
299 [/inclTimer]
301         }
302 //If the exercise is over, deal with that
303         if ((AllDone == true)||(TimeOver == true)){
304 [inclSendResults]
305                 setTimeout('SendResults(' + Score + ')', 50);
306 [/inclSendResults]
307 [inclTimer]
308                 window.clearInterval(Interval);
309 [/inclTimer]
310                 TimeOver = true;
311                 Locked = true;
312                 Finished = true;
313                 setTimeout('Finish()', SubmissionTimeout);
314                 WriteToInstructions(YourScoreIs + ' ' + Score + '%.'); 
315         }
316 [inclScorm1.2]
317         if (AllDone == true){
318                 SetScormComplete();
319         }
320         else{
321                 SetScormIncomplete();
322         }
323 [/inclScorm1.2]
326 function FindSegment(SegID){
327         var Seg = '';
328         for (var i=0; i<Segments.length; i++){
329                 if (Segments[i][1] == SegID){
330                         Seg = Segments[i][0];
331                         break;
332                 }
333         }
334         return Seg;
337 function StartUp(){
338         RemoveBottomNavBarForIE();
340 //Stash the instructions so they can be redisplayed
341         strInstructions = document.getElementById('InstructionsDiv').innerHTML;
342         
343 [inclSendResults]
344         GetUserName();
345 [/inclSendResults]
347 [inclScorm1.2]
348         ScormStartUp();
349 [/inclScorm1.2]
351 [inclPreloadImages]
352         PreloadImages([PreloadImageList]);
353 [/inclPreloadImages]
355         Segments = Shuffle(Segments);
357 //Build and show the exercise
358         BuildExercise();
359         DisplayExercise(Exercise);      
360         
361 [inclTimer]
362         StartTimer();
363 [/inclTimer]
367 function BuildExercise(){
368         Exercise = '';
370         var SegRow = '';
371         var TempRow = '';
373         for (var i=0; i<Segments.length; i++){
374 //if the segment hasn't been used yet
375                 if (Segments[i][2] == 0){
376                         TempRow = SegmentTemplate;
377                         TempRow = TempRow.replace(/\[SegmentNumber\]/g, Segments[i][1]);
378                         TempRow = TempRow.replace(/\[CurrentSegment\]/g, Segments[i][0]);
379                         SegRow += TempRow;
380                 }
381         }
383 //Make it into a table
384         Exercise = SegRow;
387 function DisplayExercise(StuffToDisplay){
388         document.getElementById('SegmentDiv').innerHTML = StuffToDisplay;
389         FocusAButton();
390 [inclPreloadImages]
391         RefreshImages();
392 [/inclPreloadImages]
395 [inclTimer]
396 function TimesUp() {
397         document.getElementById('Timer').innerHTML = '[strTimesUp]';
398 [inclPreloadImages]
399         RefreshImages();
400 [/inclPreloadImages]
401         TimeOver = true;
402         Finished = true;
403         CheckAnswer(0);
404         Locked = true;
405 [inclScorm1.2]
406         SetScormTimedOut();
407 [/inclScorm1.2]
409 [/inclTimer]