Permalink
Browse files

add HP 6.2 templates; add compatability with Safari (Mac browser); mi…

…croincrement version to 2006082901 (release 2.1.24)
  • Loading branch information...
1 parent dad0965 commit f7fe32525afbcf530a069ae43fe6ccb20c2f6ce3 gbateson committed May 1, 2007
View
@@ -1,5 +1,5 @@
===============================================
-This is v2.1.23 of the HotPot module for Moodle
+This is v2.1.24 of the HotPot module for Moodle
===============================================
This module allows teachers to administer Hot Potatoes and TexToys quizzes via Moodle.
View
@@ -1361,8 +1361,15 @@ function GetJQuizAnswerDetails(q, flag) {
var x = new Array();
} else {
// get required part of 'x' and convert to array
- var i = x.lastIndexOf('|');
- var x = x.substring((flag==2 ? (i+1) : 1), ((flag==0 || flag==2) ? x.length : i)).split('|');
+ if (x.charAt(0)=='|') {
+ // HP 6.0 and 6.1 (always has leading bar)
+ var i = x.lastIndexOf('|');
+ var x = x.substring((flag==2 ? (i+1) : 1), ((flag==0 || flag==2) ? x.length : i)).split('|');
+ } else {
+ // HP 6.2 (no leading delimiter)
+ var i = x.lastIndexOf(' | ');
+ var x = x.substring((flag==2 ? (i+3) : 0), ((flag==0 || flag==2) ? x.length : i)).split(' | ');
+ }
}
for (var i=0; i<x.length; i++) {
var a = new Array();
@@ -1378,14 +1385,33 @@ function GetJQuizAnswerDetails(q, flag) {
x[i] = a.join('+');
}
} else if (x) { // multiple-choice, short-answer and hybrid
- // remove trailing comma and convert to array
- x = x.substring(0, x.length-1).split(',');
+ if (x.charAt(x.length-1)==',') {
+ // HP 6.0 and 6.1 (always has trailing comma)
+ x = x.substring(0, x.length-1).split(',');
+ } else {
+ // HP 6.2 (short answer also contains student entered text)
+ x = x.split(' | ');
+ }
if (flag) {
var a = new Array();
if (flag==1 || flag==2 || flag==3) {
for (var i=0; i<x.length; i++) {
- var ii = I[q][3][(x[i].charCodeAt(0)-65)][2];
- if(((flag==1 || flag==2) && ii==1) || (flag==3 && ii==0)) a.push(x[i]);
+ var is_correct = false;
+ if (x[i].length==1) { // single letter
+ var ii = x[i].charCodeAt(0) - 65;
+ if (I[q][3] && I[q][3][ii] && I[q][3][ii][2]) {
+ var is_correct = true;
+ }
+ }
+ if (is_correct) {
+ if (flag==2) {
+ a.push(x[i]);
+ }
+ } else {
+ if (flag==1 || flag==3) {
+ a.push(x[i]);
+ }
+ }
}
}
if (flag==1) {
@@ -1406,8 +1432,12 @@ function GetJQuizAnswerDetails(q, flag) {
// convert answer indexes to values, if required
if (JQuiz[6]==false) {
for (var i=0; i<x.length; i++) {
- var ii = x[i].charCodeAt(0) - 65;
- x[i] = I[q][3][ii][0];
+ if (x[i].length==1) { // single letter
+ var ii = x[i].charCodeAt(0) - 65;
+ if (I[q][3] && I[q][3][ii]) {
+ x[i] = I[q][3][ii][0];
+ }
+ }
}
}
} else {
@@ -1518,7 +1548,7 @@ function hpClickClue(hp, t, v, args) {
}
function hpClickCheck(hp, t, v, args) {
if (t==2) { // JCloze
- if (v==5 || v==6) {
+ if (v==5 || v==6) {
var r = hpRottmeier();
var already_correct = 'true';
if (r==0) {
@@ -1799,7 +1829,7 @@ function hpClickCheck(hp, t, v, args) {
}
}
}
- return true;
+ //return true;
}
function hpClickCheckJCrossV5V6(hp, v, AD, q, row, col) {
// v is the version of Hot Potatoes
@@ -2020,12 +2050,19 @@ function getFuncCode(fn, extraCode, anchorCode, beforeAnchor) {
}
return s;
}
-function getArgsStr(args) {
+function getArgsStr(args, addQuotes) {
// make s(tring) version of function args array
var s = '';
var i_max = args.length;
for (var i=0; i<i_max; i++) {
- s += '"' + args[i] + '",';
+ if (addQuotes) {
+ s += '"' + args[i] + '",';
+ } else {
+ if (s) {
+ s += ',';
+ }
+ s += args[i];
+ }
}
return s;
}
@@ -2170,6 +2207,38 @@ function hpFeedback() {
// ********************
// intercept clicks
// ********************
+function hpNewFunction(f, a, s) {
+ if (window.C && C.safari) {
+ if (f=='CheckAnswers') {
+ if (s.indexOf('TotalChars-State[i].HintsAndChecks/')>=0) {
+ // special fix for "CheckAnswers" in JCloze
+ s = s.replace(/TotalChars-State\[i\]\.HintsAndChecks/g, '(TotalChars-State[i].HintsAndChecks)');
+ }
+ if (s.indexOf('CorrectLetters-Penalties/')>=0) {
+ // special fix for "CheckAnswers" in JMatch
+ s = s.replace(/CorrectLetters-Penalties/g, '(CorrectLetters-Penalties)');
+ }
+ if (s.indexOf('TotCorrectChoices-Penalties/')>=0) {
+ // special fix for "CheckAnswers" in JMix (v6)
+ s = s.replace(/TotCorrectChoices-Penalties/g, '(TotCorrectChoices-Penalties)');
+ }
+ if (s.indexOf('TotalCorrect-Penalties/')>=0) {
+ // special fix for "CheckAnswers" in JMix (v6+) Drag-and_Drop
+ s = s.replace(/TotalCorrect-Penalties/g, '(TotalCorrect-Penalties)');
+ }
+ }
+ if (s.indexOf('replace(\\[')>=0) {
+ s = s.replace(/\\\[/g, '/\\[');
+ s = s.replace(/\\\]/g, '\\]/g');
+ }
+ if (s.indexOf('for (i')>=0) {
+ s = s.replace(/for \(/g, 'for (var ');
+ }
+ eval('window.' + f + '=function(' + getArgsStr(a) + '){' + s + '}');
+ } else {
+ eval('window.' + f + '=new Function(' + getArgsStr(a, true) + 's);');
+ }
+}
function hpInterceptFeedback() {
// modify the function which writes feedback
// v6: ShowMessage(Feedback)
@@ -2194,7 +2263,7 @@ function hpInterceptFeedback() {
if (a[0] && window.FEEDBACK && FEEDBACK[0]) {
s = a[0] + "+='<br /><br />" + '<a href="javascript:hpFeedback();">' + FEEDBACK[6] + "</A>';" + s;
}
- eval('window.' + f + '=new Function(' + getArgsStr(a) + 's);');
+ hpNewFunction(f, a, s);
}
}
function hpInterceptHints() {
@@ -2257,7 +2326,7 @@ function hpInterceptHints() {
// add the e(x)tra code, if any, to the start of the hint (f)unction
if (x) {
var s = getFuncCode(f, x, '', true);
- eval('window.' + f + '=new Function(' + getArgsStr(a) + 's);');
+ hpNewFunction(f, a, s);
}
}
function hpInterceptClues() {
@@ -2312,7 +2381,8 @@ function hpInterceptClues() {
// add the e(x)tra code, if any, to the start of the clue (f)unction
if (x) {
var s = getFuncCode(f, x, '', true);
- eval('window.' + f + '=new Function(' + getArgsStr(a) + 's);');
+ var s = getFuncCode(f, '', '', true);
+ hpNewFunction(f, a, s);
}
}
function hpInterceptChecks() {
@@ -2354,7 +2424,7 @@ function hpInterceptChecks() {
if (x) {
x = "if(!Finished&&State[QNum].length&&State[QNum][0]<0){" + x + "hpClick(3,args)}";
var s = getFuncCode(f[i], x, '', true);
- eval('window.' + f[i] + '=new Function(' + getArgsStr(a) + 's);');
+ hpNewFunction(f[i], a, s);
}
}
}
@@ -2394,7 +2464,7 @@ function hpInterceptChecks() {
}
if (f) {
var s = getFuncCode(f, x, '', true);
- eval('window.' + f + '=new Function(' + getArgsStr(a) + 's);');
+ hpNewFunction(f, a, s);
}
// JMatch has three possible check functions, depending on the version
// (NB: other quiz types also have these functions)
@@ -2404,7 +2474,7 @@ function hpInterceptChecks() {
var a = getFuncArgs(f[i], true);
if (a.length==0) {
var s = getFuncCode(f[i], "hpClick(3);", '', true);
- eval('window.' + f[i] + '=new Function(' + getArgsStr(a) + 's);');
+ hpNewFunction(f[i], a, s);
break; // out of the loop
}
}
@@ -2690,7 +2760,13 @@ function hpScore() {
} else if (t==3) { // jcross
if (v==3) x = hpScoreEngine(1, CorrectAnswers, "document.QuizForm.elements[i*2].selectedIndex==a[i]");
else if (v==4) x = hpScoreEngine(1, WinLetters, "ConvertCase(GetBoxValue(i),1).charAt(0)==a[i].charAt(0)");
- else if (v==5 || v==6) x = hpScoreEngine(1, L, "", "L[i]", "L[i][ii] && L[i][ii]==G[i][ii]", "L[i][ii]");
+ else if (v==5 || v==6) {
+ if (window.CaseSensitive) { // HP 6.2
+ x = hpScoreEngine(1, L, "", "L[i]", "L[i][ii] && L[i][ii]==G[i][ii]", "L[i][ii]");
+ } else {
+ x = hpScoreEngine(1, L, "", "L[i]", "L[i][ii] && L[i][ii].toUpperCase()==G[i][ii].toUpperCase()", "L[i][ii]");
+ }
+ }
} else if (t==4) { // jmatch
if (v==3) x = hpScoreEngine(1, CorrectAnswers, "document.QuizForm.elements[i*2].selectedIndex==a[i]");
else if (v==4) x = hpScoreEngine(1, Draggables, "a[i].correct=='1'");
@@ -2771,7 +2847,13 @@ function hpFinished() {
} else if (t==3) { // jcross
if (v==3) x = hpFinishedEngine(document.Crossword.elements, "ConvertCase(is.mac?unescape(MacStringToWin(a[i].value)):a[i].value,1)!=Letters[i]");
else if (v==4) x = hpFinishedEngine(WinLetters, "ConvertCase(GetBoxValue(i),1).charAt(0) != a[i].charAt(0)");
- else if (v==5 || v==6) x = hpFinishedEngine(L, "", "L[i]", "L[i][ii] && L[i][ii]!=G[i][ii]");
+ else if (v==5 || v==6) {
+ if (window.CaseSensitive) { // 6.2
+ x = hpFinishedEngine(L, "", "L[i]", "L[i][ii] && L[i][ii]!=G[i][ii]");
+ } else {
+ x = hpFinishedEngine(L, "", "L[i]", "L[i][ii] && L[i][ii].toUpperCase()!=G[i][ii].toUpperCase()");
+ }
+ }
} else if (t==4) { // jmatch
if (v==3) x = hpFinishedEngine(CorrectAnswers, "document.QuizForm.elements[i*2].selectedIndex != a[i]");
else if (v==4) x = hpFinishedEngine(Draggables, "a[i].correct!='1'");
@@ -2830,9 +2912,9 @@ function hpIsStrict() {
// **************
// initialization
// **************
-hpInterceptFeedback();
-hpInterceptHints();
-hpInterceptClues();
+//hpInterceptFeedback();
+//hpInterceptHints();
+//hpInterceptClues();
hpInterceptChecks();
function hpFindForm(formname, w) {
if (w==null) w = self;
@@ -2896,8 +2978,13 @@ if (DB[7] && DB[8] && !is_LMS()) {
var p = getPrompt(window.GetUserName || window.StartUp);
var c = getStartUpCode(window.StartUp);
if (p && c) {
- window.StartUp = new Function('QuizLogin("' + p + '")');
- window.StartQuiz = new Function(c);
+ if (window.C && C.safari) {
+ eval('window.StartUp=function(){QuizLogin("' + p + '")}');
+ eval('window.StartQuiz=function(){' + c + '}');
+ } else {
+ window.StartUp = new Function('QuizLogin("' + p + '")');
+ window.StartQuiz = new Function(c);
+ }
// "QuizLogin" finshes by calling "StartQuiz"
}
// reassign the SendResults function
@@ -24,11 +24,11 @@ function expand_blocks($tag) {
// [1] the full block name (including optional leading 'str' or 'incl')
// [2] leading 'incl' or 'str', if any
// [3] the real block name ([1] without [2])
- $search = '/\[\/((incl|str)?(\w+))\]/';
+ $search = '/\[\/((incl|str)?((?:\w|\.)+))\]/';
preg_match_all($search, $this->$tag, $names);
$i_max = count($names[0]);
for ($i=0; $i<$i_max; $i++) {
- $method = $this->parent->template_dir.'_expand_'.$names[3][$i];
+ $method = $this->parent->template_dir.'_expand_'.str_replace('.', '', $names[3][$i]);
if (method_exists($this, $method)) {
eval('$value=$this->'.$method.'();');
$search = '/\['.$names[1][$i].'\](.*?)\[\/'.$names[1][$i].'\]/s';
@@ -323,6 +323,9 @@ function v6_expand_NavButtons() {
function v6_expand_NavBarJS() {
return $this->v6_expand_NavButtons();
}
+ function v6_expand_Scorm12() {
+ return false;
+ }
// js files (all quiz types)
@@ -29,6 +29,10 @@
<!--
+[inclScorm1.2]
+[strJSScorm_1_2]
+[/inclScorm1.2]
+
[strJSBrowserCheck]
[strJSButtons]
@@ -59,7 +63,7 @@
</head>
-<body onload="TimerStartUp()" id="TheBody">
+<body onload="TimerStartUp()" id="TheBody" [inclScorm1.2]onunload="CheckLMSFinish()"[/inclScorm1.2]>
<!-- BeginTopNavButtons -->
[inclNavButtons]
@@ -80,7 +84,7 @@
</div>
<div id="InstructionsDiv" class="StdDiv">
- <p id="Instructions">[strInstructions]</p>
+ <div id="Instructions">[strInstructions]</div>
</div>
<div class="StdDiv" id="CheckButtonDiv">
Oops, something went wrong.

0 comments on commit f7fe325

Please sign in to comment.