forked from JillElaine/jquery-idleTimeout
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery-idleTimeout-iframes.min.js
1 lines (1 loc) · 3.66 KB
/
jquery-idleTimeout-iframes.min.js
1
!function(e){e.fn.idleTimeout=function(i){var t,o,n,a,l,s,r,c,d,u,g,m,v,f,p,h,y,T,b,L,w,A,D,k,O={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},C=e.extend(O,i),E=document.title;return this.logout=function(){store.set("idleTimerLoggedOut",!0)},this.iframeRecheck=function(){A()},t=function(){store.set("activityEvents",C.activityEvents)},n=function(){l=function(){e.get(C.sessionKeepAliveUrl),n()},s=setTimeout(l,1e3*C.sessionKeepAliveTimer)},a=function(){clearTimeout(s)},o=function(){e("body").on(C.activityEvents,function(){(!C.enableDialog||C.enableDialog&&T()!==!0)&&g()})},d=function(){var i=store.get("idleTimerLastActivity")+1e3*C.idleTimeLimit;e.now()>i?C.enableDialog?C.enableDialog&&T()!==!0&&(v(),h()):w():store.get("idleTimerLoggedOut")===!0?w():C.enableDialog&&T()===!0&&(b(),y())},g=function(){m(),store.set("idleTimerLastActivity",e.now()),u()},u=function(){d(),r=setTimeout(u,1e3*C.idleCheckHeartbeat)},m=function(){clearTimeout(r)},v=function(){var i="<div id='idletimer_warning_dialog'><p>"+C.dialogText+"</p><p style='display:inline'>"+C.dialogTimeRemaining+": <div style='display:inline' id='countdownDisplay'></div></p></div>";e(i).dialog({buttons:[{text:C.dialogStayLoggedInButton,click:function(){b(),y(),g()}},{text:C.dialogLogOutNowButton,click:function(){w()}}],closeOnEscape:!1,modal:!0,title:C.dialogTitle,open:function(){e(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide()}}),L(),document.title=C.dialogTitle,C.sessionKeepAliveTimer&&a()},p=function(){var i=store.get("idleTimerLastActivity")+1e3*C.idleTimeLimit+1e3*C.dialogDisplayLimit;(e.now()>i||store.get("idleTimerLoggedOut")===!0)&&w()},h=function(){f=setInterval(p,1e3*C.idleCheckHeartbeat)},y=function(){clearInterval(f),clearInterval(c)},T=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=E,C.sessionKeepAliveTimer&&n()},L=function(){var i,t,o=C.dialogDisplayLimit;c=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),C.sessionKeepAliveTimer&&a(),C.customCallback&&C.customCallback(),C.redirectUrl&&(window.location.href=C.redirectUrl)},e("body").on("dialogopen",function(){C.enableDialog&&T()!==!0&&A()}),A=function(){var e,i;e=function(){"complete"===document.readyState&&(clearInterval(i),D())},i=setInterval(e,1e3)},D=function(i){i||(i=e(document));var t=0;i.find("iframe,frame").each(function(){if(e(this).hasClass("jit-inspected")===!1)try{D(e(this).contents()),e(this).on("load",k(e(this)));var i=e(this)[t];i.attachEvent&&i.attachEvent("onload",k(e(this))),t++}catch(o){e(this).addClass("jit-inspected cross-site")}})},k=function(i){var t=i.contents(),o=store.get("activityEvents");try{t.on(o,function(i){e("body").trigger(i)}),i.addClass("jit-inspected")}catch(n){}},this.each(function(){store.enabled?(store.set("idleTimerLastActivity",e.now()),store.set("idleTimerLoggedOut",!1),t(),o(),C.sessionKeepAliveTimer&&n(),g(),A()):alert(C.errorAlertMessage)})}}(jQuery);