Skip to content

Commit 3bd5fb0

Browse files
committed
Added an option to sent data to the keep-alive URL. Fixed some readme.md errors.
1 parent 97dd257 commit 3bd5fb0

File tree

4 files changed

+39
-23
lines changed

4 files changed

+39
-23
lines changed

README.md

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,23 @@
11
# bootstrap-session-timeout
22
Inspired by [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap)
33

4-
You can easily upgrade from jquery-sessionTimeout-bootstrap to bootstrap-session-timeout. There have been a number of major upgrades. For example, as long as the user is doing something on the page, he will never get a timeout. The original plugin launched a timeout warning dialog in a fixed amount of time regardless of user activity. See description and documentation for more information.
4+
There have been a number of major upgrades. For example, as long as the user is doing something on the page, he will never get a timeout. The original plugin launched a timeout warning dialog in a fixed amount of time regardless of user activity. See description and documentation for more information.
5+
6+
You can easily upgrade from jquery-sessionTimeout-bootstrap to bootstrap-session-timeout, since the basic options have been inherited from jquery-sessionTimeout-bootstrap and have not been renamed.
57

68
## Description
7-
After a set amount of idle time, a Bootstrap warning dialog is shown to the user with the option to either log out, or stay connected. If "Logout" button is selected, the page is redirected to a logout URL. If "Stay Connected" is selected, a keep-alive URL is requested through AJAX (optional) to keep the session alive. If no option is selected after another set amount of idle time, the page is automatically redirected to a timeout URL.
9+
After a set amount of idle time, a Bootstrap warning dialog is shown to the user with the option to either log out, or stay connected. If "Logout" button is selected, the page is redirected to a logout URL. If "Stay Connected" is selected the dialog closes and the session is kept alive. If no option is selected after another set amount of idle time, the page is automatically redirected to a set timeout URL.
10+
11+
Idle time is defined as no mouse, keyboard or touch event activity registered by the browser.
812

9-
Idle time is defined as no mouse, keyboard or touch event activity registered by the browser. As long as the user is active, the keep-alive URL also keeps getting pinged and the session stays alive. Optionally, you can also use this plugin as a simple lock mechanism on its own, if you have no need to keep the server-side session alive.
13+
As long as the user is active, the (optional) keep-alive URL keeps getting pinged and the session stays alive. If you have no need to keep the server-side session alive via the keep-alive URL, you can also use this plugin as a simple lock mechanism that redirects to your lock-session or log-out URL after a set amount of idle time.
1014

1115

1216
## Getting Started
1317

1418
1. Include `jQuery`
1519
2. Include `bootstrap.js` and `bootstrap.css`<br>(to support the modal dialog, unless you plan on using your own callback)
16-
3. Include `bootstrap-session-timeout.js` or `bootstrap-session-timeout.min.js`<br>(from the /dist folder)
20+
3. Include `bootstrap-session-timeout.js` or the minified `bootstrap-session-timeout.min.js`
1721
4. Call `$.sessionTimeout();` after document ready
1822

1923

@@ -26,7 +30,7 @@ Type: `String`
2630

2731
Default: `'Your session is about to expire.'`
2832

29-
Text shown to user in dialog after warning period.
33+
This is the text shown to user via Bootstrap warning dialog after warning period.
3034

3135
**keepAliveUrl**
3236

@@ -42,23 +46,31 @@ Type: `Boolean`
4246

4347
Default: `true`
4448

45-
If `true`, pings the **keepAliveUrl** if the user clicks "Stay Connected" on the Bootstrap warning dialog. If you have no server-side session timeout to worry about, feel free to set this one to `false` to prevent unnecessary network activity.
49+
If `true`, the plugin keeps pinging the `keepAliveUrl` for as long as the user is active. The time between two pings is set by the `keepAliveInterval` option. If you have no server-side session timeout to worry about, feel free to set this one to `false` to prevent unnecessary network activity.
4650

4751
**keepAliveInterval**
4852

4953
Type: `Integer`
5054

5155
Default: `5000` (5 seconds)
5256

53-
Minimum time in milliseconds between two keep-alive pings.
57+
Time in milliseconds between two keep-alive pings.
58+
59+
**ajaxData**
60+
61+
Type: `String`
62+
63+
Default: `''`
64+
65+
If you need to send some data via AJAX POST to your `keepAliveUrl`, you can use this option.
5466

5567
**redirUrl**
5668

5769
Type: `String`
5870

5971
Default: `'/timed-out'`
6072

61-
URL to take browser to if no action is take after warning period.
73+
URL to take browser to if no action is take after the warning.
6274

6375
**logoutUrl**
6476

@@ -82,39 +94,39 @@ Type: `Integer`
8294

8395
Default: `1200000` (20 minutes)
8496

85-
Time in milliseconds after page is opened until browser is redirected to redirUrl.
97+
Time in milliseconds after page is opened until browser is redirected to `redirUrl`.
8698

8799
**ignoreUserActivity**
88100

89101
Type: `Boolean`
90102

91103
Default: `false`
92104

93-
If `true`, this will launch the Bootstrap warning dialog / redirect (or callback functions) in a set amounts of time regardless of user activity.
105+
If `true`, this will launch the Bootstrap warning dialog / redirect (or callback functions) in a set amounts of time regardless of user activity. This in turn makes the plugin act much like the [jquery-sessionTimeout-bootstrap by maxfierke](https://github.com/maxfierke/jquery-sessionTimeout-bootstrap) plugin.
94106

95107
**onWarn**
96108

97109
Type: `Function` or `Boolean`
98110

99111
Default: `false`
100112

101-
Custom callback you can use instead of showing the Bootstrap warning dialog. Note that if you need the keepAlive option, you will need to include it yourself in the callback function. See Examples below.
113+
Custom callback you can use instead of showing the Bootstrap warning dialog.
102114

103-
Redirect action will still occur unless you also use add the onRedir callback.
115+
Redirect action will still occur unless you also add the `onRedir` callback.
104116

105117
**onRedir**
106118

107119
Type: `Function` or `Boolean`
108120

109-
Default: false
121+
Default: `false`
110122

111-
Custom callback you can use instead of redirectiong the user to **redirUrl**.
123+
Custom callback you can use instead of redirectiong the user to `redirUrl`.
112124

113125
## Examples
114126

115127
**Basic Usage**
116128

117-
Shows the warning dialog after one minute. The dialog is visible for another minute. If user takes no action, browser is redirected to `redirUrl`.
129+
Shows the warning dialog after one minute. The dialog is visible for another minute. If user takes no action (interacts with the page in any way), browser is redirected to `redirUrl`. On any user action (mouse, keyboard or touch) the timeout timer is reset. Of course, you will still need to close the dialog.
118130

119131
```js
120132
$.sessionTimeout({
@@ -127,9 +139,9 @@ $.sessionTimeout({
127139
});
128140
```
129141

130-
**With onWorn Callback**
142+
**With onWarn Callback**
131143

132-
Shows the "Warning!" alert after one minute. If user takes no action, after one more minute the browser is redirected to `redirUrl`.
144+
Shows the "Warning!" alert after one minute. If user takes no action (interacts with the page in any way), after one more minute the browser is redirected to `redirUrl`. On any user action (mouse, keyboard or touch) the timeout timer is reset.
133145

134146
```js
135147
$.sessionTimeout({
@@ -142,9 +154,9 @@ $.sessionTimeout({
142154
});
143155
```
144156

145-
**With both onWorn and onRedir Callback**
157+
**With both onWarn and onRedir Callback**
146158

147-
Console logs the "Your session will soon expire!" text after one minute. If user takes no action, after two more minutes the "Your session has expired!" alert gets shown. No redirection occurs.
159+
Console logs the "Your session will soon expire!" text after one minute. If user takes no action (interacts with the page in any way), after two more minutes the "Your session has expired!" alert gets shown. No redirection occurs. On any user action (mouse, keyboard or touch) the timeout timer is reset.
148160

149161
```js
150162
$.sessionTimeout({
@@ -163,7 +175,8 @@ $.sessionTimeout({
163175
In lieu of a formal styleguide, take care to maintain the existing coding style. Add comments for any new or changed functionality. Lint and test your code using [Grunt](http://gruntjs.com/).
164176

165177
## Release History
166-
* 2012-09-10   v1.0.0   Initial release.
178+
* 2014-01-23   v1.0.1   Added an option to sent data to the keep-alive URL.
179+
* 2014-01-22   v1.0.0   Initial release.
167180

168181
## License
169182
Copyright (c) 2014 [Orange Hill](http://www.orangehilldev.com). Licensed under the MIT license.

dist/bootstrap-session-timeout.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
var defaults = {
1414
message : 'Your session is about to expire.',
1515
keepAliveUrl : '/keep-alive',
16+
ajaxData : '',
1617
redirUrl : '/timed-out',
1718
logoutUrl : '/log-out',
1819
warnAfter : 900000, // 15 minutes
@@ -63,12 +64,14 @@
6364
}
6465

6566
// keeps the server side connection live, by pingin url set in keepAliveUrl option
67+
// keepAlivePinged is a helper var to ensure the functionality of the keepAliveInterval option
6668
var keepAlivePinged = false;
6769
function keepAlive () {
6870
if (!keepAlivePinged){
6971
$.ajax({
7072
type: 'POST',
71-
url: opt.keepAliveUrl
73+
url: opt.keepAliveUrl,
74+
data: opt.ajaxData
7275
});
7376
keepAlivePinged = true;
7477
setTimeout(function() {

dist/bootstrap-session-timeout.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-session-timeout",
3-
"version": "0.0.0",
3+
"version": "1.0.1",
44
"main": "lib/bootstrap-session-timeout.js",
55
"description": "Displays a Bootstrap display before redirecting the user after a period of inactivity.",
66
"homepage": "https://github.com/vedraan/bootstrap-session-timeout",

0 commit comments

Comments
 (0)