- Posts: 55
- Thank you received: 1
Ask the community, share ideas, and connect with other LimeSurvey users!
!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&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},t.t=function(e,i){if(1&i&&(e=t(e)),8&i)return e;if(4&i&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(t.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&i&&"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&&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&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}return function(i,t,n){return t&&e(i.prototype,t),n&&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&&this.finishTimer(),this._checkForWarning(e),this._setTimerToLocalStorage(e),this._setTimer(e)}},{key:"_setInterval",value:function(){var e=this;this._existsDisplayElement()&&(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&&(this._unsetInterval(),1))}},{key:"_setTimer",value:function(e){var i=this._parseTimeToObject(e,!0);this._existsDisplayElement()&&this.$timerDisplayElement().css({display:"flex"}).html(this.$countDownMessageElement.html()+"&nbsp;&nbsp;<div class='ls-timer-time'>"+i.hours+":"+i.minutes+":"+i.seconds+"</div>")}},{key:"_checkForWarning",value:function(e){e==this.option.warning&&this._showWarning(),e==this.option.warning2&&this._showWarning2()}},{key:"_showWarning",value:function(){var e=this;0!==this.option.warning&&(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&&(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 <https://www.limesurvey.org> * @license magnet:?xt=urn:btih:1f739d935676111cfff4b4693e3816e664797050&dn=gpl-3.0.txt GPL-v3-or-Later */i.default=s},function(e,i,t){"use strict";var n=function(e){return e&&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())}}]);
https://pathTo/limesurvey/index.php/167179?lang=en&newtest=Y