/
index.html
83 lines (71 loc) · 2.31 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
<html ng-app="demo">
<head>
<title title>NgIdle Sample</title>
<script src="../node_modules/angular/angular.js"></script>
<script src="../angular-idle.min.js"></script>
<script type="text/javascript">
var app = angular.module('demo', ['ngIdle']);
app
.controller('EventsCtrl', function($scope, Idle) {
$scope.events = [];
$scope.idle = 5;
$scope.timeout = 5;
$scope.$on('IdleStart', function() {
addEvent({event: 'IdleStart', date: new Date()});
});
$scope.$on('IdleEnd', function() {
addEvent({event: 'IdleEnd', date: new Date()});
});
$scope.$on('IdleWarn', function(e, countdown) {
addEvent({event: 'IdleWarn', date: new Date(), countdown: countdown});
});
$scope.$on('IdleTimeout', function() {
addEvent({event: 'IdleTimeout', date: new Date()});
});
$scope.$on('Keepalive', function() {
addEvent({event: 'Keepalive', date: new Date()});
});
function addEvent(evt) {
$scope.$evalAsync(function() {
$scope.events.push(evt);
})
}
$scope.reset = function() {
Idle.watch();
}
$scope.$watch('idle', function(value) {
if (value !== null) Idle.setIdle(value);
});
$scope.$watch('timeout', function(value) {
if (value !== null) Idle.setTimeout(value);
});
})
.config(function(IdleProvider, KeepaliveProvider) {
KeepaliveProvider.interval(10);
IdleProvider.windowInterrupt('focus');
})
.run(function($rootScope, Idle, $log, Keepalive){
Idle.watch();
$log.debug('app started.');
});
</script>
</head>
<body ng-controller="EventsCtrl">
<div idle-countdown="countdown">
<h1>Idle and Keepalive events</h1>
<button type="button" ng-click="reset()">Reset manually</button>
<ul>
<li ng-repeat="event in events">{{event}}</li>
</ul>
<div idle-countdown="countdown">
Timeout in {{countdown}} seconds.
</div>
<div>
Change idle value <input type="number" ng-model="idle" />
</div>
<div>
Change timeout value <input type="number" ng-model="timeout" />
</div>
</div>
</body>
</html>