1
1
/**
2
- * angular-timer - v1.1.2 - 2014-05-16 9:27 PM
2
+ * angular-timer - v1.1.2 - 2014-05-19 11:03 PM
3
3
* https://github.com/siddii/angular-timer
4
4
*
5
5
* Copyright (c) 2014 Siddique Hameed
@@ -22,8 +22,8 @@ angular.module('timer', [])
22
22
23
23
// Checking for trim function since IE8 doesn't have it
24
24
// If not a function, create tirm with RegEx to mimic native trim
25
- if ( typeof String . prototype . trim !== 'function' ) {
26
- String . prototype . trim = function ( ) {
25
+ if ( typeof String . prototype . trim !== 'function' ) {
26
+ String . prototype . trim = function ( ) {
27
27
return this . replace ( / ^ \s + | \s + $ / g, '' ) ;
28
28
} ;
29
29
}
@@ -113,72 +113,73 @@ angular.module('timer', [])
113
113
114
114
function calculateTimeUnits ( ) {
115
115
116
- // compute time values based on maxTimeUnit specification
117
- if ( ! $scope . maxTimeUnit || $scope . maxTimeUnit === 'day' ) {
118
- $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
119
- $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
120
- $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
121
- $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) ) ;
122
- $scope . months = 0 ;
123
- $scope . years = 0 ;
124
- } else if ( $scope . maxTimeUnit === 'second' ) {
125
- $scope . seconds = Math . floor ( $scope . millis / 1000 ) ;
126
- $scope . minutes = 0 ;
127
- $scope . hours = 0 ;
128
- $scope . days = 0 ;
129
- $scope . months = 0 ;
130
- $scope . years = 0 ;
131
- } else if ( $scope . maxTimeUnit === 'minute' ) {
132
- $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
133
- $scope . minutes = Math . floor ( $scope . millis / 60000 ) ;
134
- $scope . hours = 0 ;
135
- $scope . days = 0 ;
136
- $scope . months = 0 ;
137
- $scope . years = 0 ;
138
- } else if ( $scope . maxTimeUnit === 'hour' ) {
139
- $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
140
- $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
141
- $scope . hours = Math . floor ( $scope . millis / 3600000 ) ;
142
- $scope . days = 0 ;
143
- $scope . months = 0 ;
144
- $scope . years = 0 ;
145
- } else if ( $scope . maxTimeUnit === 'month' ) {
146
- $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
147
- $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
148
- $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
149
- $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) % 30 ) ;
150
- $scope . months = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) / 30 ) ;
151
- $scope . years = 0 ;
152
- } else if ( $scope . maxTimeUnit === 'year' ) {
153
- $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
154
- $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
155
- $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
156
- $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) % 30 ) ;
157
- $scope . months = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 / 30 ) % 12 ) ;
158
- $scope . years = Math . floor ( ( $scope . millis / ( 3600000 ) ) / 24 / 365 ) ;
159
- }
160
-
161
- // plural - singular unit decision
162
- $scope . secondsS = $scope . seconds == 1 ? '' : 's' ;
163
- $scope . minutesS = $scope . minutes == 1 ? '' : 's' ;
164
- $scope . hoursS = $scope . hours == 1 ? '' : 's' ;
165
- $scope . daysS = $scope . days == 1 ? '' : 's' ;
166
- $scope . monthsS = $scope . months == 1 ? '' : 's' ;
167
- $scope . yearsS = $scope . years == 1 ? '' : 's' ;
168
- //add leading zero if number is smaller than 10
169
- $scope . sseconds = $scope . seconds < 10 ? '0' + $scope . seconds : $scope . seconds ;
170
- $scope . mminutes = $scope . minutes < 10 ? '0' + $scope . minutes : $scope . minutes ;
171
- $scope . hhours = $scope . hours < 10 ? '0' + $scope . hours : $scope . hours ;
172
- $scope . ddays = $scope . days < 10 ? '0' + $scope . days : $scope . days ;
173
- $scope . mmonths = $scope . months < 10 ? '0' + $scope . months : $scope . months ;
174
- $scope . yyears = $scope . years < 10 ? '0' + $scope . years : $scope . years ;
116
+ // compute time values based on maxTimeUnit specification
117
+ if ( ! $scope . maxTimeUnit || $scope . maxTimeUnit === 'day' ) {
118
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
119
+ $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
120
+ $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
121
+ $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) ) ;
122
+ $scope . months = 0 ;
123
+ $scope . years = 0 ;
124
+ } else if ( $scope . maxTimeUnit === 'second' ) {
125
+ $scope . seconds = Math . floor ( $scope . millis / 1000 ) ;
126
+ $scope . minutes = 0 ;
127
+ $scope . hours = 0 ;
128
+ $scope . days = 0 ;
129
+ $scope . months = 0 ;
130
+ $scope . years = 0 ;
131
+ } else if ( $scope . maxTimeUnit === 'minute' ) {
132
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
133
+ $scope . minutes = Math . floor ( $scope . millis / 60000 ) ;
134
+ $scope . hours = 0 ;
135
+ $scope . days = 0 ;
136
+ $scope . months = 0 ;
137
+ $scope . years = 0 ;
138
+ } else if ( $scope . maxTimeUnit === 'hour' ) {
139
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
140
+ $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
141
+ $scope . hours = Math . floor ( $scope . millis / 3600000 ) ;
142
+ $scope . days = 0 ;
143
+ $scope . months = 0 ;
144
+ $scope . years = 0 ;
145
+ } else if ( $scope . maxTimeUnit === 'month' ) {
146
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
147
+ $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
148
+ $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
149
+ $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) % 30 ) ;
150
+ $scope . months = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) / 30 ) ;
151
+ $scope . years = 0 ;
152
+ } else if ( $scope . maxTimeUnit === 'year' ) {
153
+ $scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
154
+ $scope . minutes = Math . floor ( ( ( $scope . millis / ( 60000 ) ) % 60 ) ) ;
155
+ $scope . hours = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) % 24 ) ) ;
156
+ $scope . days = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 ) % 30 ) ;
157
+ $scope . months = Math . floor ( ( ( $scope . millis / ( 3600000 ) ) / 24 / 30 ) % 12 ) ;
158
+ $scope . years = Math . floor ( ( $scope . millis / ( 3600000 ) ) / 24 / 365 ) ;
159
+ }
160
+
161
+ // plural - singular unit decision
162
+ $scope . secondsS = $scope . seconds == 1 ? '' : 's' ;
163
+ $scope . minutesS = $scope . minutes == 1 ? '' : 's' ;
164
+ $scope . hoursS = $scope . hours == 1 ? '' : 's' ;
165
+ $scope . daysS = $scope . days == 1 ? '' : 's' ;
166
+ $scope . monthsS = $scope . months == 1 ? '' : 's' ;
167
+ $scope . yearsS = $scope . years == 1 ? '' : 's' ;
168
+ //add leading zero if number is smaller than 10
169
+ $scope . sseconds = $scope . seconds < 10 ? '0' + $scope . seconds : $scope . seconds ;
170
+ $scope . mminutes = $scope . minutes < 10 ? '0' + $scope . minutes : $scope . minutes ;
171
+ $scope . hhours = $scope . hours < 10 ? '0' + $scope . hours : $scope . hours ;
172
+ $scope . ddays = $scope . days < 10 ? '0' + $scope . days : $scope . days ;
173
+ $scope . mmonths = $scope . months < 10 ? '0' + $scope . months : $scope . months ;
174
+ $scope . yyears = $scope . years < 10 ? '0' + $scope . years : $scope . years ;
175
175
176
176
}
177
+
177
178
//determine initial values of time units and add AddSeconds functionality
178
179
if ( $scope . countdownattr ) {
179
180
$scope . millis = $scope . countdownattr * 1000 ;
180
181
181
- $scope . addCDSeconds = $element [ 0 ] . addCDSeconds = function ( extraSeconds ) {
182
+ $scope . addCDSeconds = $element [ 0 ] . addCDSeconds = function ( extraSeconds ) {
182
183
$scope . countdown += extraSeconds ;
183
184
$scope . $digest ( ) ;
184
185
if ( ! $scope . isRunning ) {
@@ -187,12 +188,12 @@ angular.module('timer', [])
187
188
} ;
188
189
189
190
$scope . $on ( 'timer-add-cd-seconds' , function ( e , extraSeconds ) {
190
- $timeout ( function ( ) {
191
+ $timeout ( function ( ) {
191
192
$scope . addCDSeconds ( extraSeconds ) ;
192
193
} ) ;
193
194
} ) ;
194
195
195
- $scope . $on ( 'timer-set-countdown-seconds' , function ( e , countdownSeconds ) {
196
+ $scope . $on ( 'timer-set-countdown-seconds' , function ( e , countdownSeconds ) {
196
197
if ( ! $scope . isRunning ) {
197
198
$scope . clear ( ) ;
198
199
}
@@ -239,7 +240,7 @@ angular.module('timer', [])
239
240
240
241
if ( $scope . countdown > 0 ) {
241
242
$scope . countdown -- ;
242
- $scope . countdownattr = String ( $scope . countdown ) ;
243
+ $scope . countdownattr = $scope . countdown . toString ( ) ;
243
244
}
244
245
else if ( $scope . countdown <= 0 ) {
245
246
$scope . stop ( ) ;
0 commit comments