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

Commit

Permalink
Merge branch 'release/1.1.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
grbsk committed May 7, 2015
2 parents aaf2712 + 404fd5f commit 39b1dce
Show file tree
Hide file tree
Showing 14 changed files with 182 additions and 107 deletions.
32 changes: 22 additions & 10 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 <[email protected]>
* @version v1.0.4
* @version v1.1.0
* @link https://github.com/HackedByChinese/ng-idle.git
* @license MIT
*/
Expand Down Expand Up @@ -42,7 +42,6 @@ angular.module('ngIdle.keepalive', [])
ping: null
};


function handleResponse(data, status) {
$rootScope.$broadcast('KeepaliveResponse', data, status);
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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);
},
Expand All @@ -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;
Expand Down Expand Up @@ -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 = {
Expand Down Expand Up @@ -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);
});
Expand Down
2 changes: 1 addition & 1 deletion angular-idle.map

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

Loading

0 comments on commit 39b1dce

Please sign in to comment.