adding some strings
[moodle-linuxchix.git] / mod / hotpot / template / v6 / jcross6.js_
blob26c911ff05ba3ef78c9f81b746ada818ebe1219a
1 [inclScorm1.2]
2 //JCROSS-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 = 'Crossword';
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                 API.LMSSetValue('cmi.objectives.0.score.min', '0');
20                 API.LMSSetValue('cmi.objectives.0.score.max', '100');
21                 API.LMSSetValue('cmi.objectives.0.score.raw', Score);
22 //We're not sending any student response data, so we can set this to a non-standard value
23                 API.LMSSetValue('cmi.interactions.0.type', 'crossword');
24                 
25                 API.LMSCommit('');
26         }
28 [/inclScorm1.2]
30 //JCROSS CORE JAVASCRIPT CODE
32 var InGap = false;
33 var CurrentBox = null;
34 var Feedback = '';
35 var AcrossCaption = '';
36 var DownCaption = '';
37 var Correct = '[strCorrect]';
38 var Incorrect = '[strIncorrect]'; 
39 var GiveHint = '[strGiveHint]';
40 var YourScoreIs = '[strYourScoreIs]';
41 var BuiltGrid = '';
42 var BuiltExercise = '';
43 var Penalties = 0;
44 var Score = 0;
45 var InTextBox = false;
46 var Locked = false;
47 var TimeOver = false;
48 var CaseSensitive = [boolCaseSensitive]; 
50 var InputStuff = '<form method="post" action="" onsubmit="return false;"><span class="ClueNum">[strClueNum]: </span>';
51 InputStuff += '[strClue] <input onfocus="CurrentBox=this;InTextBox=true;" onblur="InTextBox=false;" id="[strBoxId]" type="edit" size="[strEditSize]" maxlength="[strMaxLength]"></input>';
52 InputStuff += '<button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="EnterGuess([strParams])">[strEnterCaption]</button>';
53 InputStuff += '[inclHint]<button class="FuncButton" onfocus="FuncBtnOver(this)" onblur="FuncBtnOut(this)" onmouseover="FuncBtnOver(this)" onmouseout="FuncBtnOut(this)" onmousedown="FuncBtnDown(this)" onmouseup="FuncBtnOut(this)" onclick="ShowHint([strParams])">[strHintCaption]</button>[/inclHint]';
54 InputStuff += '</form>';
56 var CurrBoxElement = null;
57 var Finished = false;
59 function StartUp(){
60         RemoveBottomNavBarForIE();
61 //Show a keypad if there is one (added bugfix for 6.0.4.12)
62         if (document.getElementById('CharacterKeypad') != null){
63                 document.getElementById('CharacterKeypad').style.display = 'block';
64         }
65 [inclScorm1.2]
66         ScormStartUp();
67 [/inclScorm1.2]
68         
69         AcrossCaption = document.getElementById('CluesAcrossLabel').innerHTML;
70         DownCaption = document.getElementById('CluesDownLabel').innerHTML;
71 [inclSendResults]
72         GetUserName();
73 [/inclSendResults]
75 [inclPreloadImages]
76         PreloadImages([PreloadImageList]);
77 [/inclPreloadImages]
79 [inclTimer]
80         StartTimer();
81 [/inclTimer]
85 function GetAnswerLength(Across,x,y){
86         Result = 0;
87         if (Across == false){
88                 while ((x<L.length)&&(L[x][y].length > 0)){
89                         Result += L[x][y].length;
90                         x++;
91                 } 
92                 return Result;
93         }
94         else{
95                 while ((y<L[x].length)&&(L[x][y].length > 0)){
96                         Result += L[x][y].length;
97                         y++;
98                 }       
99                 return Result;
100         }
103 function GetEditSize(Across,x,y){
104         var Len = GetAnswerLength(Across,x,y);
105         if (IsCJK(L[x][y].charCodeAt(0))){
106                 Len *= 2;
107         }
108         return Len;
111 function ShowClue(ClueNum,x,y){
112         var Result = '';
113         var Temp;
114         var strParams;
115         var Clue = document.getElementById('Clue_A_' + ClueNum);
116         if (Clue != null){
117                 Temp = InputStuff.replace(/\[ClueNum\]/g, ClueNum);
118                 Temp = Temp.replace(/\[strClueNum\]/g, AcrossCaption + ' ' + ClueNum);
119                 strParams = 'true,' + ClueNum + ',' + x + ',' + y + ',\'[strBoxId]\'';
120                 Temp = Temp.replace(/\[strParams\]/g, strParams);
121                 Temp = Temp.replace(/\[strBoxId\]/g, 'GA_' + ClueNum + '_' + x + '_' + y);
122                 Temp = Temp.replace(/\[strEditSize\]/g, GetEditSize(true,x,y));
123                 Temp = Temp.replace(/\[strMaxLength\]/g, GetAnswerLength(true,x,y));
124                 Temp = Temp.replace(/\[strClue\]/g, Clue.innerHTML, Temp);
125                 Result += Temp;
126         }
127         Clue = document.getElementById('Clue_D_' + ClueNum);
128         if (Clue != null){
129                 Temp = InputStuff.replace(/\[ClueNum\]/g, ClueNum);
130                 Temp = Temp.replace(/\[strClueNum\]/g, DownCaption + ' ' + ClueNum);
131                 strParams = 'false,' + ClueNum + ',' + x + ',' + y + ',\'[strBoxId]\'';
132                 Temp = Temp.replace(/\[strParams\]/g, strParams);
133                 Temp = Temp.replace(/\[strBoxId\]/g, 'GD_' + ClueNum + '_' + x + '_' + y);
134                 Temp = Temp.replace(/\[strEditSize\]/g, GetAnswerLength(false,x,y));
135                 Temp = Temp.replace(/\[strClue\]/g, Clue.innerHTML, Temp);
136                 Result += Temp;
137         }
138         document.getElementById('ClueEntry').innerHTML = Result;
141 function EnterGuess(Across,ClueNum,x,y,BoxId){
142         if (document.getElementById(BoxId) != null){
143                 var Guess = document.getElementById(BoxId).value;
144                 var AnsLength = GetAnswerLength(Across,x,y);
145                 EnterAnswer(Guess,Across,AnsLength,x,y);
146         }
149 function SplitStringToPerceivedChars(InString, PC){
150         var Temp = InString.charAt(0);
151         if (InString.length > 1){
152                 for (var i=1; i<InString.length; i++){
153                         if (IsCombiningDiacritic(InString.charCodeAt(i)) == true){
154                                 Temp += InString.charAt(i);
155                         }
156                         else{
157                                 PC.push(Temp);
158                                 Temp = InString.charAt(i);
159                         }
160                 }
161         }
162         PC.push(Temp);
165 function EnterAnswer(Guess,Across,AnsLength,x,y){
166         var PC = new Array();
167         SplitStringToPerceivedChars(Guess, PC);
168         
169         var i=x;
170         var j=y;
171         var Letter = 0;
172         while (Letter < AnsLength){
173                 if (Letter < PC.length){
174                         G[i][j] = PC[Letter];
175                         if (document.getElementById('L_' + i + '_' + j) != null){
176                                 document.getElementById('L_' + i + '_' + j).innerHTML = PC[Letter];
177                         }
178                 }
179                 if (Across == true){
180                         j++;
181                 }
182                 else{
183                         i++;
184                 }
185                 Letter++;
186         }
189 function SetGridSquareValue(x,y,Val){
190         var GridId = 'L_' + x + '_' + y;
191         if (document.getElementById(GridId) != null){
192                 document.getElementById(GridId).innerHTML = Val;
193         }
196 function ShowHint(Across,ClueNum,x,y,BoxId){
197         var i=x;
198         var j=y;
199         var LetterFromGuess = '';
200         var LetterFromKey = '';
201         var OutString = '';
202         if (Across==true){
203                 while (j<L[i].length){
204                         if (L[i][j] != ''){
205                                 OutString += L[i][j];
206                                 if (CaseSensitive == true){
207                                         LetterFromKey = L[i][j];
208                                         LetterFromGuess = G[i][j];
209                                 }
210                                 else {
211                                         LetterFromKey = L[i][j].toUpperCase();
212                                         LetterFromGuess = G[i][j].toUpperCase();
213                                 }
214                                 if (LetterFromGuess != LetterFromKey){
215 //                              if (G[i][j] != L[i][j]){
216                                         G[i][j] = L[i][j];
217                                         Penalties++;
218                                         break;
219                                 }
220                         }
221                         else{
222                                 break;
223                         }
224                 j++;
225                 }
226         }
227         else{
228                 while (i<L.length){
229                         if (L[i][j] != ''){
230                                 OutString += L[i][j];
231                                 if (CaseSensitive == true){
232                                         LetterFromKey = L[i][j];
233                                         LetterFromGuess = G[i][j];
234                                 }
235                                 else {
236                                         LetterFromKey = L[i][j].toUpperCase();
237                                         LetterFromGuess = G[i][j].toUpperCase();
238                                 }
239                                 if (LetterFromGuess != LetterFromKey){
240 //                              if (G[i][j] != L[i][j]){
241                                         G[i][j] = L[i][j];
242                                         Penalties++;
243                                         break;
244                                 }
245                         }
246                         else{
247                                 break;
248                         }
249                 i++;
250                 }
251         }
252         if (document.getElementById(BoxId) != null){
253                 document.getElementById(BoxId).value = OutString;
254         }
257 L = new Array();
258 [strLetterArray]
260 CL = new Array();
261 [strClueNumArray]
263 G = new Array();
264 [strGuessArray]
266 function CheckAnswers(){
267         if (Locked == true){return;}
269         var AllCorrect = true;
270         var TotLetters = 0;
271         var CorrectLetters = 0;
272         var LetterFromKey = ''; 
273         var LetterFromGuess = '';
274         
275 //Check each letter
276         for (var i=0; i<L.length; i++){
277                 for (var j=0; j<L[i].length; j++){
278                         if (L[i][j] != ''){
279                                 TotLetters++;
280                                 if (CaseSensitive == true) {
281                                         LetterFromKey = L[i][j];
282                                         LetterFromGuess = G[i][j];
283                                 }
284                                 else {
285                                         LetterFromKey = L[i][j].toUpperCase();
286                                         LetterFromGuess = G[i][j].toUpperCase();
287                                 }
288                                 if (LetterFromGuess != LetterFromKey){ 
289                                         G[i][j] = '';
290 //Blank that square in the grid
291                                         SetGridSquareValue(i,j,'');
292                                         AllCorrect = false;
293                                 }
294                                 else{
295                                         CorrectLetters++;
296                                 }
297                         }
298                 }
299         }
301         Score = Math.floor(((CorrectLetters-Penalties) * 100)/TotLetters);
302         if (Score < 0){Score = 0;}
304 //Compile the output
305         var Output = '';
307         if (AllCorrect == true){
308                 Output = Correct + '<br />';
309         }
311         Output += YourScoreIs + ' ' + Score + '%.<br />';
312         if (AllCorrect == false){
313                 Output += Incorrect;
314                 Penalties++;
315         }
317         ShowMessage(Output);
318         WriteToInstructions(Output);
319         
320         if ((AllCorrect == true)||(TimeOver == true)){
321 [inclSendResults]
322                 setTimeout('SendResults(' + Score + ')', 50);
323 [/inclSendResults]
324 [inclTimer]
325                 window.clearInterval(Interval);
326 [/inclTimer]
327                 TimeOver = true;
328                 Locked = true;
329                 Finished = true;
330                 setTimeout('Finish()', SubmissionTimeout);
331         }
332 [inclScorm1.2]
333         if (AllCorrect == true){
334                 SetScormComplete();
335         }
336         else{
337                 SetScormIncomplete();
338         }
339 [/inclScorm1.2]
342 function Finish(){
343 //If there's a form, fill it out and submit it
344         if (document.store != null){
345                 Frm = document.store;
346                 Frm.starttime.value = HPNStartTime;
347                 Frm.endtime.value = (new Date()).getTime();
348                 Frm.mark.value = Score;
349                 Frm.submit();
350         }
353 function TypeChars(Chars){
354         if (CurrentBox != null){
355                 CurrentBox.value += Chars;
356         }
359 [inclTimer]
360 function TimesUp() {
361         document.getElementById('Timer').innerHTML = '[strTimesUp]';
362 [inclPreloadImages]
363         RefreshImages();
364 [/inclPreloadImages]
365         TimeOver = true;
366         Finished = true;
367         CheckAnswers();
368         Locked = true;
369 [inclScorm1.2]
370         SetScormTimedOut();
371 [/inclScorm1.2]
373 [/inclTimer]