diff --git a/css/main.css b/css/main.css index 9a75ce0..4f651a1 100644 --- a/css/main.css +++ b/css/main.css @@ -821,6 +821,10 @@ select option:disabled { opacity: 25%; } +#timer:hover:before { + content: "⏸" +} + .sk-cube-grid { width: 60px; height: 60px; @@ -909,4 +913,11 @@ display: block .answer-sub { opacity: 50%; text-align: center; - } \ No newline at end of file + } + +#resume-exam-button { + position: fixed; + top: 50%; + left: 50%; + transform: translate(-50%, -50%); +} \ No newline at end of file diff --git a/index.html b/index.html index 9bbc24d..06851fd 100644 --- a/index.html +++ b/index.html @@ -137,9 +137,13 @@ +
+
+ + diff --git a/js/helpers.js b/js/helpers.js index a9b6b4c..2830694 100644 --- a/js/helpers.js +++ b/js/helpers.js @@ -39,56 +39,4 @@ export function formatBytes(bytes, decimals = 2) { const i = Math.floor(Math.log(bytes) / Math.log(k)); return parseFloat((bytes / Math.pow(k, i)).toFixed(dm)) + " " + sizes[i]; -} - -export function CountDownTimer(duration, granularity) { - this.duration = duration; - this.granularity = granularity || 1000; - this.tickFtns = []; - this.running = false; -} - -CountDownTimer.prototype.start = function () { - if (this.running) { - return; - } - this.running = true; - var start = Date.now(), - that = this, - diff, - obj; - - (function timer() { - diff = that.duration - (((Date.now() - start) / 1000) | 0); - - if (diff > 0) { - setTimeout(timer, that.granularity); - } else { - diff = 0; - that.running = false; - } - - obj = CountDownTimer.parse(diff); - that.tickFtns.forEach(function (ftn) { - ftn.call(this, obj.minutes, obj.seconds); - }, that); - })(); -}; - -CountDownTimer.prototype.onTick = function (ftn) { - if (typeof ftn === 'function') { - this.tickFtns.push(ftn); - } - return this; -}; - -CountDownTimer.prototype.expired = function () { - return !this.running; -}; - -CountDownTimer.parse = function (seconds) { - return { - 'minutes': (seconds / 60) | 0, - seconds: seconds % 60 | 0, - }; -}; +} \ No newline at end of file diff --git a/js/main.js b/js/main.js index f2c8ab7..1e0419d 100644 --- a/js/main.js +++ b/js/main.js @@ -149,16 +149,15 @@ function setUpQuestions() { loadQuestion(0, 1, true); createQuestionListPanel(); - if (window.question_type == "rapid") { window.exam_time = 35 * 60; - } else if (window.question_type == "anatomy"){ + } else if (window.question_type == "anatomy") { window.exam_time = 90 * 60; - } else if (window.question_type == "long"){ + } else if (window.question_type == "long") { window.exam_time = 75 * 60; } - $("#exam-time").text(window.exam_time / 60) + $("#exam-time").text(window.exam_time / 60); $("#start-dialog").modal(); } @@ -1683,29 +1682,50 @@ $("#start-exam-button").click(function (evt) { }); $("#start-packet-button").click(function (evt) { - //window.cid = parseInt($("#candidate-number").val()); - // const t = 35 * 60; + let timer = new easytimer.Timer(); + //window.exam_time = 2; + timer.start({ countdown: true, startValues: { seconds: window.exam_time } }); + timer.addEventListener("secondsUpdated", function (e) { + $('#timer').html("Time left: " + timer.getTimeValues().toString()); + }); + timer.addEventListener("targetAchieved", function (e) { + $("#time-up-dialog").modal(); + }); - //const t = 2; - let display = document.querySelector("#timer"); - let timer = new helper.CountDownTimer(window.exam_time); - let timeObj = helper.CountDownTimer.parse(window.exam_time); + $("#timer").click(() => { + timer.pause(); + $("#pause").empty(); + $("#pause").append( + $( + '' + ).click(() => { + $("#pause").hide(); + timer.start(); + }) + ); + $("#pause").show(); + }); - format(timeObj.minutes, timeObj.seconds); + // //const t = 2; + // let display = document.querySelector("#timer"); + // let timer = new helper.CountDownTimer(window.exam_time); + // let timeObj = helper.CountDownTimer.parse(window.exam_time); - timer.onTick(format); + // format(timeObj.minutes, timeObj.seconds); - timer.start(); + // timer.onTick(format); - function format(minutes, seconds) { - minutes = minutes < 10 ? "0" + minutes : minutes; - seconds = seconds < 10 ? "0" + seconds : seconds; - display.textContent = "Time left: " + minutes + ":" + seconds; + // timer.start(); - if (minutes == 0 && seconds == 0) { - $("#time-up-dialog").modal(); - } - } + // function format(minutes, seconds) { + // minutes = minutes < 10 ? "0" + minutes : minutes; + // seconds = seconds < 10 ? "0" + seconds : seconds; + // display.textContent = "Time left: " + minutes + ":" + seconds; + + // if (minutes == 0 && seconds == 0) { + // $("#time-up-dialog").modal(); + // } + // } $.modal.close(); }); diff --git a/lib/easytimer.min.js b/lib/easytimer.min.js new file mode 100644 index 0000000..ca9c46b --- /dev/null +++ b/lib/easytimer.min.js @@ -0,0 +1,7 @@ +/** + * easytimer.js + * Generated: 2019-12-22 + * Version: 4.1.1 + */ + +!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).easytimer={})}(this,function(t){"use strict";function _(t){return(_="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function e(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var o=Object.getOwnPropertySymbols(e);t&&(o=o.filter(function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable})),n.push.apply(n,o)}return n}function z(r){for(var t=1;te)return t;for(o=0;o