-
Notifications
You must be signed in to change notification settings - Fork 71
/
jquery.sessionTimeout.min.js
1 lines (1 loc) · 1.43 KB
/
jquery.sessionTimeout.min.js
1
!function(a){jQuery.sessionTimeout=function(b){function c(b){switch(b){case"start":f=setTimeout(function(){a("#sessionTimeout-dialog").dialog("open"),d("start")},i.warnAfter);break;case"stop":clearTimeout(f)}}function d(a){switch(a){case"start":g=setTimeout(function(){window.location=i.redirUrl},i.redirAfter-i.warnAfter);break;case"stop":clearTimeout(g)}}function e(a,b,c){var d=new RegExp("([?|&])"+b+"=.*?(&|#|$)","i");if(a.match(d))return a.replace(d,"$1"+b+"="+c+"$2");var e="";-1!==a.indexOf("#")&&(e=a.replace(/.*#/,"#"),a=a.replace(/#.*/,""));var f=-1!==a.indexOf("?")?"&":"?";return a+f+b+"="+c+e}var f,g,h={message:"Your session is about to expire.",keepAliveUrl:"/keep-alive",keepAliveAjaxRequestType:"POST",redirUrl:"/timed-out",logoutUrl:"/log-out",warnAfter:9e5,redirAfter:12e5,appendTime:!0},i=h;b&&(i=a.extend(h,b)),a("body").append('<div title="Session Timeout" id="sessionTimeout-dialog">'+i.message+"</div>"),a("#sessionTimeout-dialog").dialog({autoOpen:!1,width:400,modal:!0,closeOnEscape:!1,open:function(){a(".ui-dialog-titlebar-close").hide()},buttons:{"Log Out Now":function(){window.location=i.logoutUrl},"Stay Connected":function(){a(this).dialog("close"),a.ajax({type:i.keepAliveAjaxRequestType,url:i.appendTime?e(i.keepAliveUrl,"_",(new Date).getTime()):i.keepAliveUrl}),d("stop"),c("start")}}}),a(document).ajaxComplete(function(){a("#sessionTimeout-dialog").dialog("isOpen")||(d("stop"),c("stop"),c("start"))}),c("start")}}(jQuery);