forked from siddii/angular-timer
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathangularjs-reset-timer
More file actions
92 lines (75 loc) · 2.52 KB
/
angularjs-reset-timer
File metadata and controls
92 lines (75 loc) · 2.52 KB
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
84
85
86
87
88
89
90
91
92
<!DOCTYPE html>
<html ng-app="doUI">
<head>
<title>AngularJS Example - Reset Countdown</title>
<script src="../bower_components/angular/angular.min.js"></script>
<script src="../bower_components/bootstrap/docs/assets/js/bootstrap.min.js"></script>
<script src="../bower_components/momentjs/min/moment.min.js"></script>
<script src="../bower_components/momentjs/min/locales.min.js"></script>
<script src="../bower_components/humanize-duration/humanize-duration.js"></script>
<script src="../dist/angular-timer.js"></script>
<style>
#ui ul {
margin: 0;
display: inline-block;
list-style-type: none;
width: 33%;
float: left;
font-family: myriad pro;
}
li {
margin: 10px 0;
padding: 5px;
color: #333;
}
li.control {
cursor: pointer;
background-color: aliceblue;
}
</style>
<script>
angular.module('doUI', ['timer']);
function doController($scope) {
$scope.timerRunning = true;
var timeStarted = false;
$scope.countdownVal = 900;
$scope.startClock = function() {
if (!timeStarted) {
$scope.$broadcast('timer-start');
$scope.timerRunning = true;
timeStarted = true
} else if ((timeStarted) && (!$scope.timerRunning)) {
$scope.$broadcast('timer-resume');
$scope.timerRunning = true;
}
};
$scope.stopClock = function() {
if ((timeStarted) && ($scope.timerRunning)) {
$scope.$broadcast('timer-stop');
$scope.timerRunning = false;
}
};
$scope.resetClock = function() {
if ((!$scope.timerRunning))
$scope.$broadcast('timer-reset');
}
$scope.$on('timer-stopped', function(event, data) {
timeStarted = true;
});
}
doController.$inject = ['$scope'];
</script>
</head>
<body ng-controller="doController">
<div id="ui">
<ul class="timerNew">
<li>
<timer interval="1000" countdown="countdownVal" autostart="false">{{millis | date:'mm:ss'}}</timer>
</li>
<li ng-click="startClock()" ng-disabled="timerRunning" class="control">Start/Resume</li>
<li ng-click="stopClock()" ng-disabled="!timerRunning" class="control">Stop</li>
<li ng-click="resetClock()" class="control">Reset</li>
</ul>
</div>
</body>
</html>