JSFiddle - React, Tailwind, and code Playground
by Shidhin C R
JavaScript
(function($){
var Timer = function( interval , handler ){
this.tmr = 0;
this.interval = ( interval * 1000 );
this.handler = handler || function(){};
};
Timer.prototype = {
constructor : Timer
,stop : function(){
clearInterval( this.tmr );
return this;
}
,start: function(){
var me = this;
me.tmr = setInterval( me.handler , me.interval );
return this;
}
,restart : function(){
this.stop().start();
}
};
function showSessionTimeoutDialog(){
alert("Done !!!");
}
function restartTimers(){
longtimer.restart();
shorttimer.restart();
}
function startTimers(){
longtimer.start();
shorttimer.start();
}
function pingServer() {
$.ajax('?cacheBuster=' + new Date().getTime() );
}
function showTimeout(){
longtimer.stop();
shorttimer.stop();
window.onbeforeunload = null;
showSessionTimeoutDialog(); // show the time out message here
}
function attachWicketAjaxHandlers(){
}
var shorttimer = new Timer( 1, pingServer)
,longtimer= new Timer( 30, showTimeout);
// Start the timer now !!!
attachWicketAjaxHandlers();
startTimers();
}(jQuery));