Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Not triggering idle or active after page load #50

Open
balastallion opened this issue Jun 21, 2018 · 0 comments
Open

Not triggering idle or active after page load #50

balastallion opened this issue Jun 21, 2018 · 0 comments

Comments

@balastallion
Copy link

Please reveiw the code below:

/*! Idle Timer v1.1.0 2016-03-21 | https://github.com/thorst/jquery-idletimer | (c) 2016 Paul Irish | Licensed MIT */
!function(a){a.idleTimer=function(b,c){var d;"object"==typeof b?(d=b,b=null):"number"==typeof b&&(d={timeout:b},b=null),c=c||document,d=a.extend({idle:!1,timeout:3e4,events:"mousemove keydown wheel DOMMouseScroll mousewheel mousedown touchstart touchmove MSPointerDown MSPointerMove"},d);var e=a(c),f=e.data("idleTimerObj")||{},g=function(b){var d=a.data(c,"idleTimerObj")||{};d.idle=!d.idle,d.olddate=+new Date;var e=a.Event((d.idle?"idle":"active")+".idleTimer");a(c).trigger(e,[c,a.extend({},d),b])},h=function(b){var d=a.data(c,"idleTimerObj")||{};if(("storage"!==b.type||b.originalEvent.key===d.timerSyncId)&&null==d.remaining){if("mousemove"===b.type){if(b.pageX===d.pageX&&b.pageY===d.pageY)return;if("undefined"==typeof b.pageX&&"undefined"==typeof b.pageY)return;var e=+new Date-d.olddate;if(200>e)return}clearTimeout(d.tId),d.idle&&g(b),d.lastActive=+new Date,d.pageX=b.pageX,d.pageY=b.pageY,"storage"!==b.type&&d.timerSyncId&&"undefined"!=typeof localStorage&&localStorage.setItem(d.timerSyncId,d.lastActive),d.tId=setTimeout(g,d.timeout)}},i=function(){var b=a.data(c,"idleTimerObj")||{};b.idle=b.idleBackup,b.olddate=+new Date,b.lastActive=b.olddate,b.remaining=null,clearTimeout(b.tId),b.idle||(b.tId=setTimeout(g,b.timeout))},j=function(){var b=a.data(c,"idleTimerObj")||{};null==b.remaining&&(b.remaining=b.timeout-(+new Date-b.olddate),clearTimeout(b.tId))},k=function(){var b=a.data(c,"idleTimerObj")||{};null!=b.remaining&&(b.idle||(b.tId=setTimeout(g,b.remaining)),b.remaining=null)},l=function(){var b=a.data(c,"idleTimerObj")||{};clearTimeout(b.tId),e.removeData("idleTimerObj"),e.off("._idleTimer")},m=function(){var b=a.data(c,"idleTimerObj")||{};if(b.idle)return 0;if(null!=b.remaining)return b.remaining;var d=b.timeout-(+new Date-b.lastActive);return 0>d&&(d=0),d};if(null===b&&"undefined"!=typeof f.idle)return i(),e;if(null===b);else{if(null!==b&&"undefined"==typeof f.idle)return!1;if("destroy"===b)return l(),e;if("pause"===b)return j(),e;if("resume"===b)return k(),e;if("reset"===b)return i(),e;if("getRemainingTime"===b)return m();if("getElapsedTime"===b)return+new Date-f.olddate;if("getLastActiveTime"===b)return f.lastActive;if("isIdle"===b)return f.idle}return e.on(a.trim((d.events+" ").split(" ").join("._idleTimer ")),function(a){h(a)}),d.timerSyncId&&a(window).bind("storage",h),f=a.extend({},{olddate:+new Date,lastActive:+new Date,idle:d.idle,idleBackup:d.idle,timeout:d.timeout,remaining:null,timerSyncId:d.timerSyncId,tId:null,pageX:null,pageY:null}),f.idle||(f.tId=setTimeout(g,f.timeout)),a.data(c,"idleTimerObj",f),e},a.fn.idleTimer=function(b){return this[0]?a.idleTimer(b,this[0]):this}}(jQuery);

var _firstRun = true;
$(document).ready(function() {
if(_firstRun){
var isLogin = $('#isLogined').val();
var maxIdleTime = 1800000; // 30 mins
var minTimeSession = $("#minSessionTime").val();
var convertMinPopup = 1800000 - minTimeSession;
var minutes = Math.floor(convertMinPopup / 60000);
var seconds = ((convertMinPopup % 60000) / 1000).toFixed(0);
var timerPopUp = minutes + ":" + (seconds < 10 ? '0' : '') + seconds;
document.getElementById('timer').innerHTML = timerPopUp;

	function countDown(){
		console.log("CountDown function called!!!");
		var presentTime = document.getElementById('timer').innerHTML;
		var timeArray = presentTime.split(/[:]+/);
		var m = timeArray[0];
		var s = checkSecond((timeArray[1] - 1));
		if(s==59){m=m-1}
		if(m == 0 && s == 0){
			$("#timeoutContainer").hide();
			logout();  
		}
		document.getElementById('timer').innerHTML = m + ":" + s;
	}
	
	function timer(){
		console.log("calling timer Function!!!");
		setInterval(countDown,1000)
	}
function checkSecond(sec) {
	if (sec < 10 && sec >= 0) {sec = "0" + sec}
	if (sec < 0) {sec = "59"}
	return sec;
}

$( document ).idleTimer(minTimeSession);
$( document ).on( "idle.idleTimer", function(){
	if(isLogin == "true"){
		$("#timeoutContainer").show();
		console.log('before function called!!!');	
		timer();
	}
});


function logout(){
  $.ajax({
      type: "POST",
      url: ACC.config.contextPath + "/logout",
      success: function (response) {
         window.location = ACC.config.contextPath + "/logout";
      }
  });
}

function checkSecond(sec) {
  if (sec < 10 && sec >= 0) {sec = "0" + sec}
  if (sec < 0) {sec = "59"}
  return sec;
}

$("#inactivity_ok").click(function(){
	window.location = window.location;
});
$("#logoutButton").click(function(){
	logout();
});

_firstRun = false;
}

});

Once the page load idle is not getting triggered, please help me to fix the issues.

Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant