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
14 changed files
with
182 additions
and
107 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,6 +1,6 @@ | ||
/*** Directives and services for responding to idle users in AngularJS | ||
* @author Mike Grabski <[email protected]> | ||
* @version v1.0.4 | ||
* @version v1.1.0 | ||
* @link https://github.com/HackedByChinese/ng-idle.git | ||
* @license MIT | ||
*/ | ||
|
@@ -42,7 +42,6 @@ angular.module('ngIdle.keepalive', []) | |
ping: null | ||
}; | ||
|
||
|
||
function handleResponse(data, status) { | ||
$rootScope.$broadcast('KeepaliveResponse', data, status); | ||
} | ||
|
@@ -200,7 +199,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) | |
function getExpiry() { | ||
var obj = LocalStorage.get('expiry'); | ||
|
||
return new Date(obj.time); | ||
return obj && obj.time ? new Date(obj.time) : null; | ||
} | ||
|
||
function setExpiry(date) { | ||
|
@@ -215,6 +214,12 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) | |
_getNow: function() { | ||
return new Date(); | ||
}, | ||
getIdle: function(){ | ||
return options.idle; | ||
}, | ||
getTimeout: function(){ | ||
return options.timeout; | ||
}, | ||
setIdle: function(seconds) { | ||
changeOption(this, setIdle, seconds); | ||
}, | ||
|
@@ -223,7 +228,7 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) | |
}, | ||
isExpired: function() { | ||
var expiry = getExpiry(); | ||
return expiry && expiry <= this._getNow(); | ||
return expiry !== null && expiry <= this._getNow(); | ||
}, | ||
running: function() { | ||
return state.running; | ||
|
@@ -290,34 +295,37 @@ angular.module('ngIdle.idle', ['ngIdle.keepalive', 'ngIdle.localStorage']) | |
]; | ||
}); | ||
|
||
angular.module('ngIdle.countdown', []) | ||
.directive('idleCountdown', function() { | ||
angular.module('ngIdle.countdown', ['ngIdle.idle']) | ||
.directive('idleCountdown', ['Idle', function(Idle) { | ||
return { | ||
restrict: 'A', | ||
scope: { | ||
value: '=idleCountdown' | ||
}, | ||
link: function($scope) { | ||
// Initialize the scope's value to the configured timeout. | ||
$scope.value = Idle.getTimeout(); | ||
|
||
$scope.$on('IdleWarn', function(e, countdown) { | ||
$scope.$apply(function() { | ||
$scope.$evalAsync(function() { | ||
$scope.value = countdown; | ||
}); | ||
}); | ||
|
||
$scope.$on('IdleTimeout', function() { | ||
$scope.$apply(function() { | ||
$scope.$evalAsync(function() { | ||
$scope.value = 0; | ||
}); | ||
}); | ||
} | ||
}; | ||
}); | ||
}]); | ||
|
||
angular.module('ngIdle.title', []) | ||
.factory('Title', ['$document', '$interpolate', function($document, $interpolate) { | ||
|
||
function padLeft(nr, n, str){ | ||
return Array(n-String(nr).length+1).join(str||'0')+nr; | ||
return new Array(n-String(nr).length+1).join(str||'0')+nr; | ||
} | ||
|
||
var state = { | ||
|
@@ -377,6 +385,10 @@ angular.module('ngIdle.title', []) | |
|
||
Title.store(true); | ||
|
||
$scope.$on('IdleStart', function() { | ||
Title.original($element[0].innerText); | ||
}); | ||
|
||
$scope.$on('IdleWarn', function(e, countdown) { | ||
Title.setAsIdle(countdown); | ||
}); | ||
|
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.