MDL-11517 reserved word MOD used in table alias in questions backup code
[moodle-pu.git] / mod / quiz / quiz.js
blobf7e24e6188090f5f777bd555cffadeb2793ddc62
1 /*
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
7 */
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) {
14 ourForm.onsubmit();
16 ourForm.submit();
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;
25 if(keyCode==13 && (!target.type || (target.type!='submit' && target.type!='textarea')))
26 return false;
27 else
28 return true;
31 /* Used to update the on-screen countdown clock for quizzes with a time limit */
32 function countdown_clock(theTimer) {
33 var timeout_id = null;
35 quizTimerValue = Math.floor((ec_quiz_finish - new Date().getTime())/1000);
37 if(quizTimerValue <= 0) {
38 clearTimeout(timeout_id);
39 document.getElementById('timeup').value = 1;
40 var ourForm = document.getElementById('responseform');
41 if (ourForm.onsubmit) {
42 ourForm.onsubmit();
44 ourForm.submit();
45 return;
48 now = quizTimerValue;
49 var hours = Math.floor(now/3600);
50 now = now - (hours*3600);
51 var minutes = Math.floor(now/60);
52 now = now - (minutes*60);
53 var seconds = now;
55 var t = "" + hours;
56 t += ((minutes < 10) ? ":0" : ":") + minutes;
57 t += ((seconds < 10) ? ":0" : ":") + seconds;
58 window.status = t.toString();
60 if(hours == 0 && minutes == 0 && seconds <= 15) {
61 //go from fff0f0 to ffe0e0 to ffd0d0...ff2020, ff1010, ff0000 in 15 steps
62 var hexascii = "0123456789ABCDEF";
63 var col = '#' + 'ff' + hexascii.charAt(seconds) + '0' + hexascii.charAt(seconds) + 0;
64 theTimer.style.backgroundColor = col;
66 document.getElementById('time').value = t.toString();
67 timeout_id = setTimeout("countdown_clock(theTimer)", 1000);
70 /* Use to keep the quiz timer on-screen as the user scrolls. */
71 function movecounter(timerbox) {
72 var pos;
74 if (window.innerHeight) {
75 pos = window.pageYOffset
76 } else if (document.documentElement && document.documentElement.scrollTop) {
77 pos = document.documentElement.scrollTop
78 } else if (document.body) {
79 pos = document.body.scrollTop
82 if (pos < theTop) {
83 pos = theTop;
84 } else {
85 pos += 100;
87 if (pos == old) {
88 timerbox.style.top = pos + 'px';
90 old = pos;
91 temp = setTimeout('movecounter(timerbox)',100);