From 86ccf19cdbaf8e33d4a4e23672a78a15011d11c7 Mon Sep 17 00:00:00 2001 From: tjhunt <tjhunt> Date: Wed, 11 Apr 2007 20:07:36 +0000 Subject: [PATCH] MDL-9280 - JavaScript countdown timer did not work in 1.8 due to XHTML strict changes. Also, fixing a few more XHTML strrrrict things in attempt.php. Merged from MOODLE_18_STABLE. --- mod/quiz/attempt.php | 15 +++++---------- mod/quiz/jstimer.php | 4 ++-- mod/quiz/timer.js | 37 ++++++++++--------------------------- 3 files changed, 17 insertions(+), 39 deletions(-) diff --git a/mod/quiz/attempt.php b/mod/quiz/attempt.php index b98d0c89a3..583f0762fc 100644 --- a/mod/quiz/attempt.php +++ b/mod/quiz/attempt.php @@ -429,14 +429,12 @@ } } - // 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> @@ -444,8 +442,6 @@ </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 @@ -502,7 +498,7 @@ 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>"; @@ -522,11 +518,10 @@ // 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) { diff --git a/mod/quiz/jstimer.php b/mod/quiz/jstimer.php index 2785f35c0e..adc6434025 100644 --- a/mod/quiz/jstimer.php +++ b/mod/quiz/jstimer.php @@ -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; diff --git a/mod/quiz/timer.js b/mod/quiz/timer.js index 41a57f0960..b21b57f113 100644 --- a/mod/quiz/timer.js +++ b/mod/quiz/timer.js @@ -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 -- 2.39.5