Incorrect variable name used for parameter.
[moodle-linuxchix.git] / mod / hotpot / v6 / source / djmatch6.js_
blob0a051d88a9768d5625412217c7a2fbec1b215e9b
1 \r
2 var CorrectResponse = '[strGuessCorrect]';\r
3 var IncorrectResponse = '[strGuessIncorrect]';\r
4 var YourScoreIs = '[strYourScoreIs]';\r
5 var DivWidth = 600; //default value\r
6 var FeedbackWidth = 200; //default\r
7 var ExBGColor = '[strExBGColor]';\r
8 var PageBGColor = '[strPageBGColor]';\r
9 var TextColor = '[strTextColor]';\r
10 var TitleColor = '[strTitleColor]';\r
11 var Penalties = 0;\r
12 var Score = 0;\r
13 var TimeOver = false;\r
14 var Locked = false;\r
15 var ShuffleQs = [boolShuffleQs];\r
16 var QsToShow = [QsToShow];\r
18 var DragWidth = 200;\r
19 var LeftColPos = 100;\r
20 var RightColPos = 500;\r
21 var DragTop = 120;\r
22 var Finished = false;\r
24 //Fixed and draggable card arrays\r
25 FC = new Array();\r
26 DC = new Array();\r
28 function onEndDrag(){ \r
29 //Is it dropped on any of the fixed cards?\r
30         var Docked = false;\r
31         var DropTarget = DroppedOnFixed(CurrDrag);\r
32         if (DropTarget > -1){\r
33 //If so, send home any card that is currently docked there\r
34                 for (var i=0; i<DC.length; i++){\r
35                         if (DC[i].tag == DropTarget+1){\r
36                                 DC[i].GoHome();\r
37                                 DC[i].tag = 0;\r
38                                 D[i][2] = 0;\r
39                         }\r
40                 }\r
41 //Dock the dropped card\r
42                 DC[CurrDrag].DockToR(FC[DropTarget]);\r
43                 D[CurrDrag][2] = F[DropTarget][1];\r
44                 DC[CurrDrag].tag = DropTarget+1;\r
45                 Docked = true;\r
46         }\r
48         if (Docked == false){\r
49                 DC[CurrDrag].GoHome();\r
50                 DC[CurrDrag].tag = 0;\r
51                 D[CurrDrag][2] = 0;\r
52         }\r
53 \r
55 function DroppedOnFixed(DNum){\r
56         var Result = -1;\r
57         var OverlapArea = 0;\r
58         var Temp = 0;\r
59         for (var i=0; i<FC.length; i++){\r
60                 Temp = DC[DNum].Overlap(FC[i]);\r
61                 if (Temp > OverlapArea){\r
62                         OverlapArea = Temp;\r
63                         Result = i;\r
64                 }\r
65         }\r
66         return Result;\r
67 }\r
70 function StartUp(){\r
72 [inclSendResults]\r
73         GetUserName();\r
74 [/inclSendResults]\r
76 [inclPreloadImages]\r
77         PreloadImages([PreloadImageList]);\r
78 [/inclPreloadImages]\r
80 //Calculate page dimensions and positions\r
81         pg = new PageDim();\r
82         DivWidth = Math.floor((pg.W*4)/5);\r
83         DragWidth = Math.floor((DivWidth*3)/10);\r
84         LeftColPos = Math.floor(pg.W/15);\r
85         RightColPos = pg.W - (DragWidth + LeftColPos);\r
86         DragTop = parseInt(document.getElementById('CheckButtonDiv').offsetHeight) + parseInt(document.getElementById('CheckButtonDiv').offsetTop) + 10;\r
88         if (C.ie){\r
89                 DragTop += 15;\r
90         }\r
91         \r
92 //Reduce array if required\r
93         if (QsToShow < F.length){\r
94                 ReduceItems2();\r
95         }\r
96         \r
97 //Shuffle the left items if required\r
98         if (ShuffleQs == true){\r
99                 F = Shuffle(F);\r
100         }\r
102 //Shuffle the items on the right\r
103         D = Shuffle(D);\r
105         var CurrTop = DragTop;\r
106         var TempInt = 0;\r
107         var DropHome = 0;\r
108         var Widest = 0;\r
109         var CardContent = '';\r
110         for (var i=0; i<F.length; i++){\r
111                 CardContent = F[i][0];\r
112                 FC[i] = new Card('F' + i, 10);\r
113                 FC[i].elm.innerHTML = CardContent; \r
114                 if (FC[i].GetW() > Widest){\r
115                         Widest = FC[i].GetW();\r
116                 }\r
117         }\r
119         if (Widest > DragWidth){Widest = DragWidth;}\r
121         CurrTop = DragTop;\r
123         DragWidth = Math.floor((DivWidth-Widest)/2) - 24;\r
124         RightColPos = DivWidth + LeftColPos - (DragWidth + 14);\r
125         var Highest = 0;\r
126         var WidestRight = 0;\r
128         for (i=0; i<D.length; i++){\r
129                 DC[i] = new Card('D' + i, 10);\r
130                 CardContent = D[i][0];\r
131 //              if (CardContent.indexOf('<img ') > -1){CardContent += '<br clear="all" />';} //used to be required for Navigator rendering bug with images\r
132                 DC[i].elm.innerHTML = CardContent; \r
133                 if (DC[i].GetW() > DragWidth){DC[i].SetW(DragWidth);}\r
134                 DC[i].css.cursor = 'move';\r
135                 DC[i].css.backgroundColor = '[strExBGColor]';\r
136                 DC[i].css.color = '[strTextColor]';\r
137                 TempInt = DC[i].GetH();\r
138                 if (TempInt > Highest){Highest = TempInt;}\r
139                 TempInt = DC[i].GetW();\r
140                 if (TempInt > WidestRight){WidestRight = TempInt;}\r
141         }\r
143         var HeightToSet = Highest;\r
144         if (C.gecko||C.ie5mac){HeightToSet -= 12;}\r
145         var WidthToSet = WidestRight;\r
146         if (C.gecko||C.ie5mac){WidthToSet -= 12;}\r
148         for (i=0; i<D.length; i++){\r
149                 DC[i].SetT(CurrTop);\r
150                 DC[i].SetL(RightColPos);\r
151                 if (DC[i].GetH() < Highest){\r
152                         DC[i].SetH(HeightToSet);\r
153                 }\r
154                 if (DC[i].GetW() < WidestRight){\r
155                         DC[i].SetW(WidthToSet);\r
156                 }\r
157                 DC[i].SetHome();\r
158                 DC[i].tag = -1;\r
159                 CurrTop = CurrTop + DC[i].GetH() + 5;\r
160         }\r
162         CurrTop = DragTop;\r
164         for (var i=0; i<F.length; i++){\r
165                 FC[i].SetW(Widest);\r
166                 if (FC[i].GetH() < Highest){\r
167                         FC[i].SetH(HeightToSet);\r
168                 }\r
169                 FC[i].SetT(CurrTop);\r
170                 FC[i].SetL(LeftColPos);\r
171                 FC[i].SetHome();\r
172                 TempInt = FC[i].GetH();\r
173                 CurrTop = CurrTop + TempInt + 5;\r
174         }\r
176 [inclSlide]\r
177 //Slide any elements that should be in position over\r
178         for (i=0; i<D.length; i++){\r
179                 if (D[i][2] > 0){\r
180                         DC[i].tag = D[i][1];\r
181                         D[i][2] = D[i][1];\r
182                         var TopChange = 0;\r
183 //Find the right target element\r
184                         var TargItem = -1;\r
185                         for (var j=0; j<F.length; j++){\r
186                                 if (F[j][1] == D[i][1]){\r
187                                         TargItem = j;\r
188                                 }\r
189                         }\r
190                         var TargetLeft = FC[TargItem].GetR() + 5;\r
191                         var TargetTop = FC[TargItem].GetT();\r
193                         if (TargetTop < DC[i].GetT()){\r
194                                 TopChange = -1;\r
195                         }\r
196                         else {\r
197                                 if (TargetTop > DC[i].GetT()){\r
198                                         TopChange = 1;\r
199                                 }\r
200                         }\r
201                         Slide(i, TargetLeft, TargetTop, TopChange);\r
202                         D[i][2] = F[TargItem][1];\r
203                         DC[i].tag = TargItem+1;\r
204                 }\r
205         }\r
206 [/inclSlide]\r
207 [inclTimer]\r
208         StartTimer();\r
209 [/inclTimer]\r
212 [inclSlide]\r
213 function Slide(MoverNum, TargL, TargT, TopChange){\r
214         var TempInt = DC[MoverNum].GetL();\r
215         if (TempInt > TargL){\r
216                 DC[MoverNum].SetL(TempInt - 5);\r
217         }\r
218         TempInt = DC[MoverNum].GetT();\r
219         if (TempInt != TargT){\r
220                 DC[MoverNum].SetT(TempInt + TopChange);\r
221         }\r
222         if ((DC[MoverNum].GetL() > TargL)||(DC[MoverNum].GetT() != TargT)){\r
223                 setTimeout('Slide('+MoverNum+','+TargL+','+TargT+','+TopChange+')', 1);\r
224         }\r
225         else{\r
226                 DC[MoverNum].SetL(TargL);\r
227         }\r
229 [/inclSlide]\r
231 F = new Array();\r
232 [FixedArray]\r
234 D = new Array();\r
235 [DragArray]\r
237 function ReduceItems2(){\r
238         var ItemToDump=0;\r
239         var j=0;\r
240         while (F.length > QsToShow){\r
241                 ItemToDump = Math.floor(F.length*Math.random());\r
242                 for (j=ItemToDump; j<(F.length-1); j++){\r
243                         F[j] = F[j+1];\r
244                 }\r
245                 for (j=ItemToDump; j<(D.length-1); j++){\r
246                         D[j] = D[j+1];\r
247                 }               \r
248                 F.length = F.length-1;\r
249                 D.length = D.length-1;\r
250         }\r
253 function TimerStartUp(){\r
254         setTimeout('StartUp()', 300);\r
257 function CheckAnswers(){\r
258         if (Locked == true){return;}\r
259 //Set the default score and response\r
260         var TotalCorrect = 0;\r
261         Score = 0;\r
262         var Feedback = '';\r
264 //for each fixed, check to see if the tag value for the draggable is the same as the fixed\r
265         var i, j;\r
266         for (i=0; i<D.length; i++){\r
267                 if ((D[i][2] == D[i][1])&&(D[i][2] > 0)){\r
268                         TotalCorrect++;\r
269                 }\r
270                 else{\r
271 //Change made for version 6.0.3.41: don't send wrong items home, \r
272 //show them in a more conspicuous way.\r
273 //                      DC[i].GoHome();\r
274                                 DC[i].SetL(DC[i].GetL() + 10);\r
275                                 DC[i].Highlight();\r
276                 }\r
277         }\r
279         Score = Math.floor((100*(TotalCorrect-Penalties))/F.length);\r
281         var AllDone = false;\r
283         if (TotalCorrect == F.length) {\r
284                 AllDone = true;\r
285         }\r
287         if (AllDone == true){\r
288                 Feedback = YourScoreIs + ' ' + Score + '%.';\r
289                 ShowMessage(Feedback + '<br />' + CorrectResponse);\r
290         }\r
291         else {\r
292                 Feedback = IncorrectResponse + '<br />' + YourScoreIs + ' ' + Score + '%.';\r
293                 ShowMessage(Feedback);\r
294                 Penalties++; // Penalty for inaccurate check\r
295         }\r
296 //If the exercise is over, deal with that\r
297         if ((AllDone == true)||(TimeOver == true)){\r
298 [inclSendResults]\r
299                 setTimeout('SendResults(' + Score + ')', 50);\r
300 [/inclSendResults]\r
301 [inclTimer]\r
302                 window.clearInterval(Interval);\r
303 [/inclTimer]\r
304                 TimeOver = true;\r
305                 Locked = true;\r
306                 Finished = true;\r
307                 setTimeout('Finish()', SubmissionTimeout);\r
308                 WriteToInstructions(Feedback);\r
309         }\r
312 [inclTimer]\r
313 function TimesUp() {\r
314         document.getElementById('Timer').innerHTML = '[strTimesUp]';\r
315 [inclPreloadImages]\r
316         RefreshImages();\r
317 [/inclPreloadImages]\r
318         TimeOver = true;\r
319         CheckAnswers();\r
320         Locked = true;\r
322 [/inclTimer]\r