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

Commit ac5f51d

Browse files
committed
Merge branch 'release/1.2.0'
2 parents 5716080 + c1650c9 commit ac5f51d

File tree

11 files changed

+139
-37
lines changed

11 files changed

+139
-37
lines changed

.travis.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
sudo: false
22
language: node_js
33
node_js:
4-
- "0.10"
4+
- "5.2.0"
55

66
before_script:
77
- npm install -g grunt-cli

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ Ng-Idle
33

44
[![Join the chat at https://gitter.im/HackedByChinese/ng-idle](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/HackedByChinese/ng-idle?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![Build Status](https://travis-ci.org/HackedByChinese/ng-idle.png?branch=master)](https://travis-ci.org/HackedByChinese/ng-idle)
55

6+
**Angular 2 Developers**: This module is for Angular 1 only. Check out [ng2-idle](https://github.com/HackedByChinese/ng2-idle) for the Angular 2 version.
7+
68
## About
79
You may wish to detect idle users and respond, for example, to log them out so their sensitive data is protected, or taunt them, or whatever. I don't care.
810

angular-idle.js

Lines changed: 47 additions & 16 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.1.1
3+
* @version v1.2.0
44
* @link https://github.com/HackedByChinese/ng-idle.git
55
* @license MIT
66
*/
@@ -85,6 +85,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
8585
timeout: 30, // in seconds (default is 30sec)
8686
autoResume: 'idle', // lets events automatically resume (unsets idle state/resets warning)
8787
interrupt: 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll',
88+
windowInterrupt: null,
8889
keepalive: true
8990
};
9091

@@ -102,6 +103,10 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
102103
options.interrupt = events;
103104
};
104105

106+
this.windowInterrupt = function(events) {
107+
options.windowInterrupt = events;
108+
};
109+
105110
var setIdle = this.idle = function(seconds) {
106111
if (seconds <= 0) throw new Error('Idle must be a value in seconds, greater than 0.');
107112

@@ -148,8 +153,6 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
148153
state.idling = !state.idling;
149154
var name = state.idling ? 'Start' : 'End';
150155

151-
$rootScope.$broadcast('Idle' + name);
152-
153156
if (state.idling) {
154157
stopKeepalive();
155158
if (options.timeout) {
@@ -161,10 +164,19 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
161164
startKeepalive();
162165
}
163166

167+
$rootScope.$broadcast('Idle' + name);
168+
164169
$interval.cancel(state.idle);
165170
}
166171

167172
function countdown() {
173+
174+
// check not called when no longer idling
175+
// possible with multiple tabs
176+
if(!state.idling){
177+
return;
178+
}
179+
168180
// countdown has expired, so signal timeout
169181
if (state.countdown <= 0) {
170182
timeout();
@@ -262,7 +274,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
262274

263275
stopKeepalive();
264276
},
265-
interrupt: function(noExpiryUpdate) {
277+
interrupt: function(anotherTab) {
266278
if (!state.running) return;
267279

268280
if (options.timeout && this.isExpired()) {
@@ -271,7 +283,24 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
271283
}
272284

273285
// note: you can no longer auto resume once we exceed the expiry; you will reset state by calling watch() manually
274-
if (options.autoResume === 'idle' || (options.autoResume === 'notIdle' && !state.idling)) this.watch(noExpiryUpdate);
286+
if (anotherTab || options.autoResume === 'idle' || (options.autoResume === 'notIdle' && !state.idling)) this.watch(anotherTab);
287+
}
288+
};
289+
290+
var lastMove = {
291+
clientX: null,
292+
clientY: null,
293+
swap: function(event) {
294+
var last = {clientX: this.clientX, clientY: this.clientY};
295+
this.clientX = event.clientX;
296+
this.clientY = event.clientY;
297+
return last;
298+
},
299+
hasMoved: function(event) {
300+
var last = this.swap(event);
301+
if (this.clientX === null || event.movementX || event.movementY) return true;
302+
else if (last.clientX != event.clientX || last.clientY != event.clientY) return true;
303+
else return false;
275304
}
276305
};
277306

@@ -280,21 +309,23 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
280309
return; // Fix for Chrome desktop notifications, triggering mousemove event.
281310
}
282311

283-
/*
284-
note:
285-
webkit fires fake mousemove events when the user has done nothing, so the idle will never time out while the cursor is over the webpage
286-
Original webkit bug report which caused this issue:
287-
https://bugs.webkit.org/show_bug.cgi?id=17052
288-
Chromium bug reports for issue:
289-
https://code.google.com/p/chromium/issues/detail?id=5598
290-
https://code.google.com/p/chromium/issues/detail?id=241476
291-
https://code.google.com/p/chromium/issues/detail?id=317007
292-
*/
293-
if (event.type !== 'mousemove' || angular.isUndefined(event.movementX) || (event.movementX || event.movementY)) {
312+
if (event.type !== 'mousemove' || lastMove.hasMoved(event)) {
294313
svc.interrupt();
295314
}
296315
});
297316

317+
if(options.windowInterrupt) {
318+
var eventList = options.windowInterrupt.split(' ');
319+
var fn = function() {
320+
svc.interrupt();
321+
};
322+
323+
for(var i=0; i<eventList.length; i++) {
324+
if ($window.addEventListener) $window.addEventListener(eventList[i], fn, false);
325+
else $window.attachEvent(eventList[i], fn)
326+
}
327+
}
328+
298329
var wrap = function(event) {
299330
if (event.key === 'ngIdle.expiry' && event.newValue && event.newValue !== event.oldValue) {
300331
var val = angular.fromJson(event.newValue);

angular-idle.map

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

angular-idle.min.js

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bower.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ng-idle",
3-
"version": "1.1.1",
3+
"version": "1.2.0",
44
"homepage": "https://github.com/HackedByChinese/ng-idle",
55
"description": "Responding to idle users in AngularJS",
66
"main": "angular-idle.js",

karma.conf.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ module.exports = function(config) {
1414

1515
// list of files / patterns to load in the browser
1616
files: [
17+
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
1718
'+(bower_components|node_modules)/jquery/?(dist)/jquery.js',
1819
'+(bower_components|node_modules)/angular/angular.js',
1920
'+(bower_components|node_modules)/angular-mocks/angular-mocks.js',

0 commit comments

Comments
 (0)