3 //JCLOZE-SPECIFIC SCORM-RELATED JAVASCRIPT CODE
5 function SetScormScore(){
6 //Reports the current score and any other information back to the LMS
8 API.LMSSetValue('cmi.core.score.raw', Score);
9 //Now send detailed reports about each item
10 for (var i=0; i<State.length; i++){
11 var ThisItemGuesses = '';
12 var GapLabel = 'Gap_' + (i+1).toString();
13 var ThisItemScore = Math.floor(State[i].ItemScore * 100) + '';
14 API.LMSSetValue('cmi.objectives.' + i + '.id', 'obj'+GapLabel);
15 API.LMSSetValue('cmi.interactions.' + i + '.id', 'int'+GapLabel);
16 API.LMSSetValue('cmi.objectives.' + i + '.score.raw', ThisItemScore);
17 API.LMSSetValue('cmi.objectives.' + i + '.score.min', '0');
18 API.LMSSetValue('cmi.objectives.' + i + '.score.max', '100');
19 if (State[i].AnsweredCorrectly == true){
20 API.LMSSetValue('cmi.objectives.' + i + '.status', 'completed');
23 API.LMSSetValue('cmi.objectives.' + i + '.status', 'incomplete');
25 for (var j=0; j<State[i].Guesses.length; j++){
26 if (j>0){ThisItemGuesses += ' | ';}
27 ThisItemGuesses += State[i].Guesses[j];
29 API.LMSSetValue('cmi.interactions.' + i + '.type', 'fill-in');
30 API.LMSSetValue('cmi.interactions.' + i + '.student_response', ThisItemGuesses);
37 //JCLOZE CORE JAVASCRIPT CODE
40 this.ClueGiven = false;
41 this.HintsAndChecks = 0;
42 this.MatchedAnswerLength = 0;
44 this.AnsweredCorrectly = false;
45 this.Guesses = new Array();
50 var Correct = '[strCorrect]';
51 var Incorrect = '[strIncorrect]';
52 var GiveHint = '[strGiveHint]';
53 var CaseSensitive = [boolCaseSensitive];
54 var YourScoreIs = '[strYourScoreIs]';
68 RemoveBottomNavBarForIE();
69 //Show a keypad if there is one (added bugfix for 6.0.4.12)
70 if (document.getElementById('CharacterKeypad') != null){
71 document.getElementById('CharacterKeypad').style.display = 'block';
83 PreloadImages([PreloadImageList]);
89 for (i=0; i<I.length; i++){
90 State[i] = new ItemState();
101 function ShowClue(ItemNum){
102 if (Locked == true){return;}
103 State[ItemNum].ClueGiven = true;
104 ShowMessage(I[ItemNum][2]);
107 function SaveCurrentAnswers(){
109 for (var i=0; i<I.length; i++){
110 Ans = GetGapValue(i);
111 if ((Ans.length > 0)&&(Ans != State[i].Guesses[State[i].Guesses.length-1])){
112 State[i].Guesses[State[i].Guesses.length] = Ans;
117 function CompileGuesses(){
118 var F = document.getElementById('store');
120 var Temp = '<?xml version="1.0"?><hpnetresult><fields>';
122 for (var i=0; i<State.length; i++){
123 GapLabel = 'Gap ' + (i+1).toString();
124 Temp += '<field><fieldname>' + GapLabel + '</fieldname>';
125 Temp += '<fieldtype>student-responses</fieldtype><fieldlabel>' + GapLabel + '</fieldlabel>';
126 Temp += '<fieldlabelid>JClozeStudentResponses</fieldlabelid><fielddata>';
127 for (var j=0; j<State[i].Guesses.length; j++){
128 if (j>0){Temp += '| ';}
129 Temp += State[i].Guesses[j] + ' ';
131 Temp += '</fielddata></field>';
133 Temp += '</fields></hpnetresult>';
138 function CheckAnswers(){
139 if (Locked == true){return;}
140 SaveCurrentAnswers();
141 var AllCorrect = true;
144 for (var i = 0; i<I.length; i++){
146 if (State[i].AnsweredCorrectly == false){
147 //If it's right, calculate its score
148 if (CheckAnswer(i, true) > -1){
149 var TotalChars = GetGapValue(i).length;
150 State[i].ItemScore = (TotalChars-State[i].HintsAndChecks)/TotalChars;
151 if (State[i].ClueGiven == true){State[i].ItemScore /= 2;}
152 if (State[i].ItemScore <0 ){State[i].ItemScore = 0;}
153 State[i].AnsweredCorrectly = true;
154 //Drop the correct answer into the page, replacing the text box
155 SetCorrectAnswer(i, GetGapValue(i));
158 //Otherwise, increment the hints for this item, as a penalty
159 State[i].HintsAndChecks++;
167 //Calculate the total score
169 for (i=0; i<State.length; i++){
170 TotalScore += State[i].ItemScore;
172 TotalScore = Math.floor((TotalScore * 100)/I.length);
177 if (AllCorrect == true){
178 Output = Correct + '<br />';
181 Output += YourScoreIs + ' ' + TotalScore + '%.<br />';
182 if (AllCorrect == false){
183 Output += '<br />' + Incorrect;
186 setTimeout('WriteToInstructions(Output)', 50);
191 if ((AllCorrect == true)||(Finished == true)){
194 setTimeout('SendResults(' + TotalScore + ')', 50);
197 window.clearInterval(Interval);
202 setTimeout('Finish()', SubmissionTimeout);
205 if (AllCorrect == true){
209 SetScormIncomplete();
214 function TrackFocus(BoxNumber){
215 CurrentWord = BoxNumber;
223 function CheckBeginning(Guess, Answer){
227 var UpperAnswer = '';
229 if (CaseSensitive == false) {
230 UpperGuess = Guess.toUpperCase();
231 UpperAnswer = Answer.toUpperCase();
235 UpperAnswer = Answer;
238 while (UpperGuess.charAt(i) == UpperAnswer.charAt(i)) {
239 OutString += Guess.charAt(i);
242 OutString += Answer.charAt(i);
246 function GetGapValue(GNum){
248 if ((GNum<0)||(GNum>=I.length)){return RetVal;}
249 if (document.getElementById('Gap' + GNum) != null){
250 RetVal = document.getElementById('Gap' + GNum).value;
251 RetVal = TrimString(RetVal);
254 RetVal = State[GNum].Guesses[State[GNum].Guesses.length-1];
259 function SetGapValue(GNum, Val){
260 if ((GNum<0)||(GNum>=I.length)){return;}
261 if (document.getElementById('Gap' + GNum) != null){
262 document.getElementById('Gap' + GNum).value = Val;
263 document.getElementById('Gap' + GNum).focus();
267 function SetCorrectAnswer(GNum, Val){
268 if ((GNum<0)||(GNum>=I.length)){return;}
269 if (document.getElementById('GapSpan' + GNum) != null){
270 document.getElementById('GapSpan' + GNum).innerHTML = Val;
274 function FindCurrent() {
278 //Test the current word:
279 //If its state is not set to already correct, check the word.
280 if (State[CurrentWord].AnsweredCorrectly == false){
281 if (CheckAnswer(CurrentWord, false) < 0){
288 if (State[x].AnsweredCorrectly == false){
289 if (CheckAnswer(x, false) < 0){
297 while (x<CurrentWord){
298 if (State[x].AnsweredCorrectly == false){
299 if (CheckAnswer(x, false) < 0){
308 function CheckAnswer(GapNum, MarkAnswer){
309 var Guess = GetGapValue(GapNum);
311 var UpperAnswer = '';
312 if (CaseSensitive == false){
313 UpperGuess = Guess.toUpperCase();
319 for (var i = 0; i<I[GapNum][1].length; i++){
320 if (CaseSensitive == false){
321 UpperAnswer = I[GapNum][1][i][0].toUpperCase();
324 UpperAnswer = I[GapNum][1][i][0];
326 if (TrimString(UpperGuess) == UpperAnswer){
328 if (MarkAnswer == true){
329 State[GapNum].AnsweredCorrectly = true;
336 function GetHint(GapNum){
337 Guess = GetGapValue(GapNum);
339 if (CheckAnswer(GapNum, false) > -1){return ''}
340 RightBits = new Array();
341 for (var i=0; i<I[GapNum][1].length; i++){
342 RightBits[i] = CheckBeginning(Guess, I[GapNum][1][i][0]);
344 var RightOne = FindLongest(RightBits);
345 var Result = I[GapNum][1][RightOne][0].substring(0,RightBits[RightOne].length);
346 //Add another char if the last one is a space
347 if (Result.charAt(Result.length-1) == ' '){
348 Result = I[GapNum][1][RightOne][0].substring(0,RightBits[RightOne].length+1);
354 if (document.getElementById('FeedbackDiv').style.display == 'block'){return;}
355 if (Locked == true){return;}
356 var CurrGap = FindCurrent();
357 if (CurrGap < 0){return;}
359 var HintString = GetHint(CurrGap);
361 if (HintString.length > 0){
362 SetGapValue(CurrGap, HintString);
363 State[CurrGap].HintsAndChecks += 1;
365 ShowMessage(GiveHint);
368 function TypeChars(Chars){
369 var CurrGap = FindCurrent();
370 if (CurrGap < 0){return;}
371 if (document.getElementById('Gap' + CurrGap) != null){
372 SetGapValue(CurrGap, document.getElementById('Gap' + CurrGap).value + Chars);
378 document.getElementById('Timer').innerHTML = '[strTimesUp]';