[ Index ]

PHP Cross Reference of Unnamed Project

title

Body

[close]

/mod/lesson/ -> timer.js (source)

   1  /*/////////////////////////////////////////////////////////
   2  // This code is based off of
   3  // "Live Clock Lite" script - Version 1.0
   4  // By Mark Plachetta (astroboy@zip.com.au)
   5  //
   6  // The original script displayed a clock.
   7  // Mark Nielsen modified it to be a countdown timer
   8  // for the lesson module in moodle.
   9  //
  10  //    Below is the code that is used to call this page.
  11  //    echo "<script type=\"text/javascript\">\n";
  12  //        echo "var starttime = ". $timer->starttime . ";\n";
  13  //        echo "var servertime = ". time() . ";\n";
  14  //        echo "var testlength = ". $lesson->timelimit .";\n";
  15  //        echo "document.write('<script type=\"text/javascript\" src=\"liveclock_lite.js\"><\/script>');\n";
  16  //        echo "window.onload = function () { show_clock(); }";
  17  //    echo "</script>\n";
  18  //
  19  //////////////////////////////////////////////////////////*/
  20  
  21      var stopclock = 0;
  22      var myclock = '';
  23      var timeleft, hours, minutes, secs;
  24      var javatimeDate = new Date();
  25      var javatime = javatimeDate.getTime();
  26      javatime = Math.floor(javatime / 1000);
  27  
  28      if (typeof(clocksettings) != 'undefined') {
  29          if (clocksettings.starttime) {
  30              starttime = parseInt(clocksettings.starttime);
  31          }
  32          if (clocksettings.servertime) {
  33              servertime = parseInt(clocksettings.servertime);
  34          }
  35          if (clocksettings.testlength) {
  36              testlength = parseInt(clocksettings.testlength);
  37          }
  38      }
  39  
  40      difference = javatime - servertime;
  41      starttime = starttime + difference;
  42  
  43      /*function leave() {  // feable attempt to run a script when someone leaves a timed test early, failed so far
  44          window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500');
  45      }
  46      leave();*/
  47  
  48      function show_clock() {
  49  
  50          currentDate = new Date();
  51          current = currentDate.getTime();
  52          current = Math.floor(current / 1000);
  53  
  54          var mytime = '',
  55              myclock = document.getElementById("lesson-timer");
  56          if (current > starttime + testlength) {
  57              mytime += M.util.get_string('timeisup', 'lesson');
  58              stopclock = 1;
  59          } else {
  60              timeleft = starttime + testlength - current;
  61              if (timeleft < 60) {
  62                  myclock.className = "timeleft1";
  63              }
  64              hours = Math.floor(timeleft / 3600);
  65              timeleft = timeleft - (hours * 3600);
  66              minutes = Math.floor(timeleft / 60);
  67              secs = timeleft - (minutes * 60);
  68  
  69              if (secs < 10) {
  70                  secs = "0" + secs;
  71              }
  72              if (minutes < 10) {
  73                  minutes = "0" + minutes;
  74              }
  75              mytime += hours + ":" + minutes + ":" + secs;
  76          }
  77  
  78          myclock.innerHTML = mytime;
  79  
  80          if (stopclock == 0) {
  81              setTimeout("show_clock()", 1000);
  82          }
  83  }


Generated: Thu Aug 11 10:00:09 2016 Cross-referenced by PHPXref 0.7.1