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

Commit 39b1dce

Browse files
committed
Merge branch 'release/1.1.0'
2 parents aaf2712 + 404fd5f commit 39b1dce

File tree

14 files changed

+182
-107
lines changed

14 files changed

+182
-107
lines changed

angular-idle.js

Lines changed: 22 additions & 10 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.4
3+
* @version v1.1.0
44
* @link https://github.com/HackedByChinese/ng-idle.git
55
* @license MIT
66
*/
@@ -42,7 +42,6 @@ angular.module('ngIdle.keepalive', [])
4242
ping: null
4343
};
4444

45-
4645
function handleResponse(data, status) {
4746
$rootScope.$broadcast('KeepaliveResponse', data, status);
4847
}
@@ -200,7 +199,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
200199
function getExpiry() {
201200
var obj = LocalStorage.get('expiry');
202201

203-
return new Date(obj.time);
202+
return obj && obj.time ? new Date(obj.time) : null;
204203
}
205204

206205
function setExpiry(date) {
@@ -215,6 +214,12 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
215214
_getNow: function() {
216215
return new Date();
217216
},
217+
getIdle: function(){
218+
return options.idle;
219+
},
220+
getTimeout: function(){
221+
return options.timeout;
222+
},
218223
setIdle: function(seconds) {
219224
changeOption(this, setIdle, seconds);
220225
},
@@ -223,7 +228,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
223228
},
224229
isExpired: function() {
225230
var expiry = getExpiry();
226-
return expiry && expiry <= this._getNow();
231+
return expiry !== null && expiry <= this._getNow();
227232
},
228233
running: function() {
229234
return state.running;
@@ -290,34 +295,37 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage'])
290295
];
291296
});
292297

293-
angular.module('ngIdle.countdown', [])
294-
.directive('idleCountdown', function() {
298+
angular.module('ngIdle.countdown', ['ngIdle.idle'])
299+
.directive('idleCountdown', ['Idle', function(Idle) {
295300
return {
296301
restrict: 'A',
297302
scope: {
298303
value: '=idleCountdown'
299304
},
300305
link: function($scope) {
306+
// Initialize the scope's value to the configured timeout.
307+
$scope.value = Idle.getTimeout();
308+
301309
$scope.$on('IdleWarn', function(e, countdown) {
302-
$scope.$apply(function() {
310+
$scope.$evalAsync(function() {
303311
$scope.value = countdown;
304312
});
305313
});
306314

307315
$scope.$on('IdleTimeout', function() {
308-
$scope.$apply(function() {
316+
$scope.$evalAsync(function() {
309317
$scope.value = 0;
310318
});
311319
});
312320
}
313321
};
314-
});
322+
}]);
315323

316324
angular.module('ngIdle.title', [])
317325
.factory('Title', ['$document', '$interpolate', function($document, $interpolate) {
318326

319327
function padLeft(nr, n, str){
320-
return Array(n-String(nr).length+1).join(str||'0')+nr;
328+
return new Array(n-String(nr).length+1).join(str||'0')+nr;
321329
}
322330

323331
var state = {
@@ -377,6 +385,10 @@ angular.module('ngIdle.title', [])
377385

378386
Title.store(true);
379387

388+
$scope.$on('IdleStart', function() {
389+
Title.original($element[0].innerText);
390+
});
391+
380392
$scope.$on('IdleWarn', function(e, countdown) {
381393
Title.setAsIdle(countdown);
382394
});

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.

0 commit comments

Comments
 (0)