forked from JillElaine/jquery-idleTimeout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-idleTimeout.min.js
1 lines (1 loc) · 2.93 KB
/
jquery-idleTimeout.min.js
1
!function(e){e.fn.idleTimeout=function(i){var t,o,n,l,a,s,r,d,c,u,g,m,v,f,T,p,y,b,L,w,h={redirectUrl:"/logout",idleTimeLimit:1200,idleCheckHeartbeat:2,customCallback:!1,activityEvents:"click keypress scroll wheel mousewheel mousemove",enableDialog:!0,dialogDisplayLimit:180,dialogTitle:"Session Expiration Warning",dialogText:"Because you have been inactive, your session is about to expire.",dialogTimeRemaining:"Time remaining",dialogStayLoggedInButton:"Stay Logged In",dialogLogOutNowButton:"Log Out Now",errorAlertMessage:'Please disable "Private Mode", or upgrade to a modern browser. Or perhaps a dependent file missing. Please see: https://github.com/marcuswestin/store.js',sessionKeepAliveTimer:600,sessionKeepAliveUrl:window.location.href},A=e.extend(h,i),D=document.title;return this.logout=function(){store.set("idleTimerLoggedOut",!0)},o=function(){l=function(){e.get(A.sessionKeepAliveUrl),o()},a=setTimeout(l,1e3*A.sessionKeepAliveTimer)},n=function(){clearTimeout(a)},t=function(){e("body").on(A.activityEvents,function(){(!A.enableDialog||A.enableDialog&&y()!==!0)&&u()})},d=function(){var i=store.get("idleTimerLastActivity")+1e3*A.idleTimeLimit;e.now()>i?A.enableDialog?A.enableDialog&&y()!==!0&&(m(),T()):w():store.get("idleTimerLoggedOut")===!0?w():A.enableDialog&&y()===!0&&(b(),p())},u=function(){g(),store.set("idleTimerLastActivity",e.now()),c()},c=function(){d(),s=setTimeout(c,1e3*A.idleCheckHeartbeat)},g=function(){clearTimeout(s)},m=function(){var i="<div id='idletimer_warning_dialog'><p>"+A.dialogText+"</p><p style='display:inline'>"+A.dialogTimeRemaining+": <div style='display:inline' id='countdownDisplay'></div></p></div>";e(i).dialog({buttons:[{text:A.dialogStayLoggedInButton,click:function(){b(),p(),u()}},{text:A.dialogLogOutNowButton,click:function(){w()}}],closeOnEscape:!1,modal:!0,title:A.dialogTitle,open:function(){e(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide()}}),L(),document.title=A.dialogTitle,A.sessionKeepAliveTimer&&n()},f=function(){var i=store.get("idleTimerLastActivity")+1e3*A.idleTimeLimit+1e3*A.dialogDisplayLimit;(e.now()>i||store.get("idleTimerLoggedOut")===!0)&&w()},T=function(){v=setInterval(f,1e3*A.idleCheckHeartbeat)},p=function(){clearInterval(v),clearInterval(r)},y=function(){var i=e("#idletimer_warning_dialog").is(":visible");return i===!0?!0:!1},b=function(){e("#idletimer_warning_dialog").dialog("destroy").remove(),document.title=D,A.sessionKeepAliveTimer&&o()},L=function(){var i,t,o=A.dialogDisplayLimit;r=setInterval(function(){i=Math.floor(o/60),10>i&&(i="0"+i),t=o-60*i,10>t&&(t="0"+t),e("#countdownDisplay").html(i+":"+t),o-=1},1e3)},w=function(){store.set("idleTimerLoggedOut",!0),A.sessionKeepAliveTimer&&n(),A.customCallback&&A.customCallback(),A.redirectUrl&&(window.location.href=A.redirectUrl)},this.each(function(){store.enabled?(store.set("idleTimerLastActivity",e.now()),store.set("idleTimerLoggedOut",!1),t(),A.sessionKeepAliveTimer&&o(),u()):alert(A.errorAlertMessage)})}}(jQuery);