Skip to content

Commit

Permalink
Merge branch 'release/1.2.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
moribvndvs committed Mar 3, 2016
2 parents 5716080 + c1650c9 commit ac5f51d
Show file tree
Hide file tree
Showing 11 changed files with 139 additions and 37 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
sudo: false
language: node_js
node_js:
- "0.10"
- "5.2.0"

before_script:
- npm install -g grunt-cli
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ Ng-Idle

[![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)

**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.

## About
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.

Expand Down
63 changes: 47 additions & 16 deletions angular-idle.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*** Directives and services for responding to idle users in AngularJS
* @author Mike Grabski <me@mikegrabski.com>
* @version v1.1.1
* @version v1.2.0
* @link https://github.com/HackedByChinese/ng-idle.git
* @license MIT
*/
Expand Down Expand Up @@ -85,6 +85,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
timeout: 30, // in seconds (default is 30sec)
autoResume: 'idle', // lets events automatically resume (unsets idle state/resets warning)
interrupt: 'mousemove keydown DOMMouseScroll mousewheel mousedown touchstart touchmove scroll',
windowInterrupt: null,
keepalive: true
};

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

this.windowInterrupt = function(events) {
options.windowInterrupt = events;
};

var setIdle = this.idle = function(seconds) {
if (seconds <= 0) throw new Error('Idle must be a value in seconds, greater than 0.');

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

$rootScope.$broadcast('Idle' + name);

if (state.idling) {
stopKeepalive();
if (options.timeout) {
Expand All @@ -161,10 +164,19 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
startKeepalive();
}

$rootScope.$broadcast('Idle' + name);

$interval.cancel(state.idle);
}

function countdown() {

// check not called when no longer idling
// possible with multiple tabs
if(!state.idling){
return;
}

// countdown has expired, so signal timeout
if (state.countdown <= 0) {
timeout();
Expand Down Expand Up @@ -262,7 +274,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])

stopKeepalive();
},
interrupt: function(noExpiryUpdate) {
interrupt: function(anotherTab) {
if (!state.running) return;

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

// note: you can no longer auto resume once we exceed the expiry; you will reset state by calling watch() manually
if (options.autoResume === 'idle' || (options.autoResume === 'notIdle' && !state.idling)) this.watch(noExpiryUpdate);
if (anotherTab || options.autoResume === 'idle' || (options.autoResume === 'notIdle' && !state.idling)) this.watch(anotherTab);
}
};

var lastMove = {
clientX: null,
clientY: null,
swap: function(event) {
var last = {clientX: this.clientX, clientY: this.clientY};
this.clientX = event.clientX;
this.clientY = event.clientY;
return last;
},
hasMoved: function(event) {
var last = this.swap(event);
if (this.clientX === null || event.movementX || event.movementY) return true;
else if (last.clientX != event.clientX || last.clientY != event.clientY) return true;
else return false;
}
};

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

/*
note:
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
Original webkit bug report which caused this issue:
https://bugs.webkit.org/show_bug.cgi?id=17052
Chromium bug reports for issue:
https://code.google.com/p/chromium/issues/detail?id=5598
https://code.google.com/p/chromium/issues/detail?id=241476
https://code.google.com/p/chromium/issues/detail?id=317007
*/
if (event.type !== 'mousemove' || angular.isUndefined(event.movementX) || (event.movementX || event.movementY)) {
if (event.type !== 'mousemove' || lastMove.hasMoved(event)) {
svc.interrupt();
}
});

if(options.windowInterrupt) {
var eventList = options.windowInterrupt.split(' ');
var fn = function() {
svc.interrupt();
};

for(var i=0; i<eventList.length; i++) {
if ($window.addEventListener) $window.addEventListener(eventList[i], fn, false);
else $window.attachEvent(eventList[i], fn)
}
}

var wrap = function(event) {
if (event.key === 'ngIdle.expiry' && event.newValue && event.newValue !== event.oldValue) {
var val = angular.fromJson(event.newValue);
Expand Down
2 changes: 1 addition & 1 deletion angular-idle.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions angular-idle.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bower.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "ng-idle",
"version": "1.1.1",
"version": "1.2.0",
"homepage": "https://github.com/HackedByChinese/ng-idle",
"description": "Responding to idle users in AngularJS",
"main": "angular-idle.js",
Expand Down
1 change: 1 addition & 0 deletions karma.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ module.exports = function(config) {

// list of files / patterns to load in the browser
files: [
'./node_modules/phantomjs-polyfill/bind-polyfill.js',
'+(bower_components|node_modules)/jquery/?(dist)/jquery.js',
'+(bower_components|node_modules)/angular/angular.js',
'+(bower_components|node_modules)/angular-mocks/angular-mocks.js',
Expand Down
Loading

0 comments on commit ac5f51d

Please sign in to comment.