From b7e09eee4aa61b44f3da3344c3e5a9d06bdcb0e0 Mon Sep 17 00:00:00 2001 From: Georget Julien Date: Thu, 31 Jul 2014 10:48:23 +0200 Subject: [PATCH 1/5] Options for modal translation + ajax request Type Add extra options to translate modal text: title and buttons Add an option to specify the ajax method type (get, post ...) --- dist/bootstrap-session-timeout.js | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/dist/bootstrap-session-timeout.js b/dist/bootstrap-session-timeout.js index 7d33a03..f53eba4 100644 --- a/dist/bootstrap-session-timeout.js +++ b/dist/bootstrap-session-timeout.js @@ -11,8 +11,12 @@ (function( $ ){ jQuery.sessionTimeout = function( options ) { var defaults = { + 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', @@ -45,7 +49,21 @@ // unless user set his own callback function, prepare bootstrap modal elements and events if(typeof opt.onWarn !== 'function'){ // create timeout warning dialog - $('body').append(''); + $('body').append(''); // "Logout" button click $('#sessionTimeout-dialog-logout').on('click', function () { window.location = opt.logoutUrl; }); @@ -69,7 +87,7 @@ function keepAlive () { if (!keepAlivePinged){ $.ajax({ - type: 'POST', + type: opt.ajaxType, url: opt.keepAliveUrl, data: opt.ajaxData }); @@ -125,4 +143,4 @@ // start session timer startSessionTimer(); }; -})( jQuery ); \ No newline at end of file +})( jQuery ); From 641ad41093db341ca1cca3c2ce5ee543f66e4bf2 Mon Sep 17 00:00:00 2001 From: Georget Julien Date: Thu, 31 Jul 2014 10:52:28 +0200 Subject: [PATCH 2/5] update readme Update readme with new options --- README.md | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/README.md b/README.md index 6a36b3f..fb4e7bc 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,14 @@ As long as the user is active, the (optional) keep-alive URL keeps getting pinge ## Documentation ### Options +**title**
+ +Type: `String` + +Default: `'Your session is about to expire!'` + +This is the text shown to user via Bootstrap warning dialog after warning period. (modal title) + **message**
Type: `String` @@ -32,6 +40,22 @@ Default: `'Your session is about to expire.'` This is the text shown to user via Bootstrap warning dialog after warning period. +**logoutButton**
+ +Type: `String` + +Default: `'Logout'` + +This is the text shown to user via Bootstrap warning dialog after warning period in the logout button. + +**keepAliveButton**
+ +Type: `String` + +Default: `'Stay Connected'` + +This is the text shown to user via Bootstrap warning dialog after warning period in the Kepp Alive button. + **keepAliveUrl** Type: `String` @@ -56,6 +80,14 @@ Default: `5000` (5 seconds) Time in milliseconds between two keep-alive pings. +**ajaxType** + +Type: `String` + +Default: `'POST'` + +If you need to specify the ajax method + **ajaxData** Type: `String` From 1843788d7be47d00862674c6f526870a2c1cf77c Mon Sep 17 00:00:00 2001 From: Georget Julien Date: Thu, 31 Jul 2014 10:53:06 +0200 Subject: [PATCH 3/5] Update bootstrap-session-timeout.js --- dist/bootstrap-session-timeout.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/dist/bootstrap-session-timeout.js b/dist/bootstrap-session-timeout.js index f53eba4..344b32c 100644 --- a/dist/bootstrap-session-timeout.js +++ b/dist/bootstrap-session-timeout.js @@ -13,8 +13,8 @@ var defaults = { title : 'Your Session is About to Expire!', message : 'Your session is about to expire.', - logoutButton : 'Logout', - keepAliveButton : 'Stay Connected', + logoutButton : 'Logout', + keepAliveButton : 'Stay Connected', keepAliveUrl : '/keep-alive', ajaxType : 'POST', ajaxData : '', From 225f22ff6a0959df9dd154953e5fa19c5bade344 Mon Sep 17 00:00:00 2001 From: Georget Julien Date: Thu, 31 Jul 2014 10:53:47 +0200 Subject: [PATCH 4/5] Update bootstrap-session-timeout.js --- dist/bootstrap-session-timeout.js | 34 +++++++++++++++---------------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/dist/bootstrap-session-timeout.js b/dist/bootstrap-session-timeout.js index 344b32c..46caa73 100644 --- a/dist/bootstrap-session-timeout.js +++ b/dist/bootstrap-session-timeout.js @@ -11,10 +11,10 @@ (function( $ ){ jQuery.sessionTimeout = function( options ) { var defaults = { - title : 'Your Session is About to Expire!', + title : 'Your Session is About to Expire!', message : 'Your session is about to expire.', - logoutButton : 'Logout', - keepAliveButton : 'Stay Connected', + logoutButton : 'Logout', + keepAliveButton : 'Stay Connected', keepAliveUrl : '/keep-alive', ajaxType : 'POST', ajaxData : '', @@ -50,20 +50,20 @@ if(typeof opt.onWarn !== 'function'){ // create timeout warning dialog $('body').append(''); + \ + '); // "Logout" button click $('#sessionTimeout-dialog-logout').on('click', function () { window.location = opt.logoutUrl; }); From 776c8e7a01b0a4c4d859be6fc1319509c312c719 Mon Sep 17 00:00:00 2001 From: Georget Julien Date: Thu, 31 Jul 2014 10:55:10 +0200 Subject: [PATCH 5/5] Update minify version Update minify version --- dist/bootstrap-session-timeout.min.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dist/bootstrap-session-timeout.min.js b/dist/bootstrap-session-timeout.min.js index b6b2dee..919dce2 100644 --- a/dist/bootstrap-session-timeout.min.js +++ b/dist/bootstrap-session-timeout.min.js @@ -1 +1 @@ -"use strict";!function(a){jQuery.sessionTimeout=function(b){function c(){i||(a.ajax({type:"POST",url:h.keepAliveUrl,data:h.ajaxData}),i=!0,setTimeout(function(){i=!1},h.keepAliveInterval))}function d(){clearTimeout(f),h.keepAlive&&c(),f=setTimeout(function(){"function"!=typeof h.onWarn?a("#sessionTimeout-dialog").modal("show"):h.onWarn("warn"),e()},h.warnAfter)}function e(){clearTimeout(f),f=setTimeout(function(){"function"!=typeof h.onRedir?(e("start"),window.location=h.redirUrl):h.onRedir()},h.redirAfter-h.warnAfter)}var f,g={message:"Your session is about to expire.",keepAliveUrl:"/keep-alive",ajaxData:"",redirUrl:"/timed-out",logoutUrl:"/log-out",warnAfter:9e5,redirAfter:12e5,keepAliveInterval:5e3,keepAlive:!0,ignoreUserActivity:!1,onWarn:!1,onRedir:!1},h=g;if(b&&(h=a.extend(g,b)),h.warnAfter>=h.redirAfter)return("undefined"!=typeof console||"undefined"!=typeof console.error)&&console.error('Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".'),!1;"function"!=typeof h.onWarn&&(a("body").append(''),a("#sessionTimeout-dialog-logout").on("click",function(){window.location=h.logoutUrl}),a("#sessionTimeout-dialog").on("hide.bs.modal",function(){d()})),h.ignoreUserActivity||a(document).on("keyup mouseup mousemove touchend touchmove",function(){d()});var i=!1;d()}}(jQuery); \ No newline at end of file +"use strict";(function(e){jQuery.sessionTimeout=function(t){function o(){if(!s){e.ajax({type:r.ajaxType,url:r.keepAliveUrl,data:r.ajaxData});s=true;setTimeout(function(){s=false},r.keepAliveInterval)}}function u(){clearTimeout(i);if(r.keepAlive){o()}i=setTimeout(function(){if(typeof r.onWarn!=="function"){e("#sessionTimeout-dialog").modal("show")}else{r.onWarn("warn")}a()},r.warnAfter)}function a(){clearTimeout(i);i=setTimeout(function(){if(typeof r.onRedir!=="function"){a("start");window.location=r.redirUrl}else{r.onRedir()}},r.redirAfter-r.warnAfter)}var n={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:true,ignoreUserActivity:false,onWarn:false,onRedir:false};var r=n,i;if(t){r=e.extend(n,t)}if(r.warnAfter>=r.redirAfter){if(typeof console!=="undefined"||typeof console.error!=="undefined"){console.error('Bootstrap-session-timeout plugin is miss-configured. Option "redirAfter" must be equal or greater than "warnAfter".')}return false}if(typeof r.onWarn!=="function"){e("body").append('");e("#sessionTimeout-dialog-logout").on("click",function(){window.location=r.logoutUrl});e("#sessionTimeout-dialog").on("hide.bs.modal",function(){u()})}if(!r.ignoreUserActivity){e(document).on("keyup mouseup mousemove touchend touchmove",function(){u()})}var s=false;u()}})(jQuery)