adding some strings
[moodle-linuxchix.git] / mod / hotpot / template / v6 / djmatch6.js_
blob65a148a9472ca44ed15ce3d25b2ad0560b115e8a
2 [inclScorm1.2]
3 //JMATCH-SPECIFIC SCORM-RELATED JAVASCRIPT CODE
5 function SetScormScore(){
6 //Reports the current score and any other information back to the LMS
7         if (API != null){
8                 API.LMSSetValue('cmi.core.score.raw', Score);
9                 
10                 
11 //Now send a detailed reports on the item
12                 var ItemLabel = 'Matching';
13                 API.LMSSetValue('cmi.objectives.0.id', 'obj'+ItemLabel);
14                 API.LMSSetValue('cmi.interactions.0.id', 'int'+ItemLabel);      
15                 API.LMSSetValue('cmi.objectives.0.status', API.LMSGetValue('cmi.core.lesson_status'));  
16                 API.LMSSetValue('cmi.objectives.0.score.min', '0');
17                 API.LMSSetValue('cmi.objectives.0.score.max', '100');
18                 API.LMSSetValue('cmi.objectives.0.score.raw', Score);
19 //We can only use the performance type, because we're storing multiple responses of various types.
20                 API.LMSSetValue('cmi.interactions.0.type', 'performance');
21                 API.LMSSetValue('cmi.interactions.0.student_response', AnswersTried);
22                 
23                 API.LMSCommit('');
24         }
26 [/inclScorm1.2]
28 //JMATCH-SPECIFIC CORE JAVASCRIPT CODE
30 var CorrectResponse = '[strGuessCorrect]';
31 var IncorrectResponse = '[strGuessIncorrect]';
32 var YourScoreIs = '[strYourScoreIs]';
33 var DivWidth = 600; //default value
34 var FeedbackWidth = 200; //default
35 var ExBGColor = '[strExBGColor]';
36 var PageBGColor = '[strPageBGColor]';
37 var TextColor = '[strTextColor]';
38 var TitleColor = '[strTitleColor]';
39 var Penalties = 0;
40 var Score = 0;
41 var TimeOver = false;
42 var Locked = false;
43 var ShuffleQs = [boolShuffleQs];
44 var QsToShow = [QsToShow];
46 var DragWidth = 200;
47 var LeftColPos = 100;
48 var RightColPos = 500;
49 var DragTop = 120;
50 var Finished = false;
51 var AnswersTried = '';
53 //Fixed and draggable card arrays
54 FC = new Array();
55 DC = new Array();
57 function onEndDrag(){ 
58 //Is it dropped on any of the fixed cards?
59         var Docked = false;
60         var DropTarget = DroppedOnFixed(CurrDrag);
61         if (DropTarget > -1){
62 //If so, send home any card that is currently docked there
63                 for (var i=0; i<DC.length; i++){
64                         if (DC[i].tag == DropTarget+1){
65                                 DC[i].GoHome();
66                                 DC[i].tag = 0;
67                                 D[i][2] = 0;
68                         }
69                 }
70 //Dock the dropped card
71                 DC[CurrDrag].DockToR(FC[DropTarget]);
72                 D[CurrDrag][2] = F[DropTarget][1];
73                 DC[CurrDrag].tag = DropTarget+1;
74                 Docked = true;
75         }
77         if (Docked == false){
78                 DC[CurrDrag].GoHome();
79                 DC[CurrDrag].tag = 0;
80                 D[CurrDrag][2] = 0;
81         }
82
84 function DroppedOnFixed(DNum){
85         var Result = -1;
86         var OverlapArea = 0;
87         var Temp = 0;
88         for (var i=0; i<FC.length; i++){
89                 Temp = DC[DNum].Overlap(FC[i]);
90                 if (Temp > OverlapArea){
91                         OverlapArea = Temp;
92                         Result = i;
93                 }
94         }
95         return Result;
99 function StartUp(){
101 [inclScorm1.2]
102         ScormStartUp();
103 [/inclScorm1.2]
105 [inclSendResults]
106         GetUserName();
107 [/inclSendResults]
109 [inclPreloadImages]
110         PreloadImages([PreloadImageList]);
111 [/inclPreloadImages]
113 //Calculate page dimensions and positions
114         pg = new PageDim();
115         DivWidth = Math.floor((pg.W*4)/5);
116         DragWidth = Math.floor((DivWidth*3)/10);
117         LeftColPos = Math.floor(pg.W/15);
118         RightColPos = pg.W - (DragWidth + LeftColPos);
119         DragTop = parseInt(document.getElementById('CheckButtonDiv').offsetHeight) + parseInt(document.getElementById('CheckButtonDiv').offsetTop) + 10;
121         if (C.ie){
122                 DragTop += 15;
123         }
124         
125 //Reduce array if required
126         if (QsToShow < F.length){
127                 ReduceItems2();
128         }
129         
130 //Shuffle the left items if required
131         if (ShuffleQs == true){
132                 F = Shuffle(F);
133         }
135 //Shuffle the items on the right
136         D = Shuffle(D);
138         var CurrTop = DragTop;
139         var TempInt = 0;
140         var DropHome = 0;
141         var Widest = 0;
142         var CardContent = '';
143         for (var i=0; i<F.length; i++){
144                 CardContent = F[i][0];
145                 FC[i] = new Card('F' + i, 10);
146                 FC[i].elm.innerHTML = CardContent; 
147                 if (FC[i].GetW() > Widest){
148                         Widest = FC[i].GetW();
149                 }
150         }
152         if (Widest > DragWidth){Widest = DragWidth;}
154         CurrTop = DragTop;
156         DragWidth = Math.floor((DivWidth-Widest)/2) - 24;
157         RightColPos = DivWidth + LeftColPos - (DragWidth + 14);
158         var Highest = 0;
159         var WidestRight = 0;
161         for (i=0; i<D.length; i++){
162                 DC[i] = new Card('D' + i, 10);
163                 CardContent = D[i][0];
164 //              if (CardContent.indexOf('<img ') > -1){CardContent += '<br clear="all" />';} //used to be required for Navigator rendering bug with images
165                 DC[i].elm.innerHTML = CardContent; 
166                 if (DC[i].GetW() > DragWidth){DC[i].SetW(DragWidth);}
167                 DC[i].css.cursor = 'move';
168                 DC[i].css.backgroundColor = '[strExBGColor]';
169                 DC[i].css.color = '[strTextColor]';
170                 TempInt = DC[i].GetH();
171                 if (TempInt > Highest){Highest = TempInt;}
172                 TempInt = DC[i].GetW();
173                 if (TempInt > WidestRight){WidestRight = TempInt;}
174         }
176 //Fix for 6.2: the reduction by 12 seems to be required -- no idea why!
177         var HeightToSet = Highest-12;
178         var WidthToSet = WidestRight-12;
180         for (i=0; i<D.length; i++){
181                 DC[i].SetT(CurrTop);
182                 DC[i].SetL(RightColPos);
183                 if (DC[i].GetH() < Highest){
184                         DC[i].SetH(HeightToSet);
185                 }
186                 if (DC[i].GetW() < WidestRight){
187                         DC[i].SetW(WidthToSet);
188                 }
189                 DC[i].SetHome();
190                 DC[i].tag = -1;
191                 CurrTop = CurrTop + DC[i].GetH() + 5;
192         }
194         CurrTop = DragTop;
196         for (var i=0; i<F.length; i++){
197                 FC[i].SetW(Widest);
198                 if (FC[i].GetH() < Highest){
199                         FC[i].SetH(HeightToSet);
200                 }
201                 FC[i].SetT(CurrTop);
202                 FC[i].SetL(LeftColPos);
203                 FC[i].SetHome();
204                 TempInt = FC[i].GetH();
205                 CurrTop = CurrTop + TempInt + 5;
206         }
208 [inclSlide]
209 //Slide any elements that should be in position over
210         for (i=0; i<D.length; i++){
211                 if (D[i][2] > 0){
212                         DC[i].tag = D[i][1];
213                         D[i][2] = D[i][1];
214                         var TopChange = 0;
215 //Find the right target element
216                         var TargItem = -1;
217                         for (var j=0; j<F.length; j++){
218                                 if (F[j][1] == D[i][1]){
219                                         TargItem = j;
220                                 }
221                         }
222                         var TargetLeft = FC[TargItem].GetR() + 5;
223                         var TargetTop = FC[TargItem].GetT();
225                         if (TargetTop < DC[i].GetT()){
226                                 TopChange = -1;
227                         }
228                         else {
229                                 if (TargetTop > DC[i].GetT()){
230                                         TopChange = 1;
231                                 }
232                         }
233                         Slide(i, TargetLeft, TargetTop, TopChange);
234                         D[i][2] = F[TargItem][1];
235                         DC[i].tag = TargItem+1;
236                 }
237         }
238 [/inclSlide]
239 [inclTimer]
240         StartTimer();
241 [/inclTimer]
244 [inclSlide]
245 function Slide(MoverNum, TargL, TargT, TopChange){
246         var TempInt = DC[MoverNum].GetL();
247         if (TempInt > TargL){
248                 DC[MoverNum].SetL(TempInt - 5);
249         }
250         TempInt = DC[MoverNum].GetT();
251         if (TempInt != TargT){
252                 DC[MoverNum].SetT(TempInt + TopChange);
253         }
254         if ((DC[MoverNum].GetL() > TargL)||(DC[MoverNum].GetT() != TargT)){
255                 setTimeout('Slide('+MoverNum+','+TargL+','+TargT+','+TopChange+')', 1);
256         }
257         else{
258                 DC[MoverNum].SetL(TargL);
259         }
261 [/inclSlide]
263 F = new Array();
264 [FixedArray]
266 D = new Array();
267 [DragArray]
269 function ReduceItems2(){
270         var ItemToDump=0;
271         var j=0;
272         while (F.length > QsToShow){
273                 ItemToDump = Math.floor(F.length*Math.random());
274                 for (j=ItemToDump; j<(F.length-1); j++){
275                         F[j] = F[j+1];
276                 }
277                 for (j=ItemToDump; j<(D.length-1); j++){
278                         D[j] = D[j+1];
279                 }               
280                 F.length = F.length-1;
281                 D.length = D.length-1;
282         }
285 function TimerStartUp(){
286         setTimeout('StartUp()', 300);
289 function CheckAnswers(){
290         if (Locked == true){return;}
291 //Set the default score and response
292         var TotalCorrect = 0;
293         Score = 0;
294         var Feedback = '';
296 //for each fixed, check to see if the tag value for the draggable is the same as the fixed
297         if (AnswersTried.length > 0){AnswersTried += ' | ';}
298         var i, j;
299         for (i=0; i<D.length; i++){
300                 if (i>0){AnswersTried += ',';}
301                 AnswersTried += D[i][1] + '.' + D[i][2] + '';
302                 if ((D[i][2] == D[i][1])&&(D[i][2] > 0)){
303                         TotalCorrect++;
304                 }
305                 else{
306 //Change made for version 6.0.3.41: don't send wrong items home, 
307 //show them in a more conspicuous way.
308 //                      DC[i].GoHome();
309                                 DC[i].SetL(DC[i].GetL() + 10);
310                                 DC[i].Highlight();
311                 }
312         }
314         Score = Math.floor((100*(TotalCorrect-Penalties))/F.length);
316         var AllDone = false;
318         if (TotalCorrect == F.length) {
319                 AllDone = true;
320         }
322         if (AllDone == true){
323                 Feedback = YourScoreIs + ' ' + Score + '%.';
324                 ShowMessage(Feedback + '<br />' + CorrectResponse);
325         }
326         else {
327                 Feedback = IncorrectResponse + '<br />' + YourScoreIs + ' ' + Score + '%.';
328                 ShowMessage(Feedback);
329                 Penalties++; // Penalty for inaccurate check
330         }
331 //If the exercise is over, deal with that
332         if ((AllDone == true)||(TimeOver == true)){
333 [inclSendResults]
334                 setTimeout('SendResults(' + Score + ')', 50);
335 [/inclSendResults]
336 [inclTimer]
337                 window.clearInterval(Interval);
338 [/inclTimer]
339                 TimeOver = true;
340                 Locked = true;
341                 Finished = true;
342                 setTimeout('Finish()', SubmissionTimeout);
343                 WriteToInstructions(Feedback);
344         }
345 [inclScorm1.2]
346         if (AllDone == true){
347                 SetScormComplete();
348         }
349         else{
350                 SetScormIncomplete();
351         }
352 [/inclScorm1.2]
355 [inclTimer]
356 function TimesUp() {
357         document.getElementById('Timer').innerHTML = '[strTimesUp]';
358 [inclPreloadImages]
359         RefreshImages();
360 [/inclPreloadImages]
361         TimeOver = true;
362         CheckAnswers();
363         Locked = true;
364 [inclScorm1.2]
365         SetScormTimedOut();
366 [/inclScorm1.2]
368 [/inclTimer]