File tree Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Expand file tree Collapse file tree 2 files changed +35
-4
lines changed Original file line number Diff line number Diff line change @@ -3,14 +3,18 @@ angular.module('timer', [])
3
3
return {
4
4
restrict : 'E' ,
5
5
replace : false ,
6
- scope : { interval : '=interval' } ,
6
+ scope : {
7
+ interval : '=interval' ,
8
+ countdownattr : '=countdown'
9
+ } ,
7
10
controller : function ( $scope , $element ) {
8
11
if ( $element . html ( ) . trim ( ) . length === 0 ) {
9
12
$element . append ( $compile ( '<span>{{millis}}</span>' ) ( $scope ) ) ;
10
13
}
11
14
12
15
$scope . startTime = null ;
13
16
$scope . timeoutId = null ;
17
+ $scope . countdown = $scope . countdownattr && parseInt ( $scope . countdownattr , 10 ) > 0 ? parseInt ( $scope . countdownattr , 10 ) : undefined ;
14
18
15
19
$scope . $on ( 'timer-start' , function ( ) {
16
20
$scope . start ( ) ;
@@ -44,6 +48,12 @@ angular.module('timer', [])
44
48
} ) ;
45
49
46
50
var tick = function ( ) {
51
+ if ( $scope . countdown > 0 ) {
52
+ $scope . countdown -- ;
53
+ }
54
+ else if ( $scope . countdown <= 0 ) {
55
+ $scope . stop ( ) ;
56
+ }
47
57
$scope . millis = new Date ( ) - $scope . startTime ;
48
58
$scope . seconds = Math . floor ( ( $scope . millis / 1000 ) % 60 ) ;
49
59
$scope . minutes = Math . floor ( ( ( $scope . millis / ( 1000 * 60 ) ) % 60 ) ) ;
Original file line number Diff line number Diff line change 81
81
< li > < a href ="index.html#basic-timer "> Basic Example</ a > </ li >
82
82
< li > < a href ="index.html#clock-timer "> Clock Timer</ a > </ li >
83
83
< li > < a href ="index.html#progressbar-timer "> Progressbar Timer</ a > </ li >
84
+ < li > < a href ="index.html#countdown-timer "> Countdown Timer</ a > </ li >
84
85
</ ul >
85
86
</ li >
86
87
< li ng-non-bindable > < a href ="index.html#markup "> <timer/></ a > </ li >
@@ -150,6 +151,15 @@ <h3><timer><div class="progress progress-striped active">
150
151
</ div >
151
152
</ section >
152
153
154
+ < section id ="countdown-timer ">
155
+ < h3 > Countdown Timer</ h3 >
156
+ < div class ="bs-docs-example ">
157
+ < p > The countdown timer < code ng-non-bindable > <timer interval="1000" countdown="100"/></ code > will start its countdown from 100 until it reaches 0 by ticking every second</ p >
158
+ < h3 > < timer interval ="1000 " countdown ="100 "> {{countdown}}</ timer > </ h3 >
159
+ </ div >
160
+ </ section >
161
+
162
+
153
163
< section id ="markup ">
154
164
< h3 > Markup</ h3 >
155
165
< p > Timer directive can be declared using following options. By default, it will display milliseconds inside < code > span</ code > tag.
@@ -189,6 +199,17 @@ <h4>Attributes</h4>
189
199
1 millisecond
190
200
</ td >
191
201
</ tr >
202
+ < tr >
203
+ < td >
204
+ countdown
205
+ </ td >
206
+ < td >
207
+ false
208
+ </ td >
209
+ < td >
210
+
211
+ </ td >
212
+ </ tr >
192
213
</ table >
193
214
194
215
@@ -204,15 +225,15 @@ <h4>Methods</h4>
204
225
</ thead >
205
226
< tr >
206
227
< td > start</ td >
207
- < td > Triggered to start the timer. Will reset the start time </ td >
228
+ < td > Starts the timer</ td >
208
229
</ tr >
209
230
< tr >
210
231
< td > stop</ td >
211
- < td > Triggered to stop the timer. </ td >
232
+ < td > Stops the timer</ td >
212
233
</ tr >
213
234
< tr >
214
235
< td > resume</ td >
215
- < td > Triggered to resume the timer. Will NOT reset the start time</ td >
236
+ < td > Resumes the timer. Will NOT reset the start time</ td >
216
237
</ tr >
217
238
</ table >
218
239
</ section >
You can’t perform that action at this time.
0 commit comments