1
1
/**
2
- * angular-timer - v1.1.0 - 2014-04-23 5:44 AM
2
+ * angular-timer - v1.1.0 - 2014-05-17 1:35 AM
3
3
* https://github.com/siddii/angular-timer
4
4
*
5
5
* Copyright (c) 2014 Siddique Hameed
@@ -113,38 +113,64 @@ angular.module('timer', [])
113
113
function calculateTimeUnits ( ) {
114
114
115
115
// compute time values based on maxTimeUnit specification
116
- if ( ! $scope . maxTimeUnit ) {
116
+ if ( ! $scope . maxTimeUnit || $scope . maxTimeUnit === 'day' ) {
117
117
$scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
118
118
$scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
119
119
$scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
120
- $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) ) ;
120
+ $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) ) ;
121
+ $scope . months = 0 ;
122
+ $scope . years = 0 ;
121
123
} else if ( $scope . maxTimeUnit === 'second' ) {
122
124
$scope . seconds = Math . floor ( $scope . millis / 1000 ) ;
123
125
$scope . minutes = 0 ;
124
126
$scope . hours = 0 ;
125
127
$scope . days = 0 ;
128
+ $scope . months = 0 ;
129
+ $scope . years = 0 ;
126
130
} else if ( $scope . maxTimeUnit === 'minute' ) {
127
131
$scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
128
132
$scope . minutes = Math . floor ( $scope . millis / 60000 ) ;
129
133
$scope . hours = 0 ;
130
134
$scope . days = 0 ;
135
+ $scope . months = 0 ;
136
+ $scope . years = 0 ;
131
137
} else if ( $scope . maxTimeUnit === 'hour' ) {
132
138
$scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
133
139
$scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
134
140
$scope . hours = Math . floor ( $scope . millis / 3600000 ) ;
135
141
$scope . days = 0 ;
142
+ $scope . months = 0 ;
143
+ $scope . years = 0 ;
144
+ } else if ( $scope . maxTimeUnit === 'month' ) {
145
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
146
+ $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
147
+ $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
148
+ $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) % 30 ) ;
149
+ $scope . months = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) / 30 ) ;
150
+ $scope . years = 0 ;
151
+ } else if ( $scope . maxTimeUnit === 'year' ) {
152
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
153
+ $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
154
+ $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
155
+ $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) % 30 ) ;
156
+ $scope . months = Math . floor ( ( $scope . millis / ( 3600000 ) ) / 24 / 30 ) ;
157
+ $scope . years = Math . floor ( ( $scope . millis / ( 3600000 ) ) / 24 / 30 / 12 ) ;
136
158
}
137
159
138
160
// plural - singular unit decision
139
161
$scope . secondsS = $scope . seconds == 1 ? '' : 's' ;
140
162
$scope . minutesS = $scope . minutes == 1 ? '' : 's' ;
141
163
$scope . hoursS = $scope . hours == 1 ? '' : 's' ;
142
164
$scope . daysS = $scope . days == 1 ? '' : 's' ;
165
+ $scope . monthsS = $scope . months == 1 ? '' : 's' ;
166
+ $scope . yearsS = $scope . years == 1 ? '' : 's' ;
143
167
//add leading zero if number is smaller than 10
144
168
$scope . sseconds = $scope . seconds < 10 ? '0' + $scope . seconds : $scope . seconds ;
145
169
$scope . mminutes = $scope . minutes < 10 ? '0' + $scope . minutes : $scope . minutes ;
146
170
$scope . hhours = $scope . hours < 10 ? '0' + $scope . hours : $scope . hours ;
147
171
$scope . ddays = $scope . days < 10 ? '0' + $scope . days : $scope . days ;
172
+ $scope . mmonths = $scope . months < 10 ? '0' + $scope . months : $scope . months ;
173
+ $scope . yyears = $scope . years < 10 ? '0' + $scope . years : $scope . years ;
148
174
149
175
}
150
176
//determine initial values of time units and add AddSeconds functionality
@@ -164,6 +190,16 @@ angular.module('timer', [])
164
190
$scope . addCDSeconds ( extraSeconds ) ;
165
191
} ) ;
166
192
} ) ;
193
+
194
+ $scope . $on ( 'timer-set-countdown-seconds' , function ( e , countdownSeconds ) {
195
+ if ( ! $scope . isRunning ) {
196
+ $scope . clear ( ) ;
197
+ }
198
+
199
+ $scope . countdown = countdownSeconds ;
200
+ $scope . millis = countdownSeconds * 1000 ;
201
+ calculateTimeUnits ( ) ;
202
+ } ) ;
167
203
} else {
168
204
$scope . millis = 0 ;
169
205
}
0 commit comments