Welcome to the LimeSurvey Community Forum

Ask the community, share ideas, and connect with other LimeSurvey users!

overriding the question timer cookie

  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 5 months ago #175919 by Siem
We have a survey that has a question timer. It causes some problems for candidates.
Especially when different candidates use the same computer (LimeSurvey will use the timer from the previous candidate) and sometimes due to human error.

In order to solve it, it would help if we could reset the timer each time the survey is started or if the page is reloaded.

Any idea how to do this? I suspect the timing code is in time.min.js see below:


Code:
!function(e){var i={};function t(n){if(i[n])return i[n].exports;var s=i[n]={i:n,l:!1,exports:{}};return e[n].call(s.exports,s,s.exports,t),s.l=!0,s.exports}t.m=e,t.c=i,t.d=function(e,i,n){t.o(e,i)||Object.defineProperty(e,i,{enumerable:!0,get:n})},t.r=function(e){"undefined"!=typeof Symbol&amp;&amp;Symbol.toStringTag&amp;&amp;Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,i){if(1&amp;i&amp;&amp;(e=t(e)),8&amp;i)return e;if(4&amp;i&amp;&amp;"object"==typeof e&amp;&amp;e&amp;&amp;e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&amp;i&amp;&amp;"string"!=typeof e)for(var s in e)t.d(n,s,function(i){return e[i]}.bind(null,s));return n},t.n=function(e){var i=e&amp;&amp;e.__esModule?function(){return e.default}:function(){return e};return t.d(i,"a",i),i},t.o=function(e,i){return Object.prototype.hasOwnProperty.call(e,i)},t.p="",t(t.s=1)}([function(e,i,t){"use strict";Object.defineProperty(i,"__esModule",{value:!0});var n=function(){function e(e,i){for(var t=0;t<i.length;t++){var n=i[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&amp;&amp;(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(i,t,n){return t&amp;&amp;e(i.prototype,t),n&amp;&amp;e(i,n),i}}(),s=function(){function e(i){var t=this;return function(e,i){if(!(e instanceof i))throw new TypeError("Cannot call a class as a function")}(this,e),this.option=this._parseOptions(i),this.timerWarning=null,this.timerWarning2=null,this.timerLogger=new ConsoleShim("TIMER#"+i.questionid,!window.debugState.frontend),this.intervalObject=null,this.warning=0,this.timersessionname="timer_question_"+this.option.questionid,this.timeLeft=this._getTimerFromLocalStorage()||this.option.timer,this.disable_next=$("#disablenext-"+this.timersessionname).val(),this.disable_prev=$("#disableprev-"+this.timersessionname).val(),this.$timerDisplayElement=function(){return $("#LS_question"+t.option.questionid+"_Timer")},this.$timerExpiredElement=$("#question"+this.option.questionid+"_timer"),this.$warningTimeDisplayElement=$("#LS_question"+this.option.questionid+"_Warning"),this.$warningDisplayElement=$("#LS_question"+this.option.questionid+"_warning"),this.$warning2TimeDisplayElement=$("#LS_question"+this.option.questionid+"_Warning_2"),this.$warning2DisplayElement=$("#LS_question"+this.option.questionid+"_warning_2"),this.$countDownMessageElement=$("#countdown-message-"+this.timersessionname),this.redirectWarnTime=$("#message-delay-"+this.timersessionname).val(),this.$toBeDisabledElement=$("#"+this.option.disabledElement),this.timerLogger.log("Options set:",this.option),{startTimer:function(){return t.startTimer.apply(t)},finishTimer:function(){return t.finishTimer.apply(t)}}}return n(e,[{key:"_parseOptions",value:function(e){return{questionid:e.questionid||null,timer:e.timer||0,action:e.action||1,warning:e.warning||0,warning2:e.warning2||0,warninghide:e.warninghide||0,warning2hide:e.warning2hide||0,disabledElement:e.disabledElement||null}}},{key:"_parseTimeToObject",value:function(e,i){i=i||!1;var t=moment.duration(e,"seconds"),n=String(t.hours()),s=String(t.minutes()),r=String(t.seconds());return{hours:i?1==n.length?"0"+n:n:parseInt(n),minutes:i?1==s.length?"0"+s:s:parseInt(s),seconds:i?1==r.length?"0"+r:r:parseInt(sSecond)}}},{key:"_intervalStep",value:function(){var e=this._getTimerFromLocalStorage();e=parseInt(e)-1,this.timerLogger.log("Interval emitted | seconds left:",e),e<=0&amp;&amp;this.finishTimer(),this._checkForWarning(e),this._setTimerToLocalStorage(e),this._setTimer(e)}},{key:"_setInterval",value:function(){var e=this;this._existsDisplayElement()&amp;&amp;(this._setTimer(this.option.timer),this.intervalObject=setInterval(function(){return e._intervalStep.apply(e)},1e3))}},{key:"_unsetInterval",value:function(){clearInterval(this.intervalObject),this.intervalObject=null}},{key:"_existsDisplayElement",value:function(){return!(!this.$timerDisplayElement().length>0&amp;&amp;(this._unsetInterval(),1))}},{key:"_setTimer",value:function(e){var i=this._parseTimeToObject(e,!0);this._existsDisplayElement()&amp;&amp;this.$timerDisplayElement().css({display:"flex"}).html(this.$countDownMessageElement.html()+"&amp;nbsp;&amp;nbsp;<div class='ls-timer-time'>"+i.hours+":"+i.minutes+":"+i.seconds+"</div>")}},{key:"_checkForWarning",value:function(e){e==this.option.warning&amp;&amp;this._showWarning(),e==this.option.warning2&amp;&amp;this._showWarning2()}},{key:"_showWarning",value:function(){var e=this;0!==this.option.warning&amp;&amp;(this.timerLogger.log("Warning called!"),this.$warningDisplayElement.removeClass("hidden").css({opacity:0}).animate({opacity:1},200),setTimeout(function(){e.timerLogger.log("Warning ended!"),e.$warningDisplayElement.animate({opacity:0},200,function(){e.$warningDisplayElement.addClass("hidden")})},1e3*this.option.warninghide))}},{key:"_showWarning2",value:function(){var e=this;0!==this.option.warning2&amp;&amp;(this.timerLogger.log("Warning2 called!"),this.$warning2DisplayElement.removeClass("hidden").css({opacity:0}).animate({opacity:1},200),setTimeout(function(){e.timerLogger.log("Warning2 ended!"),e.$warning2DisplayElement.animate({opacity:0},200,function(){e.$warning2DisplayElement.addClass("hidden")})},1e3*this.option.warning2hide))}},{key:"_disableNavigation",value:function(){var e=this;this.timerLogger.log("Disabling navigation"),$(".ls-move-previous-btn").each(function(i,t){$(t).prop("disabled",1==e.disable_prev)}),$(".ls-move-next-btn,.ls-move-submit-btn").each(function(i,t){$(t).prop("disabled",1==e.disable_next)})}},{key:"_enableNavigation",value:function(){$(".ls-move-previous-btn").each(function(){$(this).prop("disabled",!1)}),$(".ls-move-next-btn,.ls-move-submit-btn").each(function(){$(this).prop("disabled",!1)})}},{key:"_getTimerFromLocalStorage",value:function(){var e=window.localStorage.getItem("limesurvey_timers_"+this.timersessionname);return isNaN(parseInt(e))?0:e}},{key:"_setTimerToLocalStorage",value:function(e){window.localStorage.setItem("limesurvey_timers_"+this.timersessionname,e)}},{key:"_unsetTimerInLocalStorage",value:function(){window.localStorage.removeItem("limesurvey_timers_"+this.timersessionname)}},{key:"_warnBeforeRedirection",value:function(){this._disableInput(),setTimeout(this._redirectOut,this.redirectWarnTime)}},{key:"_disableInput",value:function(){this.$toBeDisabledElement.prop("readonly",!0),$("#question"+this.option.questionid).find(".answer-container").children("div").not(".timer_header").fadeOut()}},{key:"_showExpiredNotice",value:function(){this.$timerExpiredElement.removeClass("hidden")}},{key:"_redirectOut",value:function(){$("#ls-button-submit").trigger("click")}},{key:"_bindUnsetToSubmit",value:function(){var e=this;$("#limesurvey").on("submit",function(){e._unsetTimerInLocalStorage()})}},{key:"finishTimer",value:function(){switch(this.timerLogger.log("Timer has ended or was ended"),this._unsetInterval(),this._enableNavigation(),this._bindUnsetToSubmit(),this._disableInput(),this.option.action){case 3:this._showExpiredNotice();break;case 2:this._redirectOut();break;case 1:default:this._showExpiredNotice(),this._warnBeforeRedirection()}}},{key:"startTimer",value:function(){0!=this.timeLeft?(this._setTimerToLocalStorage(this.timeLeft),this._disableNavigation(),this._setInterval()):this.finishTimer()}}]),e}();
/**
 * @file Script for timer
 * @copyright LimeSurvey <http://www.limesurvey.org>
 * @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&amp;dn=gpl-3.0.txt GPL-v3-or-Later
 */i.default=s},function(e,i,t){"use strict";var n=function(e){return e&amp;&amp;e.__esModule?e:{default:e}}(t(0));window.countdown=function(e,i,t,s,r,o,a,l){window.timerObjectSpace=window.timerObjectSpace||{},window.timerObjectSpace[e]||(window.timerObjectSpace[e]=new n.default({questionid:e,timer:i,action:t,warning:s,warning2:r,warninghide:o,warning2hide:a,disabledElement:l}),window.timerObjectSpace[e].startTimer())}}]);
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 5 months ago #175932 by tpartner
Replied by tpartner on topic overriding the question timer cookie
To reset the timer when the survey is restarted, append newtest=Y to the URL. Something like:

Code:
http://pathTo/limesurvey/index.php/167179?lang=en&amp;newtest=Y

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The topic has been locked.
  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 4 months ago #176115 by Siem
Replied by Siem on topic overriding the question timer cookie
Unfortunately the timer does not reset. 'newtest=Y' was already in our URLs.
The topic has been locked.
  • tpartner
  • tpartner's Avatar
  • Offline
  • LimeSurvey Community Team
  • LimeSurvey Community Team
More
5 years 4 months ago #176116 by tpartner
Replied by tpartner on topic overriding the question timer cookie
Hmm, maybe that was never fixed - see this thread - www.limesurvey.org/forum/can-i-do-this-w...-on-last-page#170640

Cheers,
Tony Partner

Solutions, code and workarounds presented in these forums are given without any warranty, implied or otherwise.
The following user(s) said Thank You: Siem
The topic has been locked.
  • Siem
  • Siem's Avatar Topic Author
  • Offline
  • Senior Member
  • Senior Member
More
5 years 4 months ago #176199 by Siem
Replied by Siem on topic overriding the question timer cookie
Thanks that worked like a charm!
The topic has been locked.

Lime-years ahead

Online-surveys for every purse and purpose