This repository has been archived by the owner on Sep 19, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
139 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 <[email protected]> | ||
* @version v1.1.1 | ||
* @version v1.2.0 | ||
* @link https://github.com/HackedByChinese/ng-idle.git | ||
* @license MIT | ||
*/ | ||
|
@@ -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 | ||
}; | ||
|
||
|
@@ -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.'); | ||
|
||
|
@@ -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) { | ||
|
@@ -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(); | ||
|
@@ -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()) { | ||
|
@@ -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; | ||
} | ||
}; | ||
|
||
|
@@ -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); | ||
|
Large diffs are not rendered by default.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.