1
- $ ( document ) . on ( 'click' , '#button' , function ( ) {
2
- start ( ) ;
3
- } ) ;
4
-
5
1
var clsStopwatch = function ( ) {
6
2
// Private vars
7
- var startAt = 0 ; // Time of last start / resume. (0 if not running)
8
- var lapTime = 0 ; // Time on the clock when last stopped in milliseconds
3
+ var startAt = 0 ; // Time of last start / resume. (0 if not running)
4
+ var lapTime = 0 ; // Time on the clock when last stopped in milliseconds
5
+
6
+ var now = function ( ) {
7
+ return ( new Date ( ) ) . getTime ( ) ;
8
+ } ;
9
9
10
- var now = function ( ) {
11
- return ( new Date ( ) ) . getTime ( ) ;
12
- } ;
13
-
14
- // Public methods
15
- // Start or resume
16
- this . start = function ( ) {
17
- startAt = startAt ? startAt : now ( ) ;
18
- } ;
10
+ // Public methods
11
+ // Start or resume
12
+ this . startClock = function ( ) {
13
+ startAt = startAt ? startAt : now ( ) ;
14
+ } ;
19
15
20
- // Stop or pause
21
- this . stop = function ( ) {
22
- // If running, update elapsed time otherwise keep it
23
- lapTime = startAt ? lapTime + now ( ) - startAt : lapTime ;
24
- startAt = 0 ; // Paused
25
- } ;
16
+ // Stop or pause
17
+ this . stopClock = function ( ) {
18
+ // If running, update elapsed time otherwise keep it
19
+ lapTime = startAt ? lapTime + now ( ) - startAt : lapTime ;
20
+ startAt = 0 ; // Paused
21
+ } ;
26
22
27
- // Reset
28
- this . reset = function ( ) {
29
- lapTime = startAt = 0 ;
30
- } ;
23
+ // Reset
24
+ this . resetClock = function ( ) {
25
+ lapTime = startAt = 0 ;
26
+ } ;
31
27
32
- // Duration
33
- this . time = function ( ) {
34
- return lapTime + ( startAt ? now ( ) - startAt : 0 ) ;
35
- } ;
36
- } ;
28
+ // Duration
29
+ this . time = function ( ) {
30
+ return lapTime + ( startAt ? now ( ) - startAt : 0 ) ;
31
+ } ;
32
+ } ;
37
33
38
34
var x = new clsStopwatch ( ) ;
39
35
var $time ;
@@ -59,27 +55,27 @@ function formatTime(time) {
59
55
return newTime ;
60
56
}
61
57
62
- function show ( ) {
58
+ function showClock ( ) {
63
59
$time = document . getElementById ( 'time' ) ;
64
- update ( ) ;
60
+ updateClock ( ) ;
65
61
}
66
62
67
- function update ( ) {
63
+ function updateClock ( ) {
68
64
$time . innerHTML = formatTime ( x . time ( ) ) ;
69
65
}
70
66
71
- function start ( ) {
72
- clocktimer = setInterval ( "update ()" , 1 ) ;
73
- x . start ( ) ;
67
+ function startClock ( ) {
68
+ clocktimer = setInterval ( "updateClock ()" , 1 ) ;
69
+ x . startClock ( ) ;
74
70
}
75
71
76
- function stop ( ) {
77
- x . stop ( ) ;
72
+ function stopClock ( ) {
73
+ x . stopClock ( ) ;
78
74
clearInterval ( clocktimer ) ;
79
75
}
80
76
81
- function reset ( ) {
82
- stop ( ) ;
83
- x . reset ( ) ;
84
- update ( ) ;
77
+ function resetClock ( ) {
78
+ stopClock ( ) ;
79
+ x . resetClock ( ) ;
80
+ updateClock ( ) ;
85
81
}
0 commit comments