forked from siddii/angular-timer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
468 lines (432 loc) · 16.9 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
<!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"/>
<link href="bower_components/bootstrap/docs/assets/css/bootstrap.css" rel="stylesheet"/>
<link href="bower_components/bootstrap/docs/assets/css/bootstrap-responsive.css" rel="stylesheet"/>
<link href="docs/css/docs.css" rel="stylesheet"/>
<link href="docs/css/prettify.css" rel="stylesheet"/>
<script src="bower_components/jquery/jquery.min.js"></script>
<script src="bower_components/angular/angular.min.js"></script>
<script src="bower_components/bootstrap/docs/assets/js/bootstrap.min.js"></script>
<script src="app/js/timer.js"></script>
<script src="docs/docs.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">
<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" onclick="startTimer('basic-timer')" type="button">Start</button>
<button class="btn" onclick="stopTimer('basic-timer')" 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">
<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" onclick="stopResumeTimer('clock-timer', this)" type="button">Stop</button>
</div>
</section>
<section id="clock-timer-leading-zero">
<h3>
Timer with leading zero</h3>
<div class="bs-docs-example">
<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" onclick="stopResumeTimer('clock-timer-leading-zero', this)" type="button">Stop</button>
</div>
</section>
<section id="timer-with-start-time">
<h3>
Timer initialised with some predefined start time.</h3>
<div class="bs-docs-example">
<p>
Following is the timer clock setting for the days, hours, minutes & seconds elapsed since <b>January 1, 2013 (GMT-6) </b>
<p class="muted">(01 Jan 2013 06:00:00 GMT = 1357020000000 milliseconds)</p>
<code ng-non-bindable=""><timer start-time="1357020000000">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer></code>
<h3>
<timer start-time="1357020000000">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer>
</h3>
<button class="btn" onclick="stopResumeTimer('timer-with-start-time', this)" type="button">Stop</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, 2015 (GMT-6) </b>
<p class="muted">(01 Jan 2015 06:00:00 GMT = 1420070400000 milliseconds)</p>
<code ng-non-bindable=""><timer end-time="1420070400000">{{days}} days, {{hours}} hours, {{minutes}} minutes, {{seconds}} seconds.</timer></code>
<h3>
<timer end-time="1420070400000">{{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 interval="1000"><div class="progress
progress-striped active"> <div class="bar" style="width: {{seconds}}%;"></div>
</div></timer> </code>
<h3>
<timer>
<div class="progress progress-striped active">
<div class="bar" style="width: {{seconds}}%;">
</div>
</div>
</timer>
</h3>
<button class="btn" onclick="startTimer('progressbar-timer')" type="button">Start</button>
<button class="btn" onclick="stopTimer('progressbar-timer')" type="button">Stop</button>
</div>
</section>
<section id="countdown-timer">
<h3>
Countdown Timer</h3>
<div class="bs-docs-example">
<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" onclick="addCDSeconds('countdown-timer', 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">
<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" onclick="stopResumeTimer('auto-start-false-timer', this)" type="button">Start</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>
</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>
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>
<script src="docs/prettify.js"></script>
<script src="docs/application.js"></script>
</body>
</html>