Skip to content
This repository was archived by the owner on Sep 19, 2024. It is now read-only.

Commit 63950b6

Browse files
committed
Merge branch 'release/1.0.3'
2 parents 770e449 + 4baf7a1 commit 63950b6

File tree

10 files changed

+73
-119
lines changed

10 files changed

+73
-119
lines changed

README.md

Lines changed: 48 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -13,59 +13,63 @@ Authored by Mike Grabski @HackedByChinese <me@mikegrabski.com>
1313
Licensed under [MIT](http://www.opensource.org/licenses/mit-license.php)
1414

1515
## Requirements
16-
* Angular 1.2.0 or later (earlier might be possible but not tested).
16+
* Angular 1.2.0 or later.
1717

1818
## What NgIdle Does
1919
Check out the Overview in the wiki.
2020

21+
## Getting Help / "How do I..."
22+
23+
I know a lot of GH projects give you the basics on the README and don't bother with a wiki. I assure you [our wiki is fully operational](https://github.com/HackedByChinese/ng-idle/wiki) and documents the full API. Before opening an issue asking me how to do something, please stop by the wiki first; I'll probably just end up linking you to your answer in the wiki anyways :wink:.
24+
2125
## Getting Started
2226

2327
Include `angular-idle.js` after `angular.js`. You can install using Bower with this command: `bower install --save ng-idle`.
2428

2529
Bare bones example:
2630

27-
// include the `ngIdle` module
28-
var app = angular.module('demo', ['ngIdle']);
29-
30-
app
31-
.controller('EventsCtrl', function($scope, Idle) {
32-
$scope.events = [];
33-
34-
$scope.$on('IdleStart', function() {
35-
// the user appears to have gone idle
36-
});
37-
38-
$scope.$on('IdleWarn', function(e, countdown) {
39-
// follows after the IdleStart event, but includes a countdown until the user is considered timed out
40-
// the countdown arg is the number of seconds remaining until then.
41-
// you can change the title or display a warning dialog from here.
42-
// you can let them resume their session by calling Idle.watch()
43-
});
44-
45-
$scope.$on('IdleTimeout', function() {
46-
// the user has timed out (meaning idleDuration + timeout has passed without any activity)
47-
// this is where you'd log them
48-
});
49-
50-
$scope.$on('IdleEnd', function() {
51-
// the user has come back from AFK and is doing stuff. if you are warning them, you can use this to hide the dialog
52-
});
53-
54-
$scope.$on('Keepalive', function() {
55-
// do something to keep the user's session alive
56-
});
57-
58-
})
59-
.config(function(IdleProvider, KeepaliveProvider) {
60-
// configure Idle settings
61-
IdleProvider.idle(5); // in seconds
62-
IdleProvider.timeout(5); // in seconds
63-
KeepaliveProvider.interval(2); // in seconds
64-
})
65-
.run(function(Idle){
66-
// start watching when the app runs. also starts the Keepalive service by default.
67-
Idle.watch();
68-
});
31+
// include the `ngIdle` module
32+
var app = angular.module('demo', ['ngIdle']);
33+
34+
app
35+
.controller('EventsCtrl', function($scope, Idle) {
36+
$scope.events = [];
37+
38+
$scope.$on('IdleStart', function() {
39+
// the user appears to have gone idle
40+
});
41+
42+
$scope.$on('IdleWarn', function(e, countdown) {
43+
// follows after the IdleStart event, but includes a countdown until the user is considered timed out
44+
// the countdown arg is the number of seconds remaining until then.
45+
// you can change the title or display a warning dialog from here.
46+
// you can let them resume their session by calling Idle.watch()
47+
});
48+
49+
$scope.$on('IdleTimeout', function() {
50+
// the user has timed out (meaning idleDuration + timeout has passed without any activity)
51+
// this is where you'd log them
52+
});
53+
54+
$scope.$on('IdleEnd', function() {
55+
// the user has come back from AFK and is doing stuff. if you are warning them, you can use this to hide the dialog
56+
});
57+
58+
$scope.$on('Keepalive', function() {
59+
// do something to keep the user's session alive
60+
});
61+
62+
})
63+
.config(function(IdleProvider, KeepaliveProvider) {
64+
// configure Idle settings
65+
IdleProvider.idle(5); // in seconds
66+
IdleProvider.timeout(5); // in seconds
67+
KeepaliveProvider.interval(2); // in seconds
68+
})
69+
.run(function(Idle){
70+
// start watching when the app runs. also starts the Keepalive service by default.
71+
Idle.watch();
72+
});
6973

7074
You may use `Keepalive` and `Idle` independently if you desire, but they are contained in the same script.
7175

@@ -83,7 +87,7 @@ Contributors are welcome. I use the `git-flow` lifecyle, so `master` is the stab
8387

8488
## Developing
8589

86-
You will need Node/NPM, Grunt, and Bower. Once you checkout from git, run `npm install`. This will install all dev and bower dependencies so you can immediately build and test your working copy.
90+
You will need Node/NPM and Grunt (don't forget `grunt-cli`). Once you checkout from git, run `npm install`. This will install all dev and bower dependencies so you can immediately build and test your working copy.
8791

8892
### Building
8993
You can build the module by running `grunt build`.

angular-idle.js

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
/*** Directives and services for responding to idle users in AngularJS
22
* @author Mike Grabski <me@mikegrabski.com>
3-
* @version v1.0.2
3+
* @version v1.0.3
44
* @link https://github.com/HackedByChinese/ng-idle.git
55
* @license MIT
66
*/
@@ -200,7 +200,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
200200
function getExpiry() {
201201
var obj = LocalStorage.get('expiry');
202202

203-
return obj.time;
203+
return new Date(obj.time);
204204
}
205205

206206
function setExpiry(date) {
@@ -276,7 +276,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
276276

277277
var wrap = function(event) {
278278
if (event.key === 'ngIdle.expiry' && event.newValue !== event.oldValue) {
279-
var val = LocalStorage.parseJson(event.newValue);
279+
var val = angular.fromJson(event.newValue);
280280
if (val.id === id) return;
281281
svc.interrupt(true);
282282
}
@@ -393,36 +393,18 @@ angular.module('ngIdle.title', [])
393393
}]);
394394

395395
angular.module('ngIdle.localStorage', [])
396-
.factory('IdleLocalStorage', ['$window', function($window) {
396+
.service('IdleLocalStorage', ['$window', function($window) {
397397
var storage = $window.localStorage;
398-
399-
function tryParseJson(value) {
400-
try {
401-
return JSON.parse(value, function(key, value) {
402-
var match = /^(\d{4})-(\d{2})-(\d{2})T(\d{2}):(\d{2}):(\d{2}(?:\.\d*)?)Z$/.exec(value);
403-
if (match) return new Date(value);
404-
405-
return value;
406-
});
407-
}
408-
catch(e) {
409-
return value;
410-
}
411-
}
412-
398+
413399
return {
414400
set: function(key, value) {
415-
storage.setItem('ngIdle.'+key, JSON.stringify(value));
401+
storage.setItem('ngIdle.'+key, angular.toJson(value));
416402
},
417403
get: function(key) {
418-
var raw = storage.getItem('ngIdle.'+key);
419-
return tryParseJson(raw);
404+
return angular.fromJson(storage.getItem('ngIdle.'+key));
420405
},
421406
remove: function(key) {
422407
storage.removeItem('ngIdle.'+key);
423-
},
424-
parseJson: function(raw) {
425-
return tryParseJson(raw);
426408
}
427409
};
428410
}]);

0 commit comments

Comments
 (0)