Skip to content

Commit

Permalink
Merge branch 'MDL-27930' of git://github.com/jmvedrine/moodle
Browse files Browse the repository at this point in the history
  • Loading branch information
Damyon Wiese committed Nov 5, 2014
2 parents 5467cc0 + 50d70c5 commit c86477a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 66 deletions.
1 change: 1 addition & 0 deletions mod/lesson/lang/en/lesson.php
Expand Up @@ -420,6 +420,7 @@
$string['thatsthewronganswer'] = 'That\'s the wrong answer';
$string['thefollowingpagesjumptothispage'] = 'The following pages jump to this page';
$string['thispage'] = 'This page';
$string['timeisup'] = 'Time is up';
$string['timeremaining'] = 'Time remaining';
$string['timespenterror'] = 'Spend at least {$a} minutes in the lesson';
$string['timespentminutes'] = 'Time spent (minutes)';
Expand Down
7 changes: 4 additions & 3 deletions mod/lesson/locallib.php
Expand Up @@ -488,14 +488,15 @@ function lesson_clock_block_contents($cmid, $lesson, $timer, $page) {
return null;
}

$content = '<div class="jshidewhenenabled">';
$content = '<div id="lesson-timer">';
$content .= $lesson->time_remaining($timer->starttime);
$content .= '</div>';

$clocksettings = array('starttime'=>$timer->starttime, 'servertime'=>time(),'testlength'=>($lesson->maxtime * 60));
$page->requires->data_for_js('clocksettings', $clocksettings);
$page->requires->data_for_js('clocksettings', $clocksettings, true);
$page->requires->strings_for_js(array('timeisup'), 'lesson');
$page->requires->js('/mod/lesson/timer.js');
$page->requires->js_function_call('show_clock');
$page->requires->js_init_call('show_clock');

$bc = new block_contents();
$bc->title = get_string('timeremaining', 'lesson');
Expand Down
12 changes: 12 additions & 0 deletions mod/lesson/styles.css
Expand Up @@ -78,3 +78,15 @@
.path-mod-lesson.dir-rtl .standardtable,
.path-mod-lesson.dir-rtl .mform .box.contents,
.path-mod-lesson.dir-rtl .invisiblefieldset.fieldsetfix tr {text-align: right;}

/* Countdown timer. */
#lesson-timer {
font-weight: bold;
font-size: 14px;
text-align: center;
background: #ffeeee;
}

#lesson-timer.timeleft1 {
color: #ff1111;
}
90 changes: 28 additions & 62 deletions mod/lesson/timer.js
Expand Up @@ -18,100 +18,66 @@
//
//////////////////////////////////////////////////////////*/

var myfont_face = "Arial";
var myfont_size = "12";
var myfont_color = "#000000";
var myback_color = "#FFFFFF";
var mywidth = 80;
var my12_hour = 1;
var stopclock = 0;
var myclock = '';
var timeleft, hours, minutes, secs;
var javatimeDate = new Date();
var javatime = javatimeDate.getTime();
javatime = Math.floor(javatime/1000);
javatime = Math.floor(javatime / 1000);

var dn = "";
var old = "";

if (document.all||document.getElementById) {
document.write('<span id="LiveClockIE" style="width:'+mywidth+'px;"></span>');
} else if (document.layers) {
document.write('<ilayer id="ClockPosNS"><layer width="'+mywidth+'" id="LiveClockNS"></layer></ilayer>');
} else {
old = "true"; 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;

/*function leave() { // feable attempt to run a script when someone leaves a timed test early, failed so far
window.onunload = window.open('http://www.google.com','','toolbar=no,menubar=no,location=no,height=500,width=500');
}
leave();*/

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";
if (old == "die") { return; }

currentDate = new Date();
current = currentDate.getTime();
current = Math.floor(current/1000);
current = Math.floor(current / 1000);

var myclock = '<font style="color:'+myfont_color+'; font-family:'+myfont_face+'; font-size:'+myfont_size+'pt;">';
var mytime = '',
myclock = document.getElementById("lesson-timer");
if (current > starttime + testlength) {
myclock += "Time is up";
mytime += M.util.get_string('timeisup', 'lesson');
stopclock = 1;
} else {
timeleft = starttime + testlength - current;
hours = Math.floor(timeleft/3600);
if (timeleft < 60) {
myclock.className = "timeleft1";
}
hours = Math.floor(timeleft / 3600);
timeleft = timeleft - (hours * 3600);
minutes = Math.floor(timeleft/60);
minutes = Math.floor(timeleft / 60);
secs = timeleft - (minutes * 60);

if (secs < 10) {
secs = "0"+secs;
secs = "0" + secs;
}
if (minutes < 10) {
minutes = "0"+minutes;
minutes = "0" + minutes;
}
myclock += hours+":"+minutes+":"+secs;
mytime += hours + ":" + minutes + ":" + secs;
}
myclock += '</font>';

if (old == "true") {
document.write(myclock);
old = "die"; return;
}

if (document.layers) {
clockpos = document.ClockPosNS;
liveclock = clockpos.document.LiveClockNS;
liveclock.document.write(myclock);
liveclock.document.close();
} else if (document.all) {
LiveClockIE.innerHTML = myclock;
} else if (document.getElementById) {
document.getElementById("LiveClockIE").innerHTML = myclock;
}
myclock.innerHTML = mytime;

if (stopclock == 0) {
setTimeout("show_clock()",1000);
setTimeout("show_clock()", 1000);
}
}

2 changes: 1 addition & 1 deletion mod/lesson/version.php
Expand Up @@ -24,7 +24,7 @@

defined('MOODLE_INTERNAL') || die();

$plugin->version = 2014101600; // The current module version (Date: YYYYMMDDXX)
$plugin->version = 2014110400; // The current module version (Date: YYYYMMDDXX)
$plugin->requires = 2014050800; // Requires this Moodle version
$plugin->component = 'mod_lesson'; // Full name of the plugin (used for diagnostics)
$plugin->cron = 0;

0 comments on commit c86477a

Please sign in to comment.