-
Notifications
You must be signed in to change notification settings - Fork 938
/
index.html
562 lines (519 loc) · 23.1 KB
/
index.html
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
<!-- From index.tpl.html - Grunt task index -->
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8"/>
<title>Angular Timer, a simple, inter-operable AngularJS directive</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<!-- compiled CSS -->
<link rel="stylesheet" type="text/css" href="bower_components/bootstrap/docs/assets/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css" />
<link rel="stylesheet" type="text/css" href="docs/css/docs.css" />
<link rel="stylesheet" type="text/css" href="docs/css/prettify.css" />
<!-- compiled JavaScript -->
<script type="text/javascript" src="dist/assets/js/angular-timer-bower.js"></script>
<script type="text/javascript" src="dist/assets/js/angular-timer-all.min.js"></script>
<script type="text/javascript" src="docs/docs.js"></script>
<script type="text/javascript" src="docs/prettify.js"></script>
<script type="text/javascript" src="docs/application.js"></script>
</head>
<body ng-app="timer-demo" ng-controller="TimerDemoController">
<ng-include src="'navbar.html'" onload='linkAnchors();'></ng-include>
<div class="container page-content">
<section id="introduction">
<h1>
Introduction</h1>
<p>
Directives in <a href="http://angularjs.org" target="_new">AngularJS</a> is a powerful way of building
reusable <em>UI components</em>. This simple project will serve as a sample/reference implementation
demonstrating its flexibilities by making it <em>inter-operable</em> across runtime (AngularJS, plain simple
JavaScript & jQuery)</p>
<p>
For basic understanding of how directives work in AngularJS, please head to this <a
href="http://docs.angularjs.org/guide/directive" target="_new">developer guide</a>.</p>
</section>
<section id="basic-timer">
<h3>
Basic Example</h3>
<div class="bs-docs-example" timer-controls>
<p>
This simple directive <code><timer /></code> will start the timer with the default option of
ticking every 1 millisecond</p>
<h3>
<timer></timer>
</h3>
<button class="btn" ng-click="timerStart()" type="button">Start</button>
<button class="btn" ng-click="timerStop()" type="button">Stop</button>
</div>
</section>
<section id="start-time-and-auto-start-set" >
<h3>Timer with start time and auto start set</h3>
<div class="bs-docs-example">
<p>This will start a timer with 1410914940000 milliseconds and stopped</p>
<h3>
<timer start-time="1410914940000" autostart="false"></timer>
</h3>
</div>
</section>
<section id="clock-timer">
<h3>
Timer with hours, minutes & seconds</h3>
<div class="bs-docs-example" timer-controls>
<p>
This markup <code ng-non-bindable=""><timer interval="1000">{{hours}} hour{{hoursS}}, {{minutes}}
minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer></code> will run the clock timer ticking every second</p>
<h3>
<timer interval="1000">{{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</h3>
<button class="btn" ng-click="timerToggle()" type="button">{{btnText[timerStatus]}}</button>
</div>
</section>
<section id="clock-timer-i18n">
<h3>
Timer i18n</h3>
<div class="bs-docs-example">
<p>
This markup <code ng-non-bindable=""><timer interval="1000" language="fr" >{{yearUnit}}</code> will run the clock timer ticking every second.
</p>
<p>
You can use a controller variable as the language attribut or a string. If a scope variable is used, the value will be watched, <strong>that is to say if your app language changes, the change will also affects the timer.</strong>
</p>
<p>
Based on <a href="https://github.com/EvanHahn/HumanizeDuration.js">HumanizeDuration</a> with more than 16 languages available.
</p>
<h3>Spanish</h3>
<div id="spanish">
<h4>Year max unit time : <timer interval="1000" language="es">{{yearUnit}}</timer></h4>
<h4>Hour max unit time: <timer interval="1000" language="es">{{hourUnit}}</timer></h4>
<h4>Second max unit time: <timer interval="1000" language="es">{{secondUnit}}</timer></h4>
</div>
<h3>French</h3>
<div id="french">
<h4>Year max unit time : <timer interval="1000" language="fr">{{yearUnit}}</timer></h4>
<h4>Hour max unit time: <timer interval="1000" language="fr">{{hourUnit}}</timer></h4>
<h4>Second max unit time: <timer interval="1000" language="fr">{{secondUnit}}</timer></h4>
</div>
<h3>Available units</h3>
<ul>
<li><strong>secondUnit</strong>: 8 164 816 seconds</li>
<li><strong>minuteUnit</strong>: 136 089 minutes, 16 seconds</li>
<li><strong>hourUnit</strong>: 18 126 hours,9 minutes, 16 seconds</li>
<li><strong>dayUnit</strong>: 755 days, 6 hours, 9 minutes, 16 seconds</li>
<li><strong>monthUnit</strong>: 25 month, 5 days, 6 hours, 9 minutes, 16 seconds</li>
<li><strong>yearUnit </strong>: 2 years, 1 month, 5 days, 6 hours, 9 minutes, 16 seconds</li>
</ul>
</div>
</section>
<section id="clock-timer-leading-zero">
<h3>
Timer with leading zero</h3>
<div class="bs-docs-example" timer-controls>
<p>
This markup <code ng-non-bindable=""><timer interval="1000">{{hhours}} hour{{hhoursS}}, {{mminutes}}
minute{{minutesS}}, {{sseconds}} second{{secondsS}}.</timer></code> will run the clock timer ticking every second with an additional zero at the beginning if unit is smaller than 10</p>
<h3>
<timer interval="1000">{{hhours}} hour{{hoursS}}, {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
</h3>
<button class="btn" ng-click="timerToggle()" type="button">{{btnText[timerStatus]}}</button>
</div>
</section>
<section id="timer-with-start-time">
<h3>
Timer initialised with some predefined start time.</h3>
<div class="bs-docs-example" timer-controls>
<p>
Following is the timer clock setting for the days, hours, minutes & seconds elapsed since <b>January 1, {{currentYear}} (GMT-6) </b>
<p class="muted">(01 Jan {{currentYear}} 06:00:00 GMT = {{startTime}} milliseconds)</p>
<code ng-non-bindable=""><timer start-time="{{startTime}}">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer></code>
<h3>
<timer start-time="startTime">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>
</h3>
<button class="btn" ng-click="timerToggle()" type="button">{{btnText[timerStatus]}}</button>
</div>
</section>
<section id="timer-with-end-time">
<h3>
Timer initialised with some predefined end time.</h3>
<div class="bs-docs-example">
<p>
Following is the countdown timer setting for the days, hours, minutes & seconds to <b>January 1, {{endYear}} (GMT) </b>
<p class="muted">(01 Jan {{endYear}} 00:00:00 GMT = {{endTime}} milliseconds)</p>
<code ng-non-bindable=""><timer end-time="{{endTime}}">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer></code>
<h3>
<timer end-time="endTime">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>
</h3>
</div>
</section>
<section id="progressbar-timer">
<h3>
Progressbar Timer</h3>
<div class="bs-docs-example">
<p>
Timer directive along with <a href="http://twitter.github.io/bootstrap/components.html#progress"
target="_new">Twitter Bootstrap's Progressbar</a> will set the timer
on Progressbar control.</p>
<code ng-non-bindable="">
<timer countdown="30" interval="1000"><div class="progress
progress-striped active {{displayProgressActive}}"style="height: 30px;">
</code>
<code ng-non-bindable="">
Remaining time : {{countdown}} second{{secondsS}} ({{progressBar}}%). Activity? {{displayProgressActive}}
</code>
<code ng-non-bindable="">
<div class="bar" style="min-width: 2em;width: {{progressBar}}%;"></div>
</code>
<code ng-non-bindable="">
</div></timer>
</code>
<h3>
<timer id="countdown" interval="1000" countdown="30">
Remaining time : {{countdown}} second{{secondsS}} ({{progressBar}}%). Activity? {{displayProgressActive}}
<div class="progress progress-striped {{displayProgressActive}}" style="height: 30px;">
<div class="bar" style="min-width: 2em; height: 30px; width: {{progressBar}}%;">
{{ progressBar }}%
</div>
</div>
</timer>
</h3>
<code ng-non-bindable="">
<timer end-time="1451628000000" interval="1000"><div class="progress
progress-striped active {{displayProgressActive}}"style="height: 30px;">
</code>
<code ng-non-bindable="">
<div class="bar" style="min-width: 2em;width: {{progressBar}}%;"></div>
</code>
<code ng-non-bindable="">
</div></timer>
</code>
<h3>
<timer interval="1000" end-time="1451628000000">
({{progressBar}}%). Progress bar activity : {{displayProgressActive}}
<div class="progress progress-striped {{displayProgressActive}}" style="height: 30px;">
<div class="bar" style="min-width: 2em; width: {{progressBar}}%;">
{{ progressBar }}%</div>
</div>
</timer>
</h3>
<button class="btn" ng-click="timerStart()" type="button">Start</button>
<button class="btn" ng-click="timerStop()" type="button">Stop</button>
</div>
</section>
<section id="countdown-timer">
<h3>
Countdown Timer</h3>
<div class="bs-docs-example" timer-controls>
<p>
The countdown timer <code ng-non-bindable=""><timer interval="1000" countdown="100">{{countdown}}</timer></code>
will start its countdown from 100 until it reaches 0 by ticking every second</p>
<h3>
<timer countdown="100" interval="1000">{{countdown}}</timer>
</h3>
<button class="btn" ng-click="timerAddCDSeconds(10)" type="button">Add 10 Seconds</button>
</div>
</section>
<section id="auto-start-false-timer" >
<h3>
Timer with <em>autostart = false</em></h3>
<div class="bs-docs-example" timer-controls>
<p>
Click on the start button to start the timer. <code ng-non-bindable=""><timer autostart="false" interval="1000">{{seconds}}</timer></code></p>
<h3>
<timer autostart="false" interval="1000">{{seconds}}</timer>
</h3>
<button class="btn" ng-click="timerToggle()" type="button">{{btnText[timerStatus]}}</button>
</div>
</section>
<section id="plural-unit-timer">
<h3>Plural / Singular units</h3>
<div class="bs-docs-example">
<p>
Two stopped countdown timers to illustrate how to handle pluralization of time units.
<code ng-non-bindable="">
<timer autostart="false" countdown="90061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</code>
<h3 class="singular-counter">
<timer autostart="false" countdown="90061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</h3>
<code ng-non-bindable="">
<timer autostart="false" countdown="190061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</code>
<h3 class="plural-counter">
<timer autostart="false" countdown="190061">{{days}} day{{daysS}}, {{hours}} hour{{hoursS}}, {{minutes}} minute{{minutesS}}, {{seconds}} second{{secondsS}}.</timer>
</h3>
</div>
</section>
<section id="max-time-unit-countdown-timer">
<h3>Countdown time display according to specified <em>max-time-unit</em></h3>
<div class="bs-docs-example">
<p>
This markup will display countdown time in minute and seconds only. This attribute can be applied to regular clock timer as well.
<code ng-non-bindable="">
<timer countdown="10041" max-time-unit="'minute'" interval="1000">{{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
</code>
</p>
<p class="muted">countdown Time with max time unit option - year</p>
<h3 class="WithMaxTimeUnitAsYear">
<timer countdown="100410000" max-time-unit="'year'" interval="1000">{{yyears}} year{{yearsS}}, {{mmonths}} month{{monthsS}}, {{ddays}} day{{daysS}}, {{hhours}} hour{{hoursS}}, {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
</h3>
<p class="muted">countdown Time with max time unit option - minute</p>
<h3 class="WithMaxTimeUnitAsMinute">
<timer countdown="10041" max-time-unit="'minute'" interval="1000"> {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
</h3>
<p class="muted">countdown Time with max time unit option - second</p>
<h3 class="WithMaxTimeUnitAsSecond">
<timer countdown="10041" max-time-unit="'second'" interval="1000"> {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
</h3>
<p class="muted">countdown Time without max time unit option - minute</p>
<h3 class="WithoutMaxTimeUnit">
<timer countdown="10041" interval="1000"> {{ddays}} day{{daysS}}, {{hhours}} hour{{hoursS}}, {{mminutes}} minute{{minutesS}}, {{sseconds}} second{{secondsS}}</timer>
</h3>
</div>
</section>
<section id="finish-callback-timer">
<h3>Countdown Finished Callback</h3>
<div class="bs-docs-example">
<p>
A countdown timer that updates a value once the callback is reached
<code ng-non-bindable="">
<timer countdown="3" interval="1000" finish-callback="callbackTimer.finished()">{{seconds}} second{{secondsS}}</timer>
</code>
<h3 class="counter">
<timer countdown="3" interval="1000" finish-callback="callbackTimer.finished()">{{seconds}} second{{secondsS}} </timer>
</h3>
Timer: <span class="timer-status">{{callbackTimer.status}}</span>
Callbacks: <span class="timer-callbacks">{{callbackTimer.callbackCount}}</span>
</div>
</section>
<section id="markup">
<h3>
Markup</h3>
<p>
Timer directive can be declared using following options. By default, it will display milliseconds inside
<code>span</code> tag. It can also take <em>template</em> string to display user-defined formats.</p>
<div class="bs-docs-example">
<p>
<code ng-nonbindable=""><timer interval="1000" /> </code></p>
</div>
<div class="bs-docs-example">
<p>
<code ng-non-bindable=""><timer interval="1000">{{hours}} hours, {{minutes}} minutes,
{{seconds}} seconds, {{millis}} milliseconds.</timer></code></p>
</div>
<h4>
Attributes</h4>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
Name
</th>
<th>
Required
</th>
<th>
Default value
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
interval
</td>
<td>
false
</td>
<td>
1 millisecond
</td>
</tr>
<tr>
<td>
autostart<br/>
<em>Formerly called 'auto-start'. Please see this <a target="_new" href="https://github.com/siddii/angular-timer/issues/14">issue</a></em>
</td>
<td>
false
</td>
<td>
true
</td>
</tr>
<tr>
<td>
countdown
</td>
<td>
false
</td>
<td>
</td>
</tr>
<tr>
<td>
start-time
</td>
<td>
false
</td>
<td>starts the timer with predefined time (in milliseconds).
</td>
</tr>
<tr>
<td>
end-time
</td>
<td>
false
</td>
<td>Sets the countdown based on predefined end time (in milliseconds).
</td>
</tr>
<tr>
<td>
max-time-unit
</td>
<td>
false
</td>
<td> no default value. But you can give value, 'minute', 'second', or 'hour'.
</td>
</tr>
<tr>
<td>
language
</td>
<td>
false
</td>
<td> 'en' for English. Please see <a target='_blank' href="https://github.com/EvanHahn/HumanizeDuration.js#supported-languages">supported languages</a>.
</td>
</tr>
</tbody>
</table>
<h4>
Methods</h4>
<p>
Following DOM methods can be invoked to <em>timer</em>. Append to <code>timer-</code> for scope based
events when calling from AngularJS controllers.</p>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
Method name
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
start
</td>
<td>
Starts the timer
</td>
</tr>
<tr>
<td>
stop
</td>
<td>
Stops the timer
</td>
</tr>
<tr>
<td>
clear
</td>
<td>
Same as <i>stop</i>. But, without the event being triggered
</td>
</tr>
<tr>
<td>
reset
</td>
<td>
Resets a timer to its initial value, then <i>clear</i>s
the timer.
</td>
</tr>
<tr>
<td>
resume
</td>
<td>
Resumes the timer. Will NOT reset the start time
</td>
</tr>
<tr>
<td>
addCDSeconds
</td>
<td>
Add <i>seconds</i> to running countdown
</td>
</tr>
</tbody>
</table>
<h4>
Events</h4>
<table class="table table-bordered table-striped">
<thead>
<tr>
<th>
Event name
</th>
<th>
Description
</th>
</tr>
</thead>
<tbody>
<tr>
<td>
timer-tick
</td>
<td>
Tick event that gets emitted for every timer tick for specified interval. Please refer to <a href="examples.html#angularjs-polling-timer">Polling Timer</a>
example for its usage.
</td>
</tr>
<tr>
<td>
timer-stopped
</td>
<td>
Tick event that gets emitted when the timer stops. Please refer to <a href="examples.html#angularjs-single-timer">Single Timer</a>
example for its usage.
</td>
</tr>
</tbody>
</table>
</section>
<section id="bower">
<h3>
Install using Bower</h3>
<p>
<code>bower install angular-timer</code>
</p>
</section>
<section id="contribute">
<h3>
Contributions welcome!</h3>
<p>
We welcome any or all kinds of contributions! Please submit <a
href="https://github.com/siddii/angular-timer/pulls" target="_new">pull requests</a> or create <a
href="https://github.com/siddii/angular-timer/issues" target="_new">issues</a> to contribute to this
project :)</p>
</section>
<footer>
<p>
© Siddique Hameed 2013</p>
</footer>
</div>
</body>
</html>