MDL-42663 mod_lesson: Move definitions to show_clock()
authorDavid Monllao <davidm@moodle.com>
Fri, 1 Nov 2013 03:47:17 +0000 (11:47 +0800)
committerDavid Monllao <davidm@moodle.com>
Fri, 1 Nov 2013 08:37:45 +0000 (16:37 +0800)
Seems that the required data is not always set
before timer.js is included.

mod/lesson/timer.js

index 6d32720..d21267d 100644 (file)
     var javatime = javatimeDate.getTime();
     javatime = Math.floor(javatime/1000);
 
-    if (typeof(clocksettings)!='undefined') {
-        if (clocksettings.starttime) {
-            starttime = parseInt(clocksettings.starttime);
-        }
-        if (clocksettings.servertime) {
-            servertime =  parseInt(clocksettings.servertime);
-        }
-        if (clocksettings.testlength) {
-            testlength =  parseInt(clocksettings.testlength);
-        }
-    }
-
-    difference = javatime - servertime;
-    starttime = starttime + difference;
-
     var dn = "";
     var old = "";
 
 
     function show_clock() {
 
+        if (typeof(clocksettings) != 'undefined') {
+            if (clocksettings.starttime) {
+                starttime = parseInt(clocksettings.starttime);
+            }
+            if (clocksettings.servertime) {
+                servertime =  parseInt(clocksettings.servertime);
+            }
+            if (clocksettings.testlength) {
+                testlength =  parseInt(clocksettings.testlength);
+            }
+        }
+
+        difference = javatime - servertime;
+        starttime = starttime + difference;
+
         //show clock in NS 4
         if (document.layers)
                 document.ClockPosNS.visibility="show";