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

Commit 84f5169

Browse files
committed
Merge branch 'release/1.3.0'
2 parents 7c741a4 + 2852e31 commit 84f5169

File tree

7 files changed

+50
-6
lines changed

7 files changed

+50
-6
lines changed

angular-idle.js

Lines changed: 7 additions & 1 deletion
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.2.2
3+
* @version v1.3.0
44
* @link https://github.com/HackedByChinese/ng-idle.git
55
* @license MIT
66
*/
@@ -188,6 +188,10 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
188188
state.countdown--;
189189
}
190190

191+
function interrupted(anotherTab) {
192+
$rootScope.$broadcast('IdleInterrupt', anotherTab);
193+
}
194+
191195
function timeout() {
192196
stopKeepalive();
193197
$interval.cancel(state.idle);
@@ -280,6 +284,8 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
280284
if (options.timeout && this.isExpired()) {
281285
timeout();
282286
return;
287+
} else {
288+
interrupted(anotherTab);
283289
}
284290

285291
// note: you can no longer auto resume once we exceed the expiry; you will reset state by calling watch() manually

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.2.2",
3+
"version": "1.3.0",
44
"homepage": "https://github.com/HackedByChinese/ng-idle",
55
"description": "Responding to idle users in AngularJS",
66
"main": "angular-idle.js",

package.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.2.2",
3+
"version": "1.3.0",
44
"description": "Directives and services for responding to idle users in AngularJS",
55
"keywords": [
66
"angularjs",

src/idle/idle.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,10 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
108108
state.countdown--;
109109
}
110110

111+
function interrupted(anotherTab) {
112+
$rootScope.$broadcast('IdleInterrupt', anotherTab);
113+
}
114+
111115
function timeout() {
112116
stopKeepalive();
113117
$interval.cancel(state.idle);
@@ -200,6 +204,8 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
200204
if (options.timeout && this.isExpired()) {
201205
timeout();
202206
return;
207+
} else {
208+
interrupted(anotherTab);
203209
}
204210

205211
// note: you can no longer auto resume once we exceed the expiry; you will reset state by calling watch() manually

src/idle/idle.spec.js

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,6 +406,38 @@ describe('ngIdle', function() {
406406
expect(LocalStorage.set).toHaveBeenCalled();
407407
});
408408

409+
it ('interrupt() should broadcast IdleInterrupt if user has not timed out', function() {
410+
spyOn($rootScope, '$broadcast');
411+
412+
Idle.watch();
413+
Idle.interrupt();
414+
415+
expect($rootScope.$broadcast).toHaveBeenCalledWith('IdleInterrupt', undefined);
416+
});
417+
418+
it ('interrupt() should broadcast IdleInterrupt from another tab', function() {
419+
spyOn($rootScope, '$broadcast');
420+
421+
Idle.watch();
422+
Idle.interrupt(true);
423+
424+
expect($rootScope.$broadcast).toHaveBeenCalledWith('IdleInterrupt', true);
425+
});
426+
427+
it ('interrupt() should not broadcast IdleInterrupt if user has timed out', function() {
428+
spyOn($rootScope, '$broadcast');
429+
430+
// fake now to return a time in the future.
431+
spyOn(Idle, '_getNow').andCallFake(function() {
432+
return new Date(new Date().getTime() + ((DEFAULTIDLEDURATION + DEFAULTTIMEOUT + 60) * 1000));
433+
});
434+
435+
Idle.watch();
436+
Idle.interrupt();
437+
438+
expect($rootScope.$broadcast).not.toHaveBeenCalledWith('IdleInterrupt');
439+
});
440+
409441
// HACK: the body event listener is only respected the first time, and thus always checks the first Idle instance we created rather than the one we created last.
410442
// in practice, the functionality works fine, but here the test always fails. dunno how to fix it right now.
411443
// it ('document event should interrupt idle timeout', function() {

0 commit comments

Comments
 (0)