Skip to content

Commit 777e396

Browse files
author
Vedran Opacic
committed
fixes #9 #11 #19 #23
1 parent f0e1bf1 commit 777e396

File tree

6 files changed

+89
-47
lines changed

6 files changed

+89
-47
lines changed

.jshintrc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"globals": {
1515
"document": true,
1616
"window": true,
17-
"jQuery": true
17+
"jQuery": true,
18+
"$": true
1819
}
1920
}

Gruntfile.js

Lines changed: 61 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,67 @@
11
'use strict';
22

3-
module.exports = function (grunt) {
4-
// Show elapsed time at the end
5-
require('time-grunt')(grunt);
6-
// Load all grunt tasks
7-
require('load-grunt-tasks')(grunt);
3+
module.exports = function(grunt) {
4+
// Show elapsed time at the end
5+
require('time-grunt')(grunt);
6+
// Load all grunt tasks
7+
require('load-grunt-tasks')(grunt);
88

9-
// Project configuration.
10-
grunt.initConfig({
11-
jshint: {
12-
options: {
13-
jshintrc: '.jshintrc',
14-
reporter: require('jshint-stylish')
15-
},
16-
dist: {
17-
src: ['dist/bootstrap-session-timeout.js']
18-
}
19-
},
20-
watch: {
21-
dist: {
22-
files: '<%= jshint.dist.src %>',
23-
tasks: ['jshint:dist']
24-
}
25-
},
26-
uglify: {
27-
dist: {
28-
files: {
29-
'dist/bootstrap-session-timeout.min.js': ['<%= jshint.dist.src %>']
30-
}
9+
// Project configuration.
10+
grunt.initConfig({
11+
connect: {
12+
options: {
13+
port: 9000,
14+
// Enable hostname '0.0.0.0' to access the server from outside.
15+
hostname: '0.0.0.0',
16+
livereload: 36729
17+
},
18+
livereload: {
19+
options: {
20+
open: 'http://localhost:9000',
21+
middleware: function(connect) {
22+
return [
23+
connect.static('./')
24+
];
25+
}
26+
}
27+
}
28+
},
29+
jshint: {
30+
options: {
31+
jshintrc: '.jshintrc',
32+
reporter: require('jshint-stylish')
33+
},
34+
dist: {
35+
src: ['dist/bootstrap-session-timeout.js']
36+
}
37+
},
38+
watch: {
39+
dist: {
40+
files: '<%= jshint.dist.src %>',
41+
tasks: ['jshint:dist']
42+
},
43+
livereload: {
44+
options: {
45+
livereload: '<%= connect.options.livereload %>'
46+
},
47+
files: [
48+
'*.html',
49+
'examples/*.html',
50+
'dist/*.js'
51+
]
52+
}
53+
},
54+
uglify: {
55+
dist: {
56+
files: {
57+
'dist/bootstrap-session-timeout.min.js': ['<%= jshint.dist.src %>']
58+
}
59+
}
3160
}
32-
}
33-
});
61+
});
3462

35-
// Default task.
36-
grunt.registerTask('default', ['jshint']);
37-
grunt.registerTask('dev', ['watch']);
38-
grunt.registerTask('min', ['jshint', 'uglify']);
63+
// Default task.
64+
grunt.registerTask('default', ['jshint']);
65+
grunt.registerTask('dev', ['connect:livereload', 'watch']);
66+
grunt.registerTask('min', ['jshint', 'uglify']);
3967
};

dist/bootstrap-session-timeout.js

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
* Copyright (c) 2014 Vedran Opacic
66
* Licensed under the MIT license.
77
*/
8-
/*jshint multistr: true */
9-
'use strict';
108

119
(function($) {
12-
jQuery.sessionTimeout = function(options) {
10+
/*jshint multistr: true */
11+
'use strict';
12+
$.sessionTimeout = function(options) {
1313
var defaults = {
1414
title: 'Your Session is About to Expire!',
1515
message: 'Your session is about to expire.',
@@ -52,7 +52,7 @@
5252
if (typeof opt.onWarn !== 'function') {
5353
// If opt.countdownMessage is defined add a coundown timer message to the modal dialog
5454
var countdownMessage = opt.countdownMessage ?
55-
'<p>' + opt.countdownMessage.replace(/{timer}/g, '<span class="countdown-holder"></span>') + '</p>' : '';
55+
'<p>' + opt.countdownMessage.replace(/{timer}/g, '<span class="countdown-holder"></span>') + '</p>' : '';
5656
var coundownBarHtml = opt.countdownBar ?
5757
'<div class="progress"> \
5858
<div class="progress-bar progress-bar-striped countdown-bar active" role="progressbar" style="min-width: 15px; width: 100%;"> \
@@ -94,15 +94,25 @@
9494

9595
// Reset timer on any of these events
9696
if (!opt.ignoreUserActivity) {
97-
$(document).on('keyup mouseup mousemove touchend touchmove', function() {
97+
var mousePosition = [-1, -1];
98+
$(document).on('keyup mouseup mousemove touchend touchmove', function(e) {
99+
if (e.type === 'mousemove') {
100+
// Solves mousemove even when mouse not moving issue on Chrome:
101+
// https://code.google.com/p/chromium/issues/detail?id=241476
102+
if (e.clientX === mousePosition[0] && e.clientY === mousePosition[1]) {
103+
return;
104+
}
105+
mousePosition[0] = e.clientX;
106+
mousePosition[1] = e.clientY;
107+
}
98108
startSessionTimer();
99109

100110
// If they moved the mouse not only reset the counter
101111
// but remove the modal too!
102-
if( $('#session-timeout-dialog').length > 0 &&
103-
$('#session-timeout-dialog').data('bs.modal').isShown )
104-
{
105-
// http://stackoverflow.com/questions/11519660/twitter-bootstrap-modal-backdrop-doesnt-disappear
112+
if ($('#session-timeout-dialog').length > 0 &&
113+
$('#session-timeout-dialog').data('bs.modal') &&
114+
$('#session-timeout-dialog').data('bs.modal').isShown) {
115+
// http://stackoverflow.com/questions/11519660/twitter-bootstrap-modal-backdrop-doesnt-disappear
106116
$('#session-timeout-dialog').modal('hide');
107117
$('body').removeClass('modal-open');
108118
$('div.modal-backdrop').remove();
@@ -203,7 +213,9 @@
203213
var minLeft = Math.floor(secondsLeft / 60);
204214
var secRemain = secondsLeft % 60;
205215
var countTxt = minLeft > 0 ? minLeft + 'm' : '';
206-
if (countTxt.length > 0) { countTxt += ' '; }
216+
if (countTxt.length > 0) {
217+
countTxt += ' ';
218+
}
207219
countTxt += secRemain + 's';
208220
countdownEl.text(countTxt);
209221
} else {

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.

examples/custom-callback.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,11 @@ <h3>Session Status:</h3>
5555
redirAfter: 20000,
5656
onStart: function () {
5757
$('.jumbotron').css('background', '#398439').find('p').addClass('hidden');
58-
$('#fine').removeClass('hidden')
58+
$('#fine').removeClass('hidden');
5959
},
6060
onWarn: function () {
6161
$('.jumbotron').css('background', '#b92c28').find('p').addClass('hidden');
62-
$('#warn').removeClass('hidden')
62+
$('#warn').removeClass('hidden');
6363
},
6464
onRedir: function (opt) {
6565
window.location = opt.logoutUrl;

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
],
3030
"devDependencies": {
3131
"bower": "^1.3.5",
32+
"grunt-contrib-connect": "*",
3233
"grunt-contrib-jshint": "~0.7.0",
3334
"grunt-contrib-uglify": "~0.3.1",
3435
"grunt-contrib-watch": "~0.5.0",

0 commit comments

Comments
 (0)