2 * JavaScript library for the quiz module.
4 * (c) The Open University and others.
5 * @author T.J.Hunt@open.ac.uk and others.
6 * @license http://www.gnu.org/copyleft/gpl.html GNU Public License
9 /* Used by quiz navigation links to force a form submit, and hence save the user's data. */
10 function navigate(page
) {
11 var ourForm
= document
.getElementById('responseform');
12 ourForm
.action
= ourForm
.action
.replace(/page=.*/, 'page=' + page
);
13 if (ourForm
.onsubmit
) {
19 /* Use this in an onkeypress handler, to stop enter submitting the forum unless you
20 are actually on the submit button. Don't stop the user typing things in text areas. */
21 function check_enter(e
) {
22 var target
= e
.target
? e
.target
: e
.srcElement
;
23 var keyCode
= e
.keyCode
? e
.keyCode
: e
.which
;
24 if (keyCode
==13 && target
.nodeName
.toLowerCase()!='a' &&
25 (!target
.type
|| !(target
.type
=='submit' || target
.type
=='textarea'))) {
32 /* Used to update the on-screen countdown clock for quizzes with a time limit */
33 function countdown_clock(theTimer
) {
34 var timeout_id
= null;
36 quizTimerValue
= Math
.floor((ec_quiz_finish
- new Date().getTime())/1000);
38 if(quizTimerValue
<= 0) {
39 clearTimeout(timeout_id
);
40 document
.getElementById('timeup').value
= 1;
41 var ourForm
= document
.getElementById('responseform');
42 if (ourForm
.onsubmit
) {
50 var hours
= Math
.floor(now
/3600);
51 now
= now
- (hours
*3600);
52 var minutes
= Math
.floor(now
/60);
53 now
= now
- (minutes
*60);
57 t
+= ((minutes
< 10) ? ":0" : ":") + minutes
;
58 t
+= ((seconds
< 10) ? ":0" : ":") + seconds
;
59 window
.status
= t
.toString();
61 if(hours
== 0 && minutes
== 0 && seconds
<= 15) {
62 //go from fff0f0 to ffe0e0 to ffd0d0...ff2020, ff1010, ff0000 in 15 steps
63 var hexascii
= "0123456789ABCDEF";
64 var col
= '#' + 'ff' + hexascii
.charAt(seconds
) + '0' + hexascii
.charAt(seconds
) + 0;
65 theTimer
.style
.backgroundColor
= col
;
67 document
.getElementById('time').value
= t
.toString();
68 timeout_id
= setTimeout("countdown_clock(theTimer)", 1000);
71 /* Use to keep the quiz timer on-screen as the user scrolls. */
72 function movecounter(timerbox
) {
75 if (window
.innerHeight
) {
76 pos
= window
.pageYOffset
77 } else if (document
.documentElement
&& document
.documentElement
.scrollTop
) {
78 pos
= document
.documentElement
.scrollTop
79 } else if (document
.body
) {
80 pos
= document
.body
.scrollTop
89 timerbox
.style
.top
= pos
+ 'px';
92 temp
= setTimeout('movecounter(timerbox)',100);