forked from Nigrimmist/jquery-idleTimeout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjquery-idleTimeout.min.js
1 lines (1 loc) · 4.16 KB
/
jquery-idleTimeout.min.js
1
!function(a){a.fn.idleTimeout=function(b){var g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z,A,B,C,D,E,c=this,d={redirectUrl:"/logout",redirectUrlForLogoutByUser:!1,idleTimeLimit:1200,idleCheckHeartbeat:2,customCallback:!1,activityEvents:"click keypress scroll wheel mousewheel mousemove",enableDialog:!0,dialogDisplayLimit:180,dialogTitle:"Session Expiration Warning",modifyPageTitle:!0,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,useCustomPopup:!1,onPopupRequired:function(){},onDialogTimerTicked:function(a,b){},onDialogShouldBeHidden:function(){}},e=a.extend(d,b),f=document.title;return this.logout=function(){store.set("idleTimerLoggedOut",!0)},this.iframeRecheck=function(){C()},this.stayLogged=function(){y(),q()},this.logoutUser=function(){B(!0)},g=function(){store.set("activityEvents",e.activityEvents)},i=function(){k=function(){a.get(e.sessionKeepAliveUrl),i()},l=setTimeout(k,1e3*e.sessionKeepAliveTimer)},j=function(){clearTimeout(l)},h=function(){a("body").on(e.activityEvents,function(){store.get("idleTimerLoggedOut")===!0||e.enableDialog&&x()===!0||q()})},o=function(){var b=store.get("idleTimerLastActivity")+1e3*e.idleTimeLimit;a.now()>b?e.enableDialog?e.enableDialog&&x()!==!0&&s():B():store.get("idleTimerLoggedOut")===!0?B():e.enableDialog&&x()===!0&&y()},q=function(){r(),store.set("idleTimerLastActivity",a.now()),p()},p=function(){o(),m=setTimeout(p,1e3*e.idleCheckHeartbeat)},r=function(){clearTimeout(m)},s=function(){if(A=!0,d.onPopupRequired(),!d.useCustomPopup){var b="<div id='idletimer_warning_dialog'><p>"+e.dialogText+"</p><p style='display:inline'>"+e.dialogTimeRemaining+": <div style='display:inline' id='countdownDisplay'></div></p></div>";a(b).dialog({buttons:[{text:e.dialogStayLoggedInButton,click:function(){c.stayLogged()}},{text:e.dialogLogOutNowButton,click:function(){c.logoutUser()}}],closeOnEscape:!1,modal:!0,title:e.dialogTitle,open:function(){a(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide()}})}z(),e.modifyPageTitle&&(document.title=e.dialogTitle),e.sessionKeepAliveTimer&&j(),v()},u=function(){var b=store.get("idleTimerLastActivity")+1e3*e.idleTimeLimit+1e3*e.dialogDisplayLimit;(a.now()>b||store.get("idleTimerLoggedOut")===!0)&&B()},v=function(){t=setInterval(u,1e3*e.idleCheckHeartbeat)},w=function(){clearInterval(t)},x=function(){return A},y=function(){A=!1,w(),e.onDialogShouldBeHidden(),e.useCustomPopup||a("#idletimer_warning_dialog").dialog("destroy").remove(),e.modifyPageTitle&&(document.title=f),e.sessionKeepAliveTimer&&i()},z=function(){var c,d,b=e.dialogDisplayLimit;n=setInterval(function(){b<0&&(b=0,clearInterval(n)),c=Math.floor(b/60),c<10&&(c="0"+c),d=b-60*c,d<10&&(d="0"+d),e.onDialogTimerTicked(c,d),e.useCustomPopup&&a("#countdownDisplay").html(c+":"+d),b-=1},1e3)},B=function(a){r(),store.set("idleTimerLoggedOut",!0),x()===!0&&y(),e.sessionKeepAliveTimer&&j(),e.customCallback&&e.customCallback(),a&&e.redirectUrlForLogoutByUser?window.location.href=e.redirectUrlForLogoutByUser:e.redirectUrl&&(window.location.href=e.redirectUrl)},a("body").on("dialogopen",function(){e.enableDialog&&x()!==!0&&C()}),C=function(){var a,b;a=function(){"complete"===document.readyState&&(clearInterval(b),D())},b=setInterval(a,1e3)},D=function(b){b||(b=a(document));var c=0;b.find("iframe,frame").each(function(){if(a(this).hasClass("jit-inspected")===!1)try{D(a(this).contents()),a(this).on("load",E(a(this)));var b=a(this)[c];b.attachEvent&&b.attachEvent("onload",E(a(this))),c++}catch(b){a(this).addClass("jit-inspected cross-site")}})},E=function(b){var c=b.contents(),d=store.get("activityEvents");try{c.on(d,function(b){a("body").trigger(b)}),b.addClass("jit-inspected")}catch(a){}},this.each(function(){store.enabled?(store.set("idleTimerLastActivity",a.now()),store.set("idleTimerLoggedOut",!1),g(),h(),e.sessionKeepAliveTimer&&i(),q(),C()):alert(e.errorAlertMessage)})}}(jQuery);