Skip to content

Commit c178e49

Browse files
committed
Added optional onStart callback. All custom callbacks nowreceive options object as argument. Added optional countdown message. Added optional countdown bar. Fixes orangehill#6, fixes orangehill#4.
1 parent ed43bf9 commit c178e49

15 files changed

+514
-95
lines changed

.gitignore

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,4 @@
1-
/node_modules/
1+
/bower_components/
2+
/node_modules/
3+
*.sublime-project
4+
*.sublime-workspace

Gruntfile.js

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,19 +15,12 @@ module.exports = function (grunt) {
1515
},
1616
dist: {
1717
src: ['dist/bootstrap-session-timeout.js']
18-
},
19-
test: {
20-
src: ['test/**/*.js']
2118
}
2219
},
2320
watch: {
2421
dist: {
2522
files: '<%= jshint.dist.src %>',
2623
tasks: ['jshint:dist']
27-
},
28-
test: {
29-
files: '<%= jshint.test.src %>',
30-
tasks: ['jshint:test']
3124
}
3225
},
3326
uglify: {

README.md

Lines changed: 61 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,10 @@ As long as the user is active, the (optional) keep-alive URL keeps getting pinge
1515

1616
## Getting Started
1717

18-
1. Include `jQuery`
19-
2. Include `bootstrap.js` and `bootstrap.css`<br>(to support the modal dialog, unless you plan on using your own callback)
20-
3. Include `bootstrap-session-timeout.js` or the minified `bootstrap-session-timeout.min.js`
21-
4. Call `$.sessionTimeout();` after document ready
18+
1. Download or git clone.
19+
2. Run `bower install` to install dependencies or if you prefer to do it manually: include jQuery, Bootstrap JS and CSS (required if you want to use Bootstrap modal window).
20+
3. Include `bootstrap-session-timeout.js` or the minified version `bootstrap-session-timeout.min.js`
21+
4. Call `$.sessionTimeout();` on document ready. See available options below or take a look at the examples.
2222

2323

2424

@@ -136,13 +136,38 @@ Default: `false`
136136

137137
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.
138138

139+
**countdownMessage**
140+
141+
Type: `String` or `Boolean`
142+
143+
Default: `false`
144+
145+
If you want a custom sentence to appear in the warning dialog with a timer showing the seconds remaining, use this option. Example: `countdownMessage: 'Redirecting in {timer} seconds.'` Place the `{timer}` string where you want the numeric countdown (seconds) to appear. Another example: `countdownMessage: '{timer} seconds remaining.'`. Can be combined with countdownBar option or used independently.
146+
147+
**countdownBar**
148+
149+
Type: `Boolean`
150+
151+
Default: `false`
152+
153+
If `true`, ads a countdown bar (uses Bootstrap progress bar) to the warning dialog. Can be combined with countdownMessage option or used independently.
154+
155+
**onStart**
156+
157+
Type: `Function` or `Boolean`
158+
159+
Default: `false`
160+
161+
Optional callback fired when first calling the plugin and every time user refreshes the session (on any mouse, keyboard or touch action). Takes options object as the only argument.
162+
163+
139164
**onWarn**
140165

141166
Type: `Function` or `Boolean`
142167

143168
Default: `false`
144169

145-
Custom callback you can use instead of showing the Bootstrap warning dialog.
170+
Custom callback you can use instead of showing the Bootstrap warning dialog. Takes options object as the only argument.
146171

147172
Redirect action will still occur unless you also add the `onRedir` callback.
148173

@@ -152,10 +177,13 @@ Type: `Function` or `Boolean`
152177

153178
Default: `false`
154179

155-
Custom callback you can use instead of redirectiong the user to `redirUrl`.
180+
Custom callback you can use instead of redirectiong the user to `redirUrl`. Takes options object as the only argument.
156181

157182
## Examples
158183

184+
You can play around with the examples in the `/examples` directory.
185+
186+
159187
**Basic Usage**
160188

161189
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.
@@ -180,7 +208,7 @@ $.sessionTimeout({
180208
redirUrl: 'locked.html',
181209
warnAfter: 60000,
182210
redirAfter: 120000,
183-
onWarn: function{
211+
onWarn: function () {
184212
alert('Warning!');
185213
}
186214
});
@@ -194,21 +222,43 @@ Console logs the "Your session will soon expire!" text after one minute. If user
194222
$.sessionTimeout({
195223
warnAfter: 60000,
196224
redirAfter: 180000,
197-
onWarn: function{
225+
onWarn: function () {
198226
console.log('Your session will soon expire!');
199227
},
200-
onRedir: function{
228+
onRedir: function () {
201229
alert('Your session has expired!');
202230
}
203231
});
204232
```
205233

234+
**With countdown message and bar displayed in warning dialog**
235+
236+
Same as basic usage except you'll also see the countdown message and countdown bar in the warning dialog. Uses Bootstrap progress bar. In countdownMessage place the `{timer}` string where you want the numeric countdown (seconds) to appear.
237+
238+
```js
239+
$.sessionTimeout({
240+
keepAliveUrl: 'keep-alive.html',
241+
logoutUrl: 'login.html',
242+
redirUrl: 'locked.html',
243+
warnAfter: 60000,
244+
redirAfter: 120000,
245+
countdownMessage: 'Redirecting in {timer} seconds.',
246+
countdownBar: true
247+
});
248+
```
249+
206250
## Contributing
207251
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/).
208252

209253
## Release History
210-
* 2014-01-23   v1.0.1   Added an option to send data to the keep-alive URL.
211-
* 2014-01-22   v1.0.0   Initial release.
254+
* **1.0.2** `2015-02-10`
255+
* Added optional onStart callback.
256+
* All custom callbacks nowreceive options object as argument.
257+
* Added optional countdown message. Added optional countdown bar.
258+
* **1.0.1** `2014-01-23`
259+
* Added an option to send data to the keep-alive URL.
260+
* **1.0.0** `2014-01-22`
261+
* Initial release.
212262

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

bower.json

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bootstrap-session-timeout",
3-
"version": "1.0.1",
3+
"version": "1.0.2",
44
"homepage": "https://github.com/orangehill/bootstrap-session-timeout",
55
"authors": [
66
"Vedran Opacic <vedran.opacic@orangehilldev.com>"
@@ -24,5 +24,9 @@
2424
"bower_components",
2525
"test",
2626
"tests"
27-
]
27+
],
28+
"dependencies": {
29+
"bootstrap": "~3.3.2",
30+
"jquery": "~2.1.3"
31+
}
2832
}

0 commit comments

Comments
 (0)