@@ -16,32 +16,27 @@ angular.module('timer', [])
16
16
$scope . start ( ) ;
17
17
} ) ;
18
18
19
+ $scope . $on ( 'timer-resume' , function ( ) {
20
+ $scope . resume ( ) ;
21
+ } ) ;
22
+
19
23
$scope . $on ( 'timer-stop' , function ( ) {
20
24
$scope . stop ( ) ;
21
25
} ) ;
22
26
23
27
$scope . start = $element [ 0 ] . start = function ( ) {
24
28
$scope . startTime = new Date ( ) ;
25
- updateTime ( ) ;
26
- updateLater ( ) ;
29
+ tick ( ) ;
30
+ } ;
31
+
32
+ $scope . resume = $element [ 0 ] . resume = function ( ) {
33
+ tick ( ) ;
27
34
} ;
28
35
29
36
$scope . stop = $element [ 0 ] . stop = function ( ) {
30
37
$timeout . cancel ( $scope . timeoutId ) ;
31
38
} ;
32
39
33
- function updateTime ( ) {
34
- $scope . timeTaken = new Date ( ) - $scope . startTime ;
35
- $scope . minutes = Math . floor ( $scope . timeTaken / ( 1000 * 60 ) ) ;
36
- $scope . seconds = Math . floor ( ( $scope . timeTaken - ( $scope . minutes * 60 ) ) / 1000 ) % 60 ;
37
- }
38
-
39
- function updateLater ( ) {
40
- $scope . timeoutId = $timeout ( function ( ) {
41
- updateTime ( ) ;
42
- updateLater ( ) ;
43
- } , $scope . interval ) ;
44
- }
45
40
46
41
$element [ 0 ] . stop = function ( ) {
47
42
$timeout . cancel ( $scope . timeoutId ) ;
@@ -51,6 +46,16 @@ angular.module('timer', [])
51
46
$timeout . cancel ( $scope . timeoutId ) ;
52
47
} ) ;
53
48
49
+ var tick = function ( ) {
50
+ $scope . timeTaken = new Date ( ) - $scope . startTime ;
51
+ $scope . minutes = Math . floor ( $scope . timeTaken / ( 1000 * 60 ) ) ;
52
+ $scope . seconds = Math . floor ( ( $scope . timeTaken - ( $scope . minutes * 60 ) ) / 1000 ) % 60 ;
53
+
54
+ $scope . timeoutId = $timeout ( function ( ) {
55
+ tick ( ) ;
56
+ } , $scope . interval ) ;
57
+ } ;
58
+
54
59
$scope . start ( ) ;
55
60
}
56
61
} ;
0 commit comments