-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscriptz.js
93 lines (76 loc) · 2.3 KB
/
scriptz.js
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
// Generated by IcedCoffeeScript 1.4.0a
(function() {
var stopwatch,
__bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
stopwatch = (function() {
stopwatch.prototype.duration = null;
stopwatch.prototype.direction = 'down';
stopwatch.prototype.timer = null;
stopwatch.prototype.current = null;
stopwatch.prototype.interval = 1000;
stopwatch.prototype.el = $('.timer');
function stopwatch(seconds, direction) {
this.countUp = __bind(this.countUp, this);
this.countDown = __bind(this.countDown, this); this.duration = seconds;
this.direction = direction;
console.log(this.direction);
if (this.direction === 'up') {
this.current = 0;
} else {
this.current = this.duration;
}
this.el.html(this.counterDisplay(this.current));
}
stopwatch.prototype.counterDisplay = function(seconds) {
var h, m, padZero, s;
h = Math.floor(seconds / 60 / 60);
m = Math.floor((seconds / 60) % 60);
s = seconds % 60;
padZero = function(num) {
if (num < 10) {
return "0" + num;
} else {
return num;
}
};
return "" + h + ":" + (padZero(m)) + ":" + (padZero(s));
};
stopwatch.prototype.countDown = function() {
if (this.current === 0) {
this.stop();
return;
}
this.current--;
return this.el.html(this.counterDisplay(this.current));
};
stopwatch.prototype.countUp = function() {
if (this.current === this.duration) {
this.stop();
return;
}
this.current++;
return this.el.html(this.counterDisplay(this.current));
};
stopwatch.prototype.start = function(direction) {
var func;
func = this.direction === 'up' ? this.countUp : this.countDown;
clearInterval(this.timer);
return this.timer = setInterval(func, this.interval);
};
stopwatch.prototype.stop = function() {
console.log('stop');
return clearInterval(this.timer);
};
return stopwatch;
})();
$(function() {
var testing;
testing = new stopwatch(5);
$('.start').click(function() {
return testing.start();
});
return $('.stop').click(function() {
return testing.stop();
});
});
}).call(this);