I am trying to make a timer and i have coded for that part and it is working But when I am using this code in limeSurvey then it is not working. I have changed the Global setting for Html filter for XSS to No. Still code is not working.
Can anyone help in this?
code of timer that is added in scripts/template.js is :
function startTimer(duration, display) {
var start = Date.now(),
diff;
function timer() {
// get the number of seconds that have elapsed since
// startTimer() was called
diff = duration - (((Date.now() - start) / 1000) | 0);
// does the same job as parseInt truncates the float
minutes = (diff / 60) | 0;
seconds = (diff % 60) | 0;
minutes = minutes < 10 ? "0" + minutes : minutes;
seconds = seconds < 10 ? "0" + seconds : seconds;
display.textContent = minutes + ":" + seconds ;
if (diff <= 0) {
// add one second so that the count down starts at the full duration
// example 05:00 not 04:59
//start = Date.now() + 1000;
clearInterval(handle);
display.textContent ="Time finished ";
alert("Time is over.Click ok to submit Exam.");
$("#movesubmitbtn").click();
alert("vitually clicked submit");
}
}
// we don't want to wait a full second before the timer starts
timer();
handle = setInterval(timer, 1000);
}
function setCookie(cname,cvalue) {
document.cookie = cname+"="+cvalue;
}
function getCookie(cname) {
var name = cname + "=";
var ca = document.cookie.split(';');
for(var i=0; i<ca.length; i++) {
var c = ca
;
while (c.charAt(0)==' ') {
c = c.substring(1);
}
if (c.indexOf(name) === 0) {
return c.substring(name.length, c.length);
}
}
return "";
}
window.onload = function(){
alert( "time is"+{GROUPDESCRIPTION} );
var examTime;
var display = document.querySelector('#time');
if(getCookie("examDuration")=== ""){
//cookie is not defined
setCookie("examDuration", 60*5);
examTime=getCookie("examDuration");
} else{
examTime=getCookie("examDuration");
}
startTimer(examTime, display);
$("#movenextbtn").click(function(){
var remainingTime = (parseInt(minutes,10) * 60) + parseInt(seconds,10) ;
setCookie("examDuration", remainingTime);
alert("next btn is clicked, examTime : "+examTime +" and remainingTime : "+remainingTime);
clearInterval(handle);
location.reload();
});
$("#movesubmitbtn").click(function(){
var remainingTime = (parseInt(minutes,10) * 60) + parseInt(seconds,10) ;
setCookie("examDuration", remainingTime);
clearInterval(handle);
alert("submit btn is clicked and remaining time :" + remainingTime);
});
code added in Startgroup.tsptl is :
<p>Time left <br> <span id="time" ></span></p>
one library link is added:
<script src="
ajax.googleapis.com/ajax/libs/jquery/2.2.2/jquery.min.js
">
I don't know why it is not working in limesurvey and working when i run it utside limesurvey. Any help will be welcomed. Thanks in advance.