\
');
// "Logout" button click
- $('#session-timeout-dialog-logout').on('click', function() {
- window.location = opt.logoutUrl;
- });
+ // Allow for callback execution.
+ if (typeof opt.logoutButtonCallback !== 'function') {
+ $('#session-timeout-dialog-logout').on('click', function () {
+ window.location = opt.logoutUrl;
+ });
+ } else {
+ $('#session-timeout-dialog-logout').on('click', function () {
+ opt.logoutButtonCallback();
+ });
+ }
+
// "Stay Connected" button click
- $('#session-timeout-dialog').on('hide.bs.modal', function() {
- // Restart session timer
- startSessionTimer();
- });
+ // Allow for callback execution.
+ if (typeof opt.keepAliveButtonCallback !== 'function') {
+ $('#session-timeout-dialog').on('hide.bs.modal', function () {
+ // Restart session timer
+ startSessionTimer();
+ });
+ } else {
+ $('#session-timeout-dialog').on('hide.bs.modal', function () {
+ opt.keepAliveButtonCallback();
+ startSessionTimer();
+ });
+ }
}
// Reset timer on any of these events
@@ -105,23 +134,31 @@
mousePosition[0] = e.clientX;
mousePosition[1] = e.clientY;
}
- startSessionTimer();
+
+ var isModalOpen = $('#session-timeout-dialog').length > 0 &&
+ $('#session-timeout-dialog').data('bs.modal') &&
+ $('#session-timeout-dialog').data('bs.modal').isShown;
+
+ // Reset timer if the modal is not open
+ // OR
+ // if the modal is open AND the option is set to true.
+ if (!isModalOpen || (isModalOpen && opt.resetTimerWhileModalOpen)) {
+ startSessionTimer();
+ }
// If they moved the mouse not only reset the counter
// but remove the modal too!
- if ($('#session-timeout-dialog').length > 0 &&
- $('#session-timeout-dialog').data('bs.modal') &&
- $('#session-timeout-dialog').data('bs.modal').isShown) {
+ // But only hide the modal if activityHidesModal is true.
+ if (opt.activityHidesModal === true && isModalOpen) {
// http://stackoverflow.com/questions/11519660/twitter-bootstrap-modal-backdrop-doesnt-disappear
$('#session-timeout-dialog').modal('hide');
$('body').removeClass('modal-open');
$('div.modal-backdrop').remove();
-
}
});
}
- // Keeps the server side connection live, by pingin url set in keepAliveUrl option.
+ // Keeps the server side connection live, by pinging url set in keepAliveUrl option.
// KeepAlivePinged is a helper var to ensure the functionality of the keepAliveInterval option
var keepAlivePinged = false;
diff --git a/dist/bootstrap-session-timeout.min.js b/dist/bootstrap-session-timeout.min.js
index 5c47922..6c2765c 100644
--- a/dist/bootstrap-session-timeout.min.js
+++ b/dist/bootstrap-session-timeout.min.js
@@ -1 +1 @@
-!function(a){"use strict";a.sessionTimeout=function(b){function c(){n||(a.ajax({type:i.ajaxType,url:i.keepAliveUrl,data:i.ajaxData}),n=!0,setTimeout(function(){n=!1},i.keepAliveInterval))}function d(){clearTimeout(g),(i.countdownMessage||i.countdownBar)&&f("session",!0),"function"==typeof i.onStart&&i.onStart(i),i.keepAlive&&c(),g=setTimeout(function(){"function"!=typeof i.onWarn?a("#session-timeout-dialog").modal("show"):i.onWarn(i),e()},i.warnAfter)}function e(){clearTimeout(g),a("#session-timeout-dialog").hasClass("in")||!i.countdownMessage&&!i.countdownBar||f("dialog",!0),g=setTimeout(function(){"function"!=typeof i.onRedir?window.location=i.redirUrl:i.onRedir(i)},i.redirAfter-i.warnAfter)}function f(b,c){clearTimeout(j.timer),"dialog"===b&&c?j.timeLeft=Math.floor((i.redirAfter-i.warnAfter)/1e3):"session"===b&&c&&(j.timeLeft=Math.floor(i.redirAfter/1e3)),i.countdownBar&&"dialog"===b?j.percentLeft=Math.floor(j.timeLeft/((i.redirAfter-i.warnAfter)/1e3)*100):i.countdownBar&&"session"===b&&(j.percentLeft=Math.floor(j.timeLeft/(i.redirAfter/1e3)*100));var d=a(".countdown-holder"),e=j.timeLeft>=0?j.timeLeft:0;if(i.countdownSmart){var g=Math.floor(e/60),h=e%60,k=g>0?g+"m":"";k.length>0&&(k+=" "),k+=h+"s",d.text(k)}else d.text(e+"s");i.countdownBar&&a(".countdown-bar").css("width",j.percentLeft+"%"),j.timeLeft=j.timeLeft-1,j.timer=setTimeout(function(){f(b)},1e3)}var g,h={title:"Your Session is About to Expire!",message:"Your session is about to expire.",logoutButton:"Logout",keepAliveButton:"Stay Connected",keepAliveUrl:"/keep-alive",ajaxType:"POST",ajaxData:"",redirUrl:"/timed-out",logoutUrl:"/log-out",warnAfter:9e5,redirAfter:12e5,keepAliveInterval:5e3,keepAlive:!0,ignoreUserActivity:!1,onStart:!1,onWarn:!1,onRedir:!1,countdownMessage:!1,countdownBar:!1,countdownSmart:!1},i=h,j={};if(b&&(i=a.extend(h,b)),i.warnAfter>=i.redirAfter)return console.error('Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'),!1;if("function"!=typeof i.onWarn){var k=i.countdownMessage?"
"+i.countdownMessage.replace(/{timer}/g,'')+"
":"",l=i.countdownBar?'
':"";a("body").append('
'+i.message+"
"+k+" "+l+'
"),a("#session-timeout-dialog-logout").on("click",function(){window.location=i.logoutUrl}),a("#session-timeout-dialog").on("hide.bs.modal",function(){d()})}if(!i.ignoreUserActivity){var m=[-1,-1];a(document).on("keyup mouseup mousemove touchend touchmove",function(b){if("mousemove"===b.type){if(b.clientX===m[0]&&b.clientY===m[1])return;m[0]=b.clientX,m[1]=b.clientY}d(),a("#session-timeout-dialog").length>0&&a("#session-timeout-dialog").data("bs.modal")&&a("#session-timeout-dialog").data("bs.modal").isShown&&(a("#session-timeout-dialog").modal("hide"),a("body").removeClass("modal-open"),a("div.modal-backdrop").remove())})}var n=!1;d()}}(jQuery);
\ No newline at end of file
+(function(t){"use strict";t.sessionTimeout=function(e){function o(){p||(t.ajax({type:l.ajaxType,url:l.keepAliveUrl,data:l.ajaxData}),p=!0,setTimeout(function(){p=!1},l.keepAliveInterval))}function i(){clearTimeout(s),(l.countdownMessage||l.countdownBar)&&a("session",!0),"function"==typeof l.onStart&&l.onStart(l),l.keepAlive&&o(),s=setTimeout(function(){"function"!=typeof l.onWarn?t("#session-timeout-dialog").modal("show"):l.onWarn(l),n()},l.warnAfter)}function n(){clearTimeout(s),t("#session-timeout-dialog").hasClass("in")||!l.countdownMessage&&!l.countdownBar||a("dialog",!0),s=setTimeout(function(){"function"!=typeof l.onRedir?window.location=l.redirUrl:l.onRedir(l)},l.redirAfter-l.warnAfter)}function a(e,o){clearTimeout(d.timer),"dialog"===e&&o?d.timeLeft=Math.floor((l.redirAfter-l.warnAfter)/1e3):"session"===e&&o&&(d.timeLeft=Math.floor(l.redirAfter/1e3)),l.countdownBar&&"dialog"===e?d.percentLeft=Math.floor(d.timeLeft/((l.redirAfter-l.warnAfter)/1e3)*100):l.countdownBar&&"session"===e&&(d.percentLeft=Math.floor(d.timeLeft/(l.redirAfter/1e3)*100));var i=t(".countdown-holder"),n=d.timeLeft>=0?d.timeLeft:0;if(l.countdownSmart){var s=Math.floor(n/60),r=n%60,u=s>0?s+"m":"";u.length>0&&(u+=" "),u+=r+"s",i.text(u)}else i.text(n+"s");l.countdownBar&&t(".countdown-bar").css("width",d.percentLeft+"%"),d.timeLeft=d.timeLeft-1,d.timer=setTimeout(function(){a(e)},1e3)}var s,r={title:"Your Session is About to Expire!",message:"Your session is about to expire.",logoutButton:"Logout",logoutButtonCallback:!1,keepAliveButton:"Stay Connected",keepAliveButtonCallback:!1,keepAliveUrl:"/keep-alive",ajaxType:"POST",ajaxData:"",redirUrl:"/timed-out",logoutUrl:"/log-out",warnAfter:9e5,redirAfter:12e5,keepAliveInterval:5e3,keepAlive:!0,ignoreUserActivity:!1,onStart:!1,onWarn:!1,onRedir:!1,countdownMessage:!1,countdownBar:!1,countdownSmart:!1,activityHidesModal:!0,resetTimerWhileModalOpen:!0,isModalStatic:!1},l=r,d={};if(e&&(l=t.extend(r,e)),l.warnAfter>=l.redirAfter)return console.error('Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'),!1;if("function"!=typeof l.onWarn){var u=l.countdownMessage?"
"+l.countdownMessage.replace(/{timer}/g,'')+"
":"",c=l.countdownBar?'
':"",m=l.isModalStatic?'data-backdrop="static" data-keyboard="false"':"";t("body").append('
'+l.message+"
"+u+" "+c+'
"),"function"!=typeof l.logoutButtonCallback?t("#session-timeout-dialog-logout").on("click",function(){window.location=l.logoutUrl}):t("#session-timeout-dialog-logout").on("click",function(){l.logoutButtonCallback()}),"function"!=typeof l.keepAliveButtonCallback?t("#session-timeout-dialog").on("hide.bs.modal",function(){i()}):t("#session-timeout-dialog").on("hide.bs.modal",function(){l.keepAliveButtonCallback(),i()})}if(!l.ignoreUserActivity){var f=[-1,-1];t(document).on("keyup mouseup mousemove touchend touchmove",function(e){if("mousemove"===e.type){if(e.clientX===f[0]&&e.clientY===f[1])return;f[0]=e.clientX,f[1]=e.clientY}var o=t("#session-timeout-dialog").length>0&&t("#session-timeout-dialog").data("bs.modal")&&t("#session-timeout-dialog").data("bs.modal").isShown;(!o||o&&l.resetTimerWhileModalOpen)&&i(),!0===l.activityHidesModal&&o&&(t("#session-timeout-dialog").modal("hide"),t("body").removeClass("modal-open"),t("div.modal-backdrop").remove())})}var p=!1;i()}})(jQuery);