]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-9280 - JavaScript countdown timer did not work in 1.8 due to XHTML strict changes...
authortjhunt <tjhunt>
Wed, 11 Apr 2007 20:07:36 +0000 (20:07 +0000)
committertjhunt <tjhunt>
Wed, 11 Apr 2007 20:07:36 +0000 (20:07 +0000)
mod/quiz/attempt.php
mod/quiz/jstimer.php
mod/quiz/timer.js

index b98d0c89a3c0b4a34b7d64b54cb5b9a5521c9342..583f0762fc904460e96a0ddeeb9f653a98da0a64 100644 (file)
         }
     }
 
-    // Start the form
+    echo "<form id=\"responseform\" method=\"post\" action=\"attempt.php\" onclick=\"this.autocomplete='off'\">\n";
     if($quiz->timelimit > 0) {
         // Make sure javascript is enabled for time limited quizzes
         ?>
         <script type="text/javascript">
-        //<![CDATA[
-            document.write("<form id=\"responseform\" method=\"post\" action=\"attempt.php\" onclick=\"this.autocomplete='off'\">\n");
-        //]]>
+            // Do nothing.
         </script>
         <noscript>
         <div>
         </div>
         </noscript>
         <?php
-    } else {
-        echo "<form id=\"responseform\" method=\"post\" action=\"attempt.php\" onclick=\"this.autocomplete='off'\">\n";
     }
 
     // Add a hidden field with the quiz id
         echo "<input type=\"submit\" name=\"markall\" value=\"".get_string("markall", "quiz")."\" />\n";
     }
     echo "<input type=\"submit\" name=\"finishattempt\" value=\"".get_string("finishattempt", "quiz")."\" onclick=\"$onclick\" />\n";
-    echo '<input type="hidden" name="timeup" value="0" />';
+    echo '<input type="hidden" name="timeup" id="timeup" value="0" />';
 
     echo "</div>";
 
         // For teachers ignore the quiz closing time
         $secondsleft = 999999999999;
     }
+    
     // If time limit is set include floating timer.
     // MDL-7495, no timer for users with disability
-
-    if ($quiz->timelimit > 0 && !has_capability('mod/quiz:ignoretimelimits', $context)) {
-
+    if ($quiz->timelimit > 0 && !has_capability('mod/quiz:ignoretimelimits', $context, NULL, false)) {
         $timesincestart = time() - $attempt->timestart;
         $timerstartvalue = min($quiz->timelimit*60 - $timesincestart, $secondsleft);
         if ($timerstartvalue <= 0) {
index 2785f35c0e79b70a80f92135bacb05e574accf6e..adc64340256db4e564c32ebe29b4de4f69888bff 100644 (file)
@@ -47,8 +47,8 @@ var ec_quiz_finish = ec_page_start + <?php echo ($timerstartvalue * 1000); ?>;
 <script type="text/javascript">
 //<![CDATA[
 
-var timerbox = xGetElementById('timer');
-var theTimer = xGetElementById('QuizTimer');
+var timerbox = document.getElementById('timer');
+var theTimer = document.getElementById('QuizTimer');
 var theTop = 100;
 var old = theTop;
 
index 41a57f09608977b190c56d0fdda7eb9ad1fd1f71..b21b57f113eaa0714db52bb47dd1da8af6a4bf72 100644 (file)
@@ -7,16 +7,12 @@
 function countdown_clock(theTimer) {
     var timeout_id = null;
 
-    // @EC PF : current client time
-    var ec_now_epoch = new Date().getTime();
-
-    // @EC PF : time left according to client
-    quizTimerValue = Math.floor( (ec_quiz_finish - ec_now_epoch) /1000 );
+    quizTimerValue = Math.floor((ec_quiz_finish - new Date().getTime())/1000);
 
     if(quizTimerValue <= 0) {
         clearTimeout(timeout_id);
-        var ourForm = document.forms['responseform'];
-        ourForm.timeup.value = 1;
+        document.getElementById('timeup').value = 1;
+        var ourForm = document.getElementById('responseform');
         if (ourForm.onsubmit) { 
             ourForm.onsubmit();
         }
@@ -25,14 +21,11 @@ function countdown_clock(theTimer) {
     }
 
     now = quizTimerValue;
-    var hours = Math.floor( now / 3600 );
-    parseInt(hours);
-    now = now - (hours * 3600);
-    var minutes = Math.floor(now / 60);
-    parseInt(minutes);
-    now = now - (minutes * 60);
+    var hours = Math.floor(now/3600);
+    now = now - (hours*3600);
+    var minutes = Math.floor(now/60);
+    now = now - (minutes*60);
     var seconds = now;
-    parseInt(seconds);
 
     var t = "" + hours;
     t += ((minutes < 10) ? ":0" : ":") + minutes;
@@ -45,12 +38,11 @@ function countdown_clock(theTimer) {
         var col = '#' + 'ff' + hexascii.charAt(seconds) + '0' + hexascii.charAt(seconds) + 0;
         theTimer.style.backgroundColor = col;
     }
-    document.forms['clock'].time.value = t.toString();
+    document.getElementById('time').value = t.toString();
     timeout_id = setTimeout("countdown_clock(theTimer)", 1000);
 }
 
 function movecounter(timerbox) {
-
     var pos;
 
     if (window.innerHeight) {
@@ -58,7 +50,7 @@ function movecounter(timerbox) {
     } else if (document.documentElement && document.documentElement.scrollTop) {
         pos = document.documentElement.scrollTop
     } else if (document.body) {
-          pos = document.body.scrollTop
+        pos = document.body.scrollTop
     }
 
     if (pos < theTop) {
@@ -71,13 +63,4 @@ function movecounter(timerbox) {
     }
     old = pos;
     temp = setTimeout('movecounter(timerbox)',100);
-}
-
-function xGetElementById(e)
-{
-  if(typeof(e)!='string') return e;
-  if(document.getElementById) e=document.getElementById(e);
-  else if(document.all) e=document.all[e];
-  else e=null;
-  return e;
-}
+}
\ No newline at end of file