From 4067e0c602dbfecb783d7fe843853641012153b1 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 3 Jan 2020 10:36:32 -0500 Subject: [PATCH 1/2] Support ES6 Style Modules with Webpack Wait until the api.start(...) method is executed before looking up the body element. Loading the script before the DOM is loaded will results in the body element being undefined. --- src/jquery-idleTimeout-plus.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/jquery-idleTimeout-plus.js b/src/jquery-idleTimeout-plus.js index b3d436e..8d597a8 100644 --- a/src/jquery-idleTimeout-plus.js +++ b/src/jquery-idleTimeout-plus.js @@ -101,7 +101,7 @@ }; /* --strip_testing_end-- */ - var bodyElm = $('body'); // Store for jQuery optimization + var bodyElm = null; var dataStore = null; //######################################################################### @@ -116,6 +116,7 @@ * @return {boolean} - Returns true if successfully initialized */ api.start = function(userConfig) { + bodyElm = $('body'); console.log('jitp: init called'); //--Merge default and user configs config = $.extend(config, userConfig); From 3b4ef5301d0bc5e3e766ef90e40a2f029cedcf01 Mon Sep 17 00:00:00 2001 From: Sean King Date: Fri, 3 Jan 2020 10:37:12 -0500 Subject: [PATCH 2/2] Update the Distribution --- dist/js/jquery-idleTimeout-plus-iframe.js | 28 +++++++++++-------- dist/js/jquery-idleTimeout-plus-iframe.min.js | 2 +- dist/js/jquery-idleTimeout-plus.js | 28 +++++++++++-------- dist/js/jquery-idleTimeout-plus.min.js | 2 +- 4 files changed, 34 insertions(+), 26 deletions(-) diff --git a/dist/js/jquery-idleTimeout-plus-iframe.js b/dist/js/jquery-idleTimeout-plus-iframe.js index 29f19e4..a635791 100644 --- a/dist/js/jquery-idleTimeout-plus-iframe.js +++ b/dist/js/jquery-idleTimeout-plus-iframe.js @@ -1,11 +1,7 @@ /** - * This work is licensed under the Creative Commons Attribution-Share Alike 3.0 - * United States License. To view a copy of this license, - * visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter - * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. - * - * Modified by: Jason Abraham (CrashSensei) + * Written by: Jason Abraham (CrashSensei) * Email: jason@linearsoft.com + * License: GPLv3 (https://www.gnu.org/licenses/gpl-3.0-standalone.html) * * Configurable idle (no activity) timer and logout redirect for jQuery. * Supports both jQueryUI dialogs or Bootstrap modals @@ -19,7 +15,7 @@ * Multi-window support requires JQuery Storage API * Dialogs require either jQueryUI or Bootstrap * - * version 0.5.0 + * version 0.9.5 **/ (function(root, factory) { @@ -57,7 +53,7 @@ // Auto-Url settings (NOTE: if a callback is defined auto url redirection will only occur if the callback returns true) redirectUrl: '/timed-out', // URL if no action is taken after the warning/lock screen timeout logoutUrl: '/logout', // URL if the user clicks "Logout" on the warning/lock screen - logoutAutoUrl: 'null', // URL for secondary tabs that received an automatic logout trigger (to help avoid race conditions) + logoutAutoUrl: null, // URL for secondary tabs that received an automatic logout trigger (to help avoid race conditions) redirectCallback: false, logoutCallback: false, logoutAutoCallback: false, @@ -67,7 +63,9 @@ keepAliveUrl: window.location.href, // set URL to ping - does not apply if keepAliveInterval: false keepAliveAjaxType: 'GET', keepAliveAjaxData: '', - + keepAliveResponse: false, // add ability to check keep alive's response. if user was logged out by other means, or something went wrong, redirect to keepAliveBadUrl - Set to false to disable KeepAliveBadUrl redirection + keepAliveBadUrl: window.location.href, // set URL to redirect to if keepAliveResponse wasn't what was expected and if keepAliveResponse isn't set to false + // Lock Screen settings lockEnabled: false, // Set to true to enable lock screen before redirecting lockTimeLimit: 7200, // 2 hrs @@ -88,7 +86,7 @@ iframesSupport: false, // Enable iframe support (also requires multiWindow support to work) multiWindowSupport: false // Requires jquery-storage-api }; - var bodyElm = $('body'); // Store for jQuery optimization + var bodyElm = null; var dataStore = null; //######################################################################### // ### Public API Functions @@ -101,9 +99,10 @@ * @return {boolean} - Returns true if successfully initialized */ api.start = function(userConfig) { + bodyElm = $('body'); //--Merge default and user configs config = $.extend(config, userConfig); - if (config.logoutAutoUrl === null) config.logoutAutoUrl = config.logoutUrl; + if (config.logoutAutoUrl == null) config.logoutAutoUrl = config.logoutUrl; //--Convert secs to millisecs config.idleTimeLimit *= 1000; config.idleCheckHeartbeat *= 1000; @@ -349,7 +348,12 @@ $.ajax({ type: config.keepAliveAjaxType, url: config.keepAliveUrl, - data: config.keepAliveAjaxData + data: config.keepAliveAjaxData, + success: function(response){ + if(config.keepAliveResponse !== false && $.trim(response) !== config.keepAliveResponse){ + window.location.replace(config.keepAliveBadUrl); + } + } }); }, config.keepAliveInterval); } diff --git a/dist/js/jquery-idleTimeout-plus-iframe.min.js b/dist/js/jquery-idleTimeout-plus-iframe.min.js index e3437c1..85438de 100644 --- a/dist/js/jquery-idleTimeout-plus-iframe.min.js +++ b/dist/js/jquery-idleTimeout-plus-iframe.min.js @@ -1 +1 @@ -!function(t,o){"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof exports?module.exports=o(require("jquery")):t.IdleTimeoutPlus=o(t.jQuery)}(this,function(t){function o(){null===tt&&(tt=t.localStorage?t.initNamespaceStorage("jqueryIdleTimeoutPlus").localStorage:{})}function n(t,o){$.multiWindowSupport?tt.set(t,o):tt[t]=o}function e(t,o){if(o="undefined"==typeof o?null:o,$.multiWindowSupport){if(tt.isSet(t))return tt.get(t)}else if(t in tt)return tt[t];return o}function l(){n("warningStartTime",-1),n("lockStartTime",-1),i(),$.idleCallback!==!1&&$.idleCallback($)}function i(){a(),n("lastActivity",t.now()),nt=setInterval(r,$.idleCheckHeartbeat)}function a(){clearInterval(nt)}function r(){var o=e("lastActivity",t.now())+$.idleTimeLimit;return e("logoutTriggered")===!0?N():e("lockStartTime",-1)!==-1?(a(),A()):t.now()>=o?(a(),$.warnEnabled?d():$.lockEnabled?L():O()):void 0}function c(){t(document).on($.activityEvents,function(t){if("mousemove"===t.type){if(t.clientX===at[0]&&t.clientY===at[1])return;at[0]=t.clientX,at[1]=t.clientY}e("warningStartTime",-1)===-1&&e("lockStartTime",-1)===-1&&i()})}function u(){s(),et=setInterval(function(){t.ajax({type:$.keepAliveAjaxType,url:$.keepAliveUrl,data:$.keepAliveAjaxData})},$.keepAliveInterval)}function s(){clearInterval(et)}function d(){k(),$.warnCallback!==!1&&(rt=$.warnCallback($)),v()}function p(){f(),w(),n("warningStartTime",-1),l()}function k(){n("warningStartTime",t.now()),lt=setInterval(m,500)}function f(){clearInterval(lt)}function m(){if(e("logoutTriggered")===!0)return f(),N();if(e("warningStartTime",-1)===-1)return p();var o=e("warningStartTime")+$.warnTimeLimit-1;return t.now()>=o?(f(),$.lockEnabled?(w(),L()):O()):void b()}function v(){rt&&(g(),b(),$.bootstrap?(ut.modal("show"),ut.focus()):ut.dialog("open"),ct=!0)}function w(){ct=!1,null!==ut&&($.bootstrap?(ut.modal("hide"),_.removeClass("modal-open"),t("div.modal-backdrop").remove()):ut.dialog("close"))}function b(){if(null!==ut&&(null!==st||null!==dt)){var o=t.now(),n=Math.floor((e("warningStartTime",o)+$.warnTimeLimit-o)/1e3);if(null!==st&&st.html(V(n)),null!==dt){var l=Math.floor(n/($.warnTimeLimit/1e3)*100);$.bootstrap?dt.css("width",l+"%"):dt.progressbar("value",l)}}}function g(){if(null===ut){var t="";t=$.warnContentCallback===!1?$.bootstrap?j():C():$.warnContentCallback($),$.bootstrap?h(t):y(t)}}function h(o){_.append(o),null!==$.warnLogoutButton&&t("#jitp-warn-logout").on("click",function(){T()}),t("#jitp-warn-alive").on("click",function(){S()}),ut=t("#jitp-warn-display"),(null!==$.warnCountdownMessage||$.warnCountdownBar)&&(st=ut.find(".jitp-countdown-holder")),$.warnCountdownBar&&(dt=t("#jitp-warn-bar"))}function y(o){var n=[];null!==$.warnLogoutButton&&n.push({text:$.warnLogoutButton,click:function(){T()}}),n.push({text:$.warnStayAliveButton,click:function(){S()}}),t(o).dialog({buttons:n,closeOnEscape:!1,modal:!0,title:$.warnTitle,minWidth:320,autoOpen:!1,open:function(){null===$.warnTitle?t(this).closest(".ui-dialog").find(".ui-dialog-titlebar").hide():t(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide(),t(this).parent().find("button:nth-child(2)").focus()}}),ut=t("#jitp-warn-display"),null!==$.warnCountdownMessage&&(st=ut.find(".jitp-countdown-holder")),$.warnCountdownBar&&(dt=t("#jitp-warn-bar"),dt.progressbar({value:0,max:100}))}function j(){var t=null===$.warnTitle?"":'",o=null===$.warnCountdownMessage?"":"

"+$.warnCountdownMessage.replace(/\{timer}/g,'')+"

",n=null===$.warnLogoutButton?"":'",e=null===$.warnCountdownBar?"":'
';return'"}function C(){var t=null===$.warnCountdownMessage?"":"

"+$.warnCountdownMessage.replace(/\{timer}/g,'')+"

",o=null===$.warnCountdownBar?"":'
';return'

'+$.warnMessage+"

"+t+o+"
"}function T(){f(),D()}function S(){p()}function L(){$.lockHaltKeepAlive&&s(),I(),$.lockCallback!==!1&&(pt=$.lockCallback($)),E()}function A(){$.lockHaltKeepAlive?s():$.keepAliveInterval&&u(),e("lockStartTime",-1)===-1?I():it=setInterval(B,500),E()}function U(){M(),x(),t("#jitp-lock-pass").val(""),$.keepAliveInterval&&u(),n("lockStartTime",-1),l()}function I(){n("lockStartTime",t.now()),it=setInterval(B,500)}function M(){clearInterval(it)}function B(){if(e("logoutTriggered")===!0)return M(),N();if(e("lockStartTime",-1)===-1)return U();var o=e("lockStartTime")+$.lockTimeLimit-1;return t.now()>=o?(M(),e("logoutTriggered")===!0?N():O()):void W()}function E(){if(pt){q(),W();var o={message:t("#jitp-lock-display")};o=t.extend(o,$.lockBlockUiConfig),t.blockUI(o),kt=!0}}function x(){t.unblockUI(),kt=!1}function W(){if(null!==mt){var o=t.now(),n=Math.floor((e("lockStartTime",o)+$.lockTimeLimit-o)/1e3);mt.html(V(n))}}function q(){if(null===ft){var o="";o=$.lockContentCallback===!1?$.bootstrap?P():H():$.lockContentCallback($),_.append(o),ft=t("#jitp-lock-display"),$.lockCountdownMessage!==!1&&(mt=ft.find(".jitp-countdown-holder")),t("#jitp-lock-logout").on("click",function(){K()}),t("#jitp-lock-unlock").on("click",function(){Q()}),t("#jitp-lock-form").length&&t("#jitp-lock-form").submit(function(){return Q(),!1}),W()}}function P(){var t=null===$.lockTitle?"":'

'+$.lockTitle+"

",o=$.lockLogoutButton.replace(/\{username}/g,$.lockUsername),n=null===$.lockCountdownMessage?"":'";return'"}function H(){var t=null===$.lockTitle?"":"
"+$.lockTitle+"
",o=$.lockLogoutButton.replace(/\{username}/g,$.lockUsername),n=null===$.lockCountdownMessage?"":"
"+$.lockCountdownMessage.replace(/\{timer}/g,'')+"
";return'"}function K(){M(),D()}function Q(){$.lockPassCallback(t("#jitp-lock-pass").val())}function Y(){s(),a(),f(),M()}function D(){Y(),n("logoutTriggered",!0),("function"!=typeof $.logoutCallback||$.logoutCallback($))&&window.location.replace($.logoutUrl)}function N(){Y(),("function"!=typeof $.logoutAutoCallback||$.logoutAutoCallback($))&&window.location.replace($.logoutAutoUrl)}function O(){return Y(),$.multiWindowSupport?void setTimeout(X,Z(100,500)):X()}function X(){return e("logoutTriggered",!1)?N():(n("logoutTriggered",!0),void(("function"!=typeof $.redirectCallback||$.redirectCallback($))&&window.location.replace($.redirectUrl)))}function F(){n("activityEvents",$.activityEvents)}function G(){t(document).on("dialogopen shown.bs.modal",function(){ct||kt||J()})}function J(){var t,o=function(){"complete"===document.readyState&&(clearInterval(t),R())};t=setInterval(o,1e3)}function R(o){o||(o=t(document));var n=0;o.find("iframe,frame").each(function(){if(t(this).hasClass("jitp-inspected")===!1)try{R(t(this).contents()),t(this).on("load",z(t(this)));var o=t(this)[n];o.attachEvent&&o.attachEvent("onload",z(t(this))),n++}catch(e){t(this).addClass("jitp-inspected cross-site")}})}function z(o){var n=o.contents(),l=e("activityEvents","");try{n.on(l,function(o){t("body").trigger(o)}),o.addClass("jitp-inspected")}catch(i){}}function V(t){var o=Math.floor(t/60);if(o<=15){var n=t%60,e=o>0?o+"m ":"";return e+=n+"s"}if(o<=75)return o<=22?"about 15 mins":o<=37?"about 30 mins":o<=52?"about 25 mins":"about 1 hour";var l=Math.floor(o/60);return o%=60,o<=15?"about "+l+" hours":o>52?"about "+(l+1)+" hours":"about "+l+"½ hours"}function Z(t,o){return Math.floor(Math.random()*(o-t))+t}var $={idleTimeLimit:1200,idleCallback:!1,idleCheckHeartbeat:2,bootstrap:!1,activityEvents:"click keypress scroll wheel mousewheel mousemove touchmove",warnEnabled:!0,warnTimeLimit:180,warnCallback:!1,warnContentCallback:!1,warnTitle:"Session Timeout",warnMessage:"Your session is about to expire!",warnStayAliveButton:"Stay Connected",warnLogoutButton:"Logout",warnCountdownMessage:"Time remaining: {timer}",warnCountdownBar:!1,redirectUrl:"/timed-out",logoutUrl:"/logout",logoutAutoUrl:"null",redirectCallback:!1,logoutCallback:!1,logoutAutoCallback:!1,keepAliveInterval:600,keepAliveUrl:window.location.href,keepAliveAjaxType:"GET",keepAliveAjaxData:"",lockEnabled:!1,lockTimeLimit:7200,lockHaltKeepAlive:!0,lockCallback:!1,lockContentCallback:!1,lockPassCallback:!1,lockTitle:null,lockUsername:"System User",lockMessage:"Enter your password to unlock the screen",lockUnlockButton:"UnLock",lockLogoutButton:"Not {username} ?",lockCountdownMessage:"Auto-logout in: {timer}",lockBlockUiConfig:{},lockLoadActive:!1,iframesSupport:!1,multiWindowSupport:!1},_=t("body"),tt=null,ot={};ot.start=function(l){if($=t.extend($,l),null===$.logoutAutoUrl&&($.logoutAutoUrl=$.logoutUrl),$.idleTimeLimit*=1e3,$.idleCheckHeartbeat*=1e3,$.warnTimeLimit*=1e3,$.lockTimeLimit*=1e3,$.keepAliveInterval*=1e3,$.multiWindowSupport&&!t.localStorage)return console.error("jitp: Multi-Window support requested but JQuery Storage API is unavailable."),!1;if($.warnEnabled&&$.warnCallback===!1||$.lockEnabled&&$.lockCallback===!1)if($.bootstrap){if("undefined"==typeof t.fn.modal)return console.error("jitp: Bootstrap library is unavailable"),!1}else if("undefined"==typeof t.ui)return console.error("jitp: jQueryUI library is unavailable"),!1;if($.lockEnabled&&!$.multiWindowSupport)return console.error("jitp: Lock screen requested but multi-window support is not enabled."),!1;if($.lockEnabled&&$.lockCallback===!1){if("undefined"==typeof t.blockUI)return console.error("jitp: Lock screen requested but blockUI library is unavailable."),!1;if($.lockPassCallback===!1)return console.error("jitp: Lock screen requested but lockPassCallback function is not set."),!1}return $.iframesSupport&&!$.multiWindowSupport?(console.error("jitp: IFrame support requested but Multi-Window support disabled."),!1):(o(),$.lockEnabled&&($.lockLoadActive||e("lockStartTime",-1)>0)?A():(n("logoutTriggered",!1),n("warningStartTime",-1),n("lockStartTime",-1),n("lastActivity",t.now()),i(),$.keepAliveInterval&&u()),$.keepAliveInterval&&u(),F(),G(),c(),J(),!0)},ot.cleanUpLockScreen=function(){o(),t.localStorage&&tt.set("lockStartTime",-99)},ot.logout=function(){D()},ot.displayWarning=function(){v()},ot.displayLockScreen=function(){E()},ot.initLockScreen=function(){a(),f(),L()},ot.setIdleTimeLimit=function(t){"number"==typeof t&&($.idleTimeLimit=1e3*t,ot.rollback())},ot.setWarnTimeLimit=function(t){"number"==typeof t&&($.warnTimeLimit=1e3*t,ot.rollback())},ot.setLockTimeLimit=function(t){"number"==typeof t&&($.lockTimeLimit=1e3*t,ot.rollback())},ot.rollback=function(){U(),p()},ot.iframeRecheck=function(){J()};var nt,et,lt,it,at=[-1,-1],rt=!0,ct=!1,ut=null,st=null,dt=null,pt=!0,kt=!1,ft=null,mt=null;return ot}); \ No newline at end of file +!function(t,o){"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof exports?module.exports=o(require("jquery")):t.IdleTimeoutPlus=o(t.jQuery)}(this,function(t){function o(){null===tt&&(tt=t.localStorage?t.initNamespaceStorage("jqueryIdleTimeoutPlus").localStorage:{})}function n(t,o){$.multiWindowSupport?tt.set(t,o):tt[t]=o}function e(t,o){if(o="undefined"==typeof o?null:o,$.multiWindowSupport){if(tt.isSet(t))return tt.get(t)}else if(t in tt)return tt[t];return o}function l(){n("warningStartTime",-1),n("lockStartTime",-1),i(),$.idleCallback!==!1&&$.idleCallback($)}function i(){a(),n("lastActivity",t.now()),nt=setInterval(r,$.idleCheckHeartbeat)}function a(){clearInterval(nt)}function r(){var o=e("lastActivity",t.now())+$.idleTimeLimit;return e("logoutTriggered")===!0?D():e("lockStartTime",-1)!==-1?(a(),L()):t.now()>=o?(a(),$.warnEnabled?d():$.lockEnabled?A():N()):void 0}function c(){t(document).on($.activityEvents,function(t){if("mousemove"===t.type){if(t.clientX===at[0]&&t.clientY===at[1])return;at[0]=t.clientX,at[1]=t.clientY}e("warningStartTime",-1)===-1&&e("lockStartTime",-1)===-1&&i()})}function u(){s(),et=setInterval(function(){t.ajax({type:$.keepAliveAjaxType,url:$.keepAliveUrl,data:$.keepAliveAjaxData,success:function(o){$.keepAliveResponse!==!1&&t.trim(o)!==$.keepAliveResponse&&window.location.replace($.keepAliveBadUrl)}})},$.keepAliveInterval)}function s(){clearInterval(et)}function d(){k(),$.warnCallback!==!1&&(rt=$.warnCallback($)),m()}function p(){f(),w(),n("warningStartTime",-1),l()}function k(){n("warningStartTime",t.now()),lt=setInterval(v,500)}function f(){clearInterval(lt)}function v(){if(e("logoutTriggered")===!0)return f(),D();if(e("warningStartTime",-1)===-1)return p();var o=e("warningStartTime")+$.warnTimeLimit-1;return t.now()>=o?(f(),$.lockEnabled?(w(),A()):N()):void b()}function m(){rt&&(g(),b(),$.bootstrap?(ut.modal("show"),ut.focus()):ut.dialog("open"),ct=!0)}function w(){ct=!1,null!==ut&&($.bootstrap?(ut.modal("hide"),_.removeClass("modal-open"),t("div.modal-backdrop").remove()):ut.dialog("close"))}function b(){if(null!==ut&&(null!==st||null!==dt)){var o=t.now(),n=Math.floor((e("warningStartTime",o)+$.warnTimeLimit-o)/1e3);if(null!==st&&st.html(V(n)),null!==dt){var l=Math.floor(n/($.warnTimeLimit/1e3)*100);$.bootstrap?dt.css("width",l+"%"):dt.progressbar("value",l)}}}function g(){if(null===ut){var t="";t=$.warnContentCallback===!1?$.bootstrap?j():C():$.warnContentCallback($),$.bootstrap?h(t):y(t)}}function h(o){_.append(o),null!==$.warnLogoutButton&&t("#jitp-warn-logout").on("click",function(){T()}),t("#jitp-warn-alive").on("click",function(){S()}),ut=t("#jitp-warn-display"),(null!==$.warnCountdownMessage||$.warnCountdownBar)&&(st=ut.find(".jitp-countdown-holder")),$.warnCountdownBar&&(dt=t("#jitp-warn-bar"))}function y(o){var n=[];null!==$.warnLogoutButton&&n.push({text:$.warnLogoutButton,click:function(){T()}}),n.push({text:$.warnStayAliveButton,click:function(){S()}}),t(o).dialog({buttons:n,closeOnEscape:!1,modal:!0,title:$.warnTitle,minWidth:320,autoOpen:!1,open:function(){null===$.warnTitle?t(this).closest(".ui-dialog").find(".ui-dialog-titlebar").hide():t(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide(),t(this).parent().find("button:nth-child(2)").focus()}}),ut=t("#jitp-warn-display"),null!==$.warnCountdownMessage&&(st=ut.find(".jitp-countdown-holder")),$.warnCountdownBar&&(dt=t("#jitp-warn-bar"),dt.progressbar({value:0,max:100}))}function j(){var t=null===$.warnTitle?"":'",o=null===$.warnCountdownMessage?"":"

"+$.warnCountdownMessage.replace(/\{timer}/g,'')+"

",n=null===$.warnLogoutButton?"":'",e=null===$.warnCountdownBar?"":'
';return'"}function C(){var t=null===$.warnCountdownMessage?"":"

"+$.warnCountdownMessage.replace(/\{timer}/g,'')+"

",o=null===$.warnCountdownBar?"":'
';return'

'+$.warnMessage+"

"+t+o+"
"}function T(){f(),Y()}function S(){p()}function A(){$.lockHaltKeepAlive&&s(),I(),$.lockCallback!==!1&&(pt=$.lockCallback($)),E()}function L(){$.lockHaltKeepAlive?s():$.keepAliveInterval&&u(),e("lockStartTime",-1)===-1?I():it=setInterval(B,500),E()}function U(){M(),x(),t("#jitp-lock-pass").val(""),$.keepAliveInterval&&u(),n("lockStartTime",-1),l()}function I(){n("lockStartTime",t.now()),it=setInterval(B,500)}function M(){clearInterval(it)}function B(){if(e("logoutTriggered")===!0)return M(),D();if(e("lockStartTime",-1)===-1)return U();var o=e("lockStartTime")+$.lockTimeLimit-1;return t.now()>=o?(M(),e("logoutTriggered")===!0?D():N()):void W()}function E(){if(pt){q(),W();var o={message:t("#jitp-lock-display")};o=t.extend(o,$.lockBlockUiConfig),t.blockUI(o),kt=!0}}function x(){t.unblockUI(),kt=!1}function W(){if(null!==vt){var o=t.now(),n=Math.floor((e("lockStartTime",o)+$.lockTimeLimit-o)/1e3);vt.html(V(n))}}function q(){if(null===ft){var o="";o=$.lockContentCallback===!1?$.bootstrap?P():H():$.lockContentCallback($),_.append(o),ft=t("#jitp-lock-display"),$.lockCountdownMessage!==!1&&(vt=ft.find(".jitp-countdown-holder")),t("#jitp-lock-logout").on("click",function(){R()}),t("#jitp-lock-unlock").on("click",function(){K()}),t("#jitp-lock-form").length&&t("#jitp-lock-form").submit(function(){return K(),!1}),W()}}function P(){var t=null===$.lockTitle?"":'

'+$.lockTitle+"

",o=$.lockLogoutButton.replace(/\{username}/g,$.lockUsername),n=null===$.lockCountdownMessage?"":'";return'"}function H(){var t=null===$.lockTitle?"":"
"+$.lockTitle+"
",o=$.lockLogoutButton.replace(/\{username}/g,$.lockUsername),n=null===$.lockCountdownMessage?"":"
"+$.lockCountdownMessage.replace(/\{timer}/g,'')+"
";return'"}function R(){M(),Y()}function K(){$.lockPassCallback(t("#jitp-lock-pass").val())}function Q(){s(),a(),f(),M()}function Y(){Q(),n("logoutTriggered",!0),("function"!=typeof $.logoutCallback||$.logoutCallback($))&&window.location.replace($.logoutUrl)}function D(){Q(),("function"!=typeof $.logoutAutoCallback||$.logoutAutoCallback($))&&window.location.replace($.logoutAutoUrl)}function N(){return Q(),$.multiWindowSupport?void setTimeout(O,Z(100,500)):O()}function O(){return e("logoutTriggered",!1)?D():(n("logoutTriggered",!0),void(("function"!=typeof $.redirectCallback||$.redirectCallback($))&&window.location.replace($.redirectUrl)))}function X(){n("activityEvents",$.activityEvents)}function F(){t(document).on("dialogopen shown.bs.modal",function(){ct||kt||G()})}function G(){var t,o=function(){"complete"===document.readyState&&(clearInterval(t),J())};t=setInterval(o,1e3)}function J(o){o||(o=t(document));var n=0;o.find("iframe,frame").each(function(){if(t(this).hasClass("jitp-inspected")===!1)try{J(t(this).contents()),t(this).on("load",z(t(this)));var o=t(this)[n];o.attachEvent&&o.attachEvent("onload",z(t(this))),n++}catch(e){t(this).addClass("jitp-inspected cross-site")}})}function z(o){var n=o.contents(),l=e("activityEvents","");try{n.on(l,function(o){t("body").trigger(o)}),o.addClass("jitp-inspected")}catch(i){}}function V(t){var o=Math.floor(t/60);if(o<=15){var n=t%60,e=o>0?o+"m ":"";return e+=n+"s"}if(o<=75)return o<=22?"about 15 mins":o<=37?"about 30 mins":o<=52?"about 25 mins":"about 1 hour";var l=Math.floor(o/60);return o%=60,o<=15?"about "+l+" hours":o>52?"about "+(l+1)+" hours":"about "+l+"½ hours"}function Z(t,o){return Math.floor(Math.random()*(o-t))+t}var $={idleTimeLimit:1200,idleCallback:!1,idleCheckHeartbeat:2,bootstrap:!1,activityEvents:"click keypress scroll wheel mousewheel mousemove touchmove",warnEnabled:!0,warnTimeLimit:180,warnCallback:!1,warnContentCallback:!1,warnTitle:"Session Timeout",warnMessage:"Your session is about to expire!",warnStayAliveButton:"Stay Connected",warnLogoutButton:"Logout",warnCountdownMessage:"Time remaining: {timer}",warnCountdownBar:!1,redirectUrl:"/timed-out",logoutUrl:"/logout",logoutAutoUrl:null,redirectCallback:!1,logoutCallback:!1,logoutAutoCallback:!1,keepAliveInterval:600,keepAliveUrl:window.location.href,keepAliveAjaxType:"GET",keepAliveAjaxData:"",keepAliveResponse:!1,keepAliveBadUrl:window.location.href,lockEnabled:!1,lockTimeLimit:7200,lockHaltKeepAlive:!0,lockCallback:!1,lockContentCallback:!1,lockPassCallback:!1,lockTitle:null,lockUsername:"System User",lockMessage:"Enter your password to unlock the screen",lockUnlockButton:"UnLock",lockLogoutButton:"Not {username} ?",lockCountdownMessage:"Auto-logout in: {timer}",lockBlockUiConfig:{},lockLoadActive:!1,iframesSupport:!1,multiWindowSupport:!1},_=null,tt=null,ot={};ot.start=function(l){if(_=t("body"),$=t.extend($,l),null==$.logoutAutoUrl&&($.logoutAutoUrl=$.logoutUrl),$.idleTimeLimit*=1e3,$.idleCheckHeartbeat*=1e3,$.warnTimeLimit*=1e3,$.lockTimeLimit*=1e3,$.keepAliveInterval*=1e3,$.multiWindowSupport&&!t.localStorage)return console.error("jitp: Multi-Window support requested but JQuery Storage API is unavailable."),!1;if($.warnEnabled&&$.warnCallback===!1||$.lockEnabled&&$.lockCallback===!1)if($.bootstrap){if("undefined"==typeof t.fn.modal)return console.error("jitp: Bootstrap library is unavailable"),!1}else if("undefined"==typeof t.ui)return console.error("jitp: jQueryUI library is unavailable"),!1;if($.lockEnabled&&!$.multiWindowSupport)return console.error("jitp: Lock screen requested but multi-window support is not enabled."),!1;if($.lockEnabled&&$.lockCallback===!1){if("undefined"==typeof t.blockUI)return console.error("jitp: Lock screen requested but blockUI library is unavailable."),!1;if($.lockPassCallback===!1)return console.error("jitp: Lock screen requested but lockPassCallback function is not set."),!1}return $.iframesSupport&&!$.multiWindowSupport?(console.error("jitp: IFrame support requested but Multi-Window support disabled."),!1):(o(),$.lockEnabled&&($.lockLoadActive||e("lockStartTime",-1)>0)?L():(n("logoutTriggered",!1),n("warningStartTime",-1),n("lockStartTime",-1),n("lastActivity",t.now()),i(),$.keepAliveInterval&&u()),$.keepAliveInterval&&u(),X(),F(),c(),G(),!0)},ot.cleanUpLockScreen=function(){o(),t.localStorage&&tt.set("lockStartTime",-99)},ot.logout=function(){Y()},ot.displayWarning=function(){m()},ot.displayLockScreen=function(){E()},ot.initLockScreen=function(){a(),f(),A()},ot.setIdleTimeLimit=function(t){"number"==typeof t&&($.idleTimeLimit=1e3*t,ot.rollback())},ot.setWarnTimeLimit=function(t){"number"==typeof t&&($.warnTimeLimit=1e3*t,ot.rollback())},ot.setLockTimeLimit=function(t){"number"==typeof t&&($.lockTimeLimit=1e3*t,ot.rollback())},ot.rollback=function(){U(),p()},ot.iframeRecheck=function(){G()};var nt,et,lt,it,at=[-1,-1],rt=!0,ct=!1,ut=null,st=null,dt=null,pt=!0,kt=!1,ft=null,vt=null;return ot}); \ No newline at end of file diff --git a/dist/js/jquery-idleTimeout-plus.js b/dist/js/jquery-idleTimeout-plus.js index d8da996..c4064c9 100644 --- a/dist/js/jquery-idleTimeout-plus.js +++ b/dist/js/jquery-idleTimeout-plus.js @@ -1,11 +1,7 @@ /** - * This work is licensed under the Creative Commons Attribution-Share Alike 3.0 - * United States License. To view a copy of this license, - * visit http://creativecommons.org/licenses/by-sa/3.0/us/ or send a letter - * to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA. - * - * Modified by: Jason Abraham (CrashSensei) + * Written by: Jason Abraham (CrashSensei) * Email: jason@linearsoft.com + * License: GPLv3 (https://www.gnu.org/licenses/gpl-3.0-standalone.html) * * Configurable idle (no activity) timer and logout redirect for jQuery. * Supports both jQueryUI dialogs or Bootstrap modals @@ -19,7 +15,7 @@ * Multi-window support requires JQuery Storage API * Dialogs require either jQueryUI or Bootstrap * - * version 0.5.0 + * version 0.9.5 **/ (function(root, factory) { @@ -57,7 +53,7 @@ // Auto-Url settings (NOTE: if a callback is defined auto url redirection will only occur if the callback returns true) redirectUrl: '/timed-out', // URL if no action is taken after the warning/lock screen timeout logoutUrl: '/logout', // URL if the user clicks "Logout" on the warning/lock screen - logoutAutoUrl: 'null', // URL for secondary tabs that received an automatic logout trigger (to help avoid race conditions) + logoutAutoUrl: null, // URL for secondary tabs that received an automatic logout trigger (to help avoid race conditions) redirectCallback: false, logoutCallback: false, logoutAutoCallback: false, @@ -67,7 +63,9 @@ keepAliveUrl: window.location.href, // set URL to ping - does not apply if keepAliveInterval: false keepAliveAjaxType: 'GET', keepAliveAjaxData: '', - + keepAliveResponse: false, // add ability to check keep alive's response. if user was logged out by other means, or something went wrong, redirect to keepAliveBadUrl - Set to false to disable KeepAliveBadUrl redirection + keepAliveBadUrl: window.location.href, // set URL to redirect to if keepAliveResponse wasn't what was expected and if keepAliveResponse isn't set to false + // Lock Screen settings lockEnabled: false, // Set to true to enable lock screen before redirecting lockTimeLimit: 7200, // 2 hrs @@ -88,7 +86,7 @@ multiWindowSupport: false // Requires jquery-storage-api }; - var bodyElm = $('body'); // Store for jQuery optimization + var bodyElm = null; var dataStore = null; //######################################################################### // ### Public API Functions @@ -101,9 +99,10 @@ * @return {boolean} - Returns true if successfully initialized */ api.start = function(userConfig) { + bodyElm = $('body'); //--Merge default and user configs config = $.extend(config, userConfig); - if (config.logoutAutoUrl === null) config.logoutAutoUrl = config.logoutUrl; + if (config.logoutAutoUrl == null) config.logoutAutoUrl = config.logoutUrl; //--Convert secs to millisecs config.idleTimeLimit *= 1000; config.idleCheckHeartbeat *= 1000; @@ -335,7 +334,12 @@ $.ajax({ type: config.keepAliveAjaxType, url: config.keepAliveUrl, - data: config.keepAliveAjaxData + data: config.keepAliveAjaxData, + success: function(response){ + if(config.keepAliveResponse !== false && $.trim(response) !== config.keepAliveResponse){ + window.location.replace(config.keepAliveBadUrl); + } + } }); }, config.keepAliveInterval); } diff --git a/dist/js/jquery-idleTimeout-plus.min.js b/dist/js/jquery-idleTimeout-plus.min.js index b7cf1e1..f7252fe 100644 --- a/dist/js/jquery-idleTimeout-plus.min.js +++ b/dist/js/jquery-idleTimeout-plus.min.js @@ -1 +1 @@ -!function(t,o){"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof exports?module.exports=o(require("jquery")):t.IdleTimeoutPlus=o(t.jQuery)}(this,function(t){function o(){null===R&&(R=t.localStorage?t.initNamespaceStorage("jqueryIdleTimeoutPlus").localStorage:{})}function n(t,o){z.multiWindowSupport?R.set(t,o):R[t]=o}function e(t,o){if(o="undefined"==typeof o?null:o,z.multiWindowSupport){if(R.isSet(t))return R.get(t)}else if(t in R)return R[t];return o}function l(){n("warningStartTime",-1),n("lockStartTime",-1),i(),z.idleCallback!==!1&&z.idleCallback(z)}function i(){a(),n("lastActivity",t.now()),Z=setInterval(r,z.idleCheckHeartbeat)}function a(){clearInterval(Z)}function r(){var o=e("lastActivity",t.now())+z.idleTimeLimit;return e("logoutTriggered")===!0?N():e("lockStartTime",-1)!==-1?(a(),A()):t.now()>=o?(a(),z.warnEnabled?d():z.lockEnabled?L():O()):void 0}function c(){t(document).on(z.activityEvents,function(t){if("mousemove"===t.type){if(t.clientX===ot[0]&&t.clientY===ot[1])return;ot[0]=t.clientX,ot[1]=t.clientY}e("warningStartTime",-1)===-1&&e("lockStartTime",-1)===-1&&i()})}function u(){s(),$=setInterval(function(){t.ajax({type:z.keepAliveAjaxType,url:z.keepAliveUrl,data:z.keepAliveAjaxData})},z.keepAliveInterval)}function s(){clearInterval($)}function d(){k(),z.warnCallback!==!1&&(nt=z.warnCallback(z)),w()}function p(){f(),b(),n("warningStartTime",-1),l()}function k(){n("warningStartTime",t.now()),_=setInterval(m,500)}function f(){clearInterval(_)}function m(){if(e("logoutTriggered")===!0)return f(),N();if(e("warningStartTime",-1)===-1)return p();var o=e("warningStartTime")+z.warnTimeLimit-1;return t.now()>=o?(f(),z.lockEnabled?(b(),L()):O()):void v()}function w(){nt&&(g(),v(),z.bootstrap?(lt.modal("show"),lt.focus()):lt.dialog("open"),et=!0)}function b(){et=!1,null!==lt&&(z.bootstrap?(lt.modal("hide"),F.removeClass("modal-open"),t("div.modal-backdrop").remove()):lt.dialog("close"))}function v(){if(null!==lt&&(null!==it||null!==at)){var o=t.now(),n=Math.floor((e("warningStartTime",o)+z.warnTimeLimit-o)/1e3);if(null!==it&&it.html(G(n)),null!==at){var l=Math.floor(n/(z.warnTimeLimit/1e3)*100);z.bootstrap?at.css("width",l+"%"):at.progressbar("value",l)}}}function g(){if(null===lt){var t="";t=z.warnContentCallback===!1?z.bootstrap?j():C():z.warnContentCallback(z),z.bootstrap?y(t):T(t)}}function y(o){F.append(o),null!==z.warnLogoutButton&&t("#jitp-warn-logout").on("click",function(){h()}),t("#jitp-warn-alive").on("click",function(){S()}),lt=t("#jitp-warn-display"),(null!==z.warnCountdownMessage||z.warnCountdownBar)&&(it=lt.find(".jitp-countdown-holder")),z.warnCountdownBar&&(at=t("#jitp-warn-bar"))}function T(o){var n=[];null!==z.warnLogoutButton&&n.push({text:z.warnLogoutButton,click:function(){h()}}),n.push({text:z.warnStayAliveButton,click:function(){S()}}),t(o).dialog({buttons:n,closeOnEscape:!1,modal:!0,title:z.warnTitle,minWidth:320,autoOpen:!1,open:function(){null===z.warnTitle?t(this).closest(".ui-dialog").find(".ui-dialog-titlebar").hide():t(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide(),t(this).parent().find("button:nth-child(2)").focus()}}),lt=t("#jitp-warn-display"),null!==z.warnCountdownMessage&&(it=lt.find(".jitp-countdown-holder")),z.warnCountdownBar&&(at=t("#jitp-warn-bar"),at.progressbar({value:0,max:100}))}function j(){var t=null===z.warnTitle?"":'",o=null===z.warnCountdownMessage?"":"

"+z.warnCountdownMessage.replace(/\{timer}/g,'')+"

",n=null===z.warnLogoutButton?"":'",e=null===z.warnCountdownBar?"":'
';return'"}function C(){var t=null===z.warnCountdownMessage?"":"

"+z.warnCountdownMessage.replace(/\{timer}/g,'')+"

",o=null===z.warnCountdownBar?"":'
';return'

'+z.warnMessage+"

"+t+o+"
"}function h(){f(),D()}function S(){p()}function L(){z.lockHaltKeepAlive&&s(),M(),z.lockCallback!==!1&&(rt=z.lockCallback(z)),x()}function A(){z.lockHaltKeepAlive?s():z.keepAliveInterval&&u(),e("lockStartTime",-1)===-1?M():tt=setInterval(B,500),x()}function U(){I(),E(),t("#jitp-lock-pass").val(""),z.keepAliveInterval&&u(),n("lockStartTime",-1),l()}function M(){n("lockStartTime",t.now()),tt=setInterval(B,500)}function I(){clearInterval(tt)}function B(){if(e("logoutTriggered")===!0)return I(),N();if(e("lockStartTime",-1)===-1)return U();var o=e("lockStartTime")+z.lockTimeLimit-1;return t.now()>=o?(I(),e("logoutTriggered")===!0?N():O()):void q()}function x(){if(rt){W(),q();var o={message:t("#jitp-lock-display")};o=t.extend(o,z.lockBlockUiConfig),t.blockUI(o),ct=!0}}function E(){t.unblockUI(),ct=!1}function q(){if(null!==st){var o=t.now(),n=Math.floor((e("lockStartTime",o)+z.lockTimeLimit-o)/1e3);st.html(G(n))}}function W(){if(null===ut){var o="";o=z.lockContentCallback===!1?z.bootstrap?P():H():z.lockContentCallback(z),F.append(o),ut=t("#jitp-lock-display"),z.lockCountdownMessage!==!1&&(st=ut.find(".jitp-countdown-holder")),t("#jitp-lock-logout").on("click",function(){K()}),t("#jitp-lock-unlock").on("click",function(){Q()}),t("#jitp-lock-form").length&&t("#jitp-lock-form").submit(function(){return Q(),!1}),q()}}function P(){var t=null===z.lockTitle?"":'

'+z.lockTitle+"

",o=z.lockLogoutButton.replace(/\{username}/g,z.lockUsername),n=null===z.lockCountdownMessage?"":'";return'"}function H(){var t=null===z.lockTitle?"":"
"+z.lockTitle+"
",o=z.lockLogoutButton.replace(/\{username}/g,z.lockUsername),n=null===z.lockCountdownMessage?"":"
"+z.lockCountdownMessage.replace(/\{timer}/g,'')+"
";return'"}function K(){I(),D()}function Q(){z.lockPassCallback(t("#jitp-lock-pass").val())}function Y(){s(),a(),f(),I()}function D(){Y(),n("logoutTriggered",!0),("function"!=typeof z.logoutCallback||z.logoutCallback(z))&&window.location.replace(z.logoutUrl)}function N(){Y(),("function"!=typeof z.logoutAutoCallback||z.logoutAutoCallback(z))&&window.location.replace(z.logoutAutoUrl)}function O(){return Y(),z.multiWindowSupport?void setTimeout(X,J(100,500)):X()}function X(){return e("logoutTriggered",!1)?N():(n("logoutTriggered",!0),void(("function"!=typeof z.redirectCallback||z.redirectCallback(z))&&window.location.replace(z.redirectUrl)))}function G(t){var o=Math.floor(t/60);if(o<=15){var n=t%60,e=o>0?o+"m ":"";return e+=n+"s"}if(o<=75)return o<=22?"about 15 mins":o<=37?"about 30 mins":o<=52?"about 25 mins":"about 1 hour";var l=Math.floor(o/60);return o%=60,o<=15?"about "+l+" hours":o>52?"about "+(l+1)+" hours":"about "+l+"½ hours"}function J(t,o){return Math.floor(Math.random()*(o-t))+t}var z={idleTimeLimit:1200,idleCallback:!1,idleCheckHeartbeat:2,bootstrap:!1,activityEvents:"click keypress scroll wheel mousewheel mousemove touchmove",warnEnabled:!0,warnTimeLimit:180,warnCallback:!1,warnContentCallback:!1,warnTitle:"Session Timeout",warnMessage:"Your session is about to expire!",warnStayAliveButton:"Stay Connected",warnLogoutButton:"Logout",warnCountdownMessage:"Time remaining: {timer}",warnCountdownBar:!1,redirectUrl:"/timed-out",logoutUrl:"/logout",logoutAutoUrl:"null",redirectCallback:!1,logoutCallback:!1,logoutAutoCallback:!1,keepAliveInterval:600,keepAliveUrl:window.location.href,keepAliveAjaxType:"GET",keepAliveAjaxData:"",lockEnabled:!1,lockTimeLimit:7200,lockHaltKeepAlive:!0,lockCallback:!1,lockContentCallback:!1,lockPassCallback:!1,lockTitle:null,lockUsername:"System User",lockMessage:"Enter your password to unlock the screen",lockUnlockButton:"UnLock",lockLogoutButton:"Not {username} ?",lockCountdownMessage:"Auto-logout in: {timer}",lockBlockUiConfig:{},lockLoadActive:!1,multiWindowSupport:!1},F=t("body"),R=null,V={};V.start=function(l){if(z=t.extend(z,l),null===z.logoutAutoUrl&&(z.logoutAutoUrl=z.logoutUrl),z.idleTimeLimit*=1e3,z.idleCheckHeartbeat*=1e3,z.warnTimeLimit*=1e3,z.lockTimeLimit*=1e3,z.keepAliveInterval*=1e3,z.multiWindowSupport&&!t.localStorage)return console.error("jitp: Multi-Window support requested but JQuery Storage API is unavailable."),!1;if(z.warnEnabled&&z.warnCallback===!1||z.lockEnabled&&z.lockCallback===!1)if(z.bootstrap){if("undefined"==typeof t.fn.modal)return console.error("jitp: Bootstrap library is unavailable"),!1}else if("undefined"==typeof t.ui)return console.error("jitp: jQueryUI library is unavailable"),!1;if(z.lockEnabled&&!z.multiWindowSupport)return console.error("jitp: Lock screen requested but multi-window support is not enabled."),!1;if(z.lockEnabled&&z.lockCallback===!1){if("undefined"==typeof t.blockUI)return console.error("jitp: Lock screen requested but blockUI library is unavailable."),!1;if(z.lockPassCallback===!1)return console.error("jitp: Lock screen requested but lockPassCallback function is not set."),!1}return o(),z.lockEnabled&&(z.lockLoadActive||e("lockStartTime",-1)>0)?A():(n("logoutTriggered",!1),n("warningStartTime",-1),n("lockStartTime",-1),n("lastActivity",t.now()),i(),z.keepAliveInterval&&u()),z.keepAliveInterval&&u(),c(),!0},V.cleanUpLockScreen=function(){o(),t.localStorage&&R.set("lockStartTime",-99)},V.logout=function(){D()},V.displayWarning=function(){w()},V.displayLockScreen=function(){x()},V.initLockScreen=function(){a(),f(),L()},V.setIdleTimeLimit=function(t){"number"==typeof t&&(z.idleTimeLimit=1e3*t,V.rollback())},V.setWarnTimeLimit=function(t){"number"==typeof t&&(z.warnTimeLimit=1e3*t,V.rollback())},V.setLockTimeLimit=function(t){"number"==typeof t&&(z.lockTimeLimit=1e3*t,V.rollback())},V.rollback=function(){U(),p()};var Z,$,_,tt,ot=[-1,-1],nt=!0,et=!1,lt=null,it=null,at=null,rt=!0,ct=!1,ut=null,st=null;return V}); \ No newline at end of file +!function(t,o){"function"==typeof define&&define.amd?define(["jquery"],o):"object"==typeof exports?module.exports=o(require("jquery")):t.IdleTimeoutPlus=o(t.jQuery)}(this,function(t){function o(){null===F&&(F=t.localStorage?t.initNamespaceStorage("jqueryIdleTimeoutPlus").localStorage:{})}function n(t,o){J.multiWindowSupport?F.set(t,o):F[t]=o}function e(t,o){if(o="undefined"==typeof o?null:o,J.multiWindowSupport){if(F.isSet(t))return F.get(t)}else if(t in F)return F[t];return o}function l(){n("warningStartTime",-1),n("lockStartTime",-1),i(),J.idleCallback!==!1&&J.idleCallback(J)}function i(){a(),n("lastActivity",t.now()),Z=setInterval(r,J.idleCheckHeartbeat)}function a(){clearInterval(Z)}function r(){var o=e("lastActivity",t.now())+J.idleTimeLimit;return e("logoutTriggered")===!0?D():e("lockStartTime",-1)!==-1?(a(),L()):t.now()>=o?(a(),J.warnEnabled?d():J.lockEnabled?S():N()):void 0}function c(){t(document).on(J.activityEvents,function(t){if("mousemove"===t.type){if(t.clientX===ot[0]&&t.clientY===ot[1])return;ot[0]=t.clientX,ot[1]=t.clientY}e("warningStartTime",-1)===-1&&e("lockStartTime",-1)===-1&&i()})}function u(){s(),$=setInterval(function(){t.ajax({type:J.keepAliveAjaxType,url:J.keepAliveUrl,data:J.keepAliveAjaxData,success:function(o){J.keepAliveResponse!==!1&&t.trim(o)!==J.keepAliveResponse&&window.location.replace(J.keepAliveBadUrl)}})},J.keepAliveInterval)}function s(){clearInterval($)}function d(){k(),J.warnCallback!==!1&&(nt=J.warnCallback(J)),m()}function p(){f(),v(),n("warningStartTime",-1),l()}function k(){n("warningStartTime",t.now()),_=setInterval(w,500)}function f(){clearInterval(_)}function w(){if(e("logoutTriggered")===!0)return f(),D();if(e("warningStartTime",-1)===-1)return p();var o=e("warningStartTime")+J.warnTimeLimit-1;return t.now()>=o?(f(),J.lockEnabled?(v(),S()):N()):void b()}function m(){nt&&(g(),b(),J.bootstrap?(lt.modal("show"),lt.focus()):lt.dialog("open"),et=!0)}function v(){et=!1,null!==lt&&(J.bootstrap?(lt.modal("hide"),z.removeClass("modal-open"),t("div.modal-backdrop").remove()):lt.dialog("close"))}function b(){if(null!==lt&&(null!==it||null!==at)){var o=t.now(),n=Math.floor((e("warningStartTime",o)+J.warnTimeLimit-o)/1e3);if(null!==it&&it.html(X(n)),null!==at){var l=Math.floor(n/(J.warnTimeLimit/1e3)*100);J.bootstrap?at.css("width",l+"%"):at.progressbar("value",l)}}}function g(){if(null===lt){var t="";t=J.warnContentCallback===!1?J.bootstrap?h():j():J.warnContentCallback(J),J.bootstrap?y(t):T(t)}}function y(o){z.append(o),null!==J.warnLogoutButton&&t("#jitp-warn-logout").on("click",function(){C()}),t("#jitp-warn-alive").on("click",function(){A()}),lt=t("#jitp-warn-display"),(null!==J.warnCountdownMessage||J.warnCountdownBar)&&(it=lt.find(".jitp-countdown-holder")),J.warnCountdownBar&&(at=t("#jitp-warn-bar"))}function T(o){var n=[];null!==J.warnLogoutButton&&n.push({text:J.warnLogoutButton,click:function(){C()}}),n.push({text:J.warnStayAliveButton,click:function(){A()}}),t(o).dialog({buttons:n,closeOnEscape:!1,modal:!0,title:J.warnTitle,minWidth:320,autoOpen:!1,open:function(){null===J.warnTitle?t(this).closest(".ui-dialog").find(".ui-dialog-titlebar").hide():t(this).closest(".ui-dialog").find(".ui-dialog-titlebar-close").hide(),t(this).parent().find("button:nth-child(2)").focus()}}),lt=t("#jitp-warn-display"),null!==J.warnCountdownMessage&&(it=lt.find(".jitp-countdown-holder")),J.warnCountdownBar&&(at=t("#jitp-warn-bar"),at.progressbar({value:0,max:100}))}function h(){var t=null===J.warnTitle?"":'",o=null===J.warnCountdownMessage?"":"

"+J.warnCountdownMessage.replace(/\{timer}/g,'')+"

",n=null===J.warnLogoutButton?"":'",e=null===J.warnCountdownBar?"":'
';return'"}function j(){var t=null===J.warnCountdownMessage?"":"

"+J.warnCountdownMessage.replace(/\{timer}/g,'')+"

",o=null===J.warnCountdownBar?"":'
';return'

'+J.warnMessage+"

"+t+o+"
"}function C(){f(),Y()}function A(){p()}function S(){J.lockHaltKeepAlive&&s(),M(),J.lockCallback!==!1&&(rt=J.lockCallback(J)),x()}function L(){J.lockHaltKeepAlive?s():J.keepAliveInterval&&u(),e("lockStartTime",-1)===-1?M():tt=setInterval(I,500),x()}function U(){B(),E(),t("#jitp-lock-pass").val(""),J.keepAliveInterval&&u(),n("lockStartTime",-1),l()}function M(){n("lockStartTime",t.now()),tt=setInterval(I,500)}function B(){clearInterval(tt)}function I(){if(e("logoutTriggered")===!0)return B(),D();if(e("lockStartTime",-1)===-1)return U();var o=e("lockStartTime")+J.lockTimeLimit-1;return t.now()>=o?(B(),e("logoutTriggered")===!0?D():N()):void q()}function x(){if(rt){W(),q();var o={message:t("#jitp-lock-display")};o=t.extend(o,J.lockBlockUiConfig),t.blockUI(o),ct=!0}}function E(){t.unblockUI(),ct=!1}function q(){if(null!==st){var o=t.now(),n=Math.floor((e("lockStartTime",o)+J.lockTimeLimit-o)/1e3);st.html(X(n))}}function W(){if(null===ut){var o="";o=J.lockContentCallback===!1?J.bootstrap?P():H():J.lockContentCallback(J),z.append(o),ut=t("#jitp-lock-display"),J.lockCountdownMessage!==!1&&(st=ut.find(".jitp-countdown-holder")),t("#jitp-lock-logout").on("click",function(){K()}),t("#jitp-lock-unlock").on("click",function(){Q()}),t("#jitp-lock-form").length&&t("#jitp-lock-form").submit(function(){return Q(),!1}),q()}}function P(){var t=null===J.lockTitle?"":'

'+J.lockTitle+"

",o=J.lockLogoutButton.replace(/\{username}/g,J.lockUsername),n=null===J.lockCountdownMessage?"":'";return'"}function H(){var t=null===J.lockTitle?"":"
"+J.lockTitle+"
",o=J.lockLogoutButton.replace(/\{username}/g,J.lockUsername),n=null===J.lockCountdownMessage?"":"
"+J.lockCountdownMessage.replace(/\{timer}/g,'')+"
";return'"}function K(){B(),Y()}function Q(){J.lockPassCallback(t("#jitp-lock-pass").val())}function R(){s(),a(),f(),B()}function Y(){R(),n("logoutTriggered",!0),("function"!=typeof J.logoutCallback||J.logoutCallback(J))&&window.location.replace(J.logoutUrl)}function D(){R(),("function"!=typeof J.logoutAutoCallback||J.logoutAutoCallback(J))&&window.location.replace(J.logoutAutoUrl)}function N(){return R(),J.multiWindowSupport?void setTimeout(O,G(100,500)):O()}function O(){return e("logoutTriggered",!1)?D():(n("logoutTriggered",!0),void(("function"!=typeof J.redirectCallback||J.redirectCallback(J))&&window.location.replace(J.redirectUrl)))}function X(t){var o=Math.floor(t/60);if(o<=15){var n=t%60,e=o>0?o+"m ":"";return e+=n+"s"}if(o<=75)return o<=22?"about 15 mins":o<=37?"about 30 mins":o<=52?"about 25 mins":"about 1 hour";var l=Math.floor(o/60);return o%=60,o<=15?"about "+l+" hours":o>52?"about "+(l+1)+" hours":"about "+l+"½ hours"}function G(t,o){return Math.floor(Math.random()*(o-t))+t}var J={idleTimeLimit:1200,idleCallback:!1,idleCheckHeartbeat:2,bootstrap:!1,activityEvents:"click keypress scroll wheel mousewheel mousemove touchmove",warnEnabled:!0,warnTimeLimit:180,warnCallback:!1,warnContentCallback:!1,warnTitle:"Session Timeout",warnMessage:"Your session is about to expire!",warnStayAliveButton:"Stay Connected",warnLogoutButton:"Logout",warnCountdownMessage:"Time remaining: {timer}",warnCountdownBar:!1,redirectUrl:"/timed-out",logoutUrl:"/logout",logoutAutoUrl:null,redirectCallback:!1,logoutCallback:!1,logoutAutoCallback:!1,keepAliveInterval:600,keepAliveUrl:window.location.href,keepAliveAjaxType:"GET",keepAliveAjaxData:"",keepAliveResponse:!1,keepAliveBadUrl:window.location.href,lockEnabled:!1,lockTimeLimit:7200,lockHaltKeepAlive:!0,lockCallback:!1,lockContentCallback:!1,lockPassCallback:!1,lockTitle:null,lockUsername:"System User",lockMessage:"Enter your password to unlock the screen",lockUnlockButton:"UnLock",lockLogoutButton:"Not {username} ?",lockCountdownMessage:"Auto-logout in: {timer}",lockBlockUiConfig:{},lockLoadActive:!1,multiWindowSupport:!1},z=null,F=null,V={};V.start=function(l){if(z=t("body"),J=t.extend(J,l),null==J.logoutAutoUrl&&(J.logoutAutoUrl=J.logoutUrl),J.idleTimeLimit*=1e3,J.idleCheckHeartbeat*=1e3,J.warnTimeLimit*=1e3,J.lockTimeLimit*=1e3,J.keepAliveInterval*=1e3,J.multiWindowSupport&&!t.localStorage)return console.error("jitp: Multi-Window support requested but JQuery Storage API is unavailable."),!1;if(J.warnEnabled&&J.warnCallback===!1||J.lockEnabled&&J.lockCallback===!1)if(J.bootstrap){if("undefined"==typeof t.fn.modal)return console.error("jitp: Bootstrap library is unavailable"),!1}else if("undefined"==typeof t.ui)return console.error("jitp: jQueryUI library is unavailable"),!1;if(J.lockEnabled&&!J.multiWindowSupport)return console.error("jitp: Lock screen requested but multi-window support is not enabled."),!1;if(J.lockEnabled&&J.lockCallback===!1){if("undefined"==typeof t.blockUI)return console.error("jitp: Lock screen requested but blockUI library is unavailable."),!1;if(J.lockPassCallback===!1)return console.error("jitp: Lock screen requested but lockPassCallback function is not set."),!1}return o(),J.lockEnabled&&(J.lockLoadActive||e("lockStartTime",-1)>0)?L():(n("logoutTriggered",!1),n("warningStartTime",-1),n("lockStartTime",-1),n("lastActivity",t.now()),i(),J.keepAliveInterval&&u()),J.keepAliveInterval&&u(),c(),!0},V.cleanUpLockScreen=function(){o(),t.localStorage&&F.set("lockStartTime",-99)},V.logout=function(){Y()},V.displayWarning=function(){m()},V.displayLockScreen=function(){x()},V.initLockScreen=function(){a(),f(),S()},V.setIdleTimeLimit=function(t){"number"==typeof t&&(J.idleTimeLimit=1e3*t,V.rollback())},V.setWarnTimeLimit=function(t){"number"==typeof t&&(J.warnTimeLimit=1e3*t,V.rollback())},V.setLockTimeLimit=function(t){"number"==typeof t&&(J.lockTimeLimit=1e3*t,V.rollback())},V.rollback=function(){U(),p()};var Z,$,_,tt,ot=[-1,-1],nt=!0,et=!1,lt=null,it=null,at=null,rt=!0,ct=!1,ut=null,st=null;return V}); \ No newline at end of file