-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathindex.html
215 lines (200 loc) · 6.31 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
<!doctype html>
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html" charset="utf-8" />
<meta name="description" content>
<meta name="keywords" content>
<meta name="author" content>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
<title>Stopwatch</title>
<link href="css/bootstrap.min.css" rel="stylesheet"/>
<link href="css/bootstrap-responsive.min.css" rel="stylesheet"/>
<link href="css/font-awesome.css" rel="stylesheet">
<link href="css/custom.css" rel="stylesheet"/>
</head>
<body>
<header>
<div class="container">
<div class="center">
<div id="stopWatch">
<h1 id="title">Stopwatch</h1>
<div class="row">
<div class="span12">
<div id="time" class="pointable" style="font-weight:bold; width:100%; display:block;">00:00:00</div>
</div>
</div>
<div class="row">
<div id="divStart" class="span4 center">
<button id="btnStart" class="btn btn-large btn-block btn-primary" style="font-weight:bold;" data-do="start" type="button">Start</button>
</div>
</div>
<div class="row hidden" id="divControls">
<div class="span4 center">
<div class="row">
<span class="span2 pull-left">
<button id="btnPause" class="btn btn-large btn-block" type="button">
<i class="icon-pause"></i>
Pause
</button>
</span>
<span class="span2 pull-right">
<button id="btnStop" class="btn btn-large btn-block" type="button">
<i class="icon-repeat"></i>
Reset
</button>
</span>
</div>
</div>
</div>
</div>
<div class="clear"></div>
<div id="lapTimes" class="hidden row center">
<div class="heightlap" style="margin-top:10px;">
<button class="btn hidden" id="btnClear" type="button">Clear</button>
<p id="lapInst">Tap the time to record a lap.</p>
</div>
<div class="span12 center scrollable" id="lapListCont" style="height:0px;">
<div class="row">
<div class="span4 center" style="margin-top:5px;">
<table id="timeTable" class="table table-striped" style="width:70%; margin:auto;">
<thead class="hidden">
<tr>
<th>#</th>
<th>Time</th>
</tr>
</thead>
<tbody id="lapList"></tbody>
</table>
</div>
</div>
</div>
</div>
</div>
</div>
</header>
<!-- scripts -->
<!--
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
-->
<script type="text/javascript" src="js/jquery.1.9.1.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/custom.js"></script>
<script src="js/jquery.fittext.js"></script>
<script type="text/javascript">
$(document).ready(function(){
function adjustHeight(){
$('#lapListCont').height( ($(window).height() - $('#stopWatch').height() - $('#heightlap').height() - 110) + "px") ;
}
adjustHeight();
$(window).on('resize', function(){
adjustHeight();
});
var startTime;
var timeout;
var pauseTime = 0;
var mils;
var paused = false;
var count = 0;
$('#time').on('click', function(){
if(mils != undefined){
if(mils > 0){
$('#lapInst').hide();
var time = milToTime(mils);
//alert(mils);
time = formatTime(time);
count += 1;
$('#timeTable thead').show();
$('#lapList').prepend('<tr class="timeRow"><td class="lapCount muted">' + count + ".</td><td>" +time.h +':'+time.m +':'+time.s + '.' + time.mils+ '</td></tr>');
$('#lapListCont').animate({ scrollTop: 0 }, "fast");
}
}
});
$('#btnPause').on('click', function(){
if(paused == false){
paused = true;
clearTimeout(timeout);
pauseTime = mils;
$(this).html('<i class="icon-play-circle"></i> Resume');
$('#time').addClass('paused');
}else{
paused = false;
$(this).html('<i class="icon-pause"></i> Pause');
startTime = new Date();
clock();
}
});
$('#btnStop').on('click', function(){
$('#title').slideDown();
$('#lapInst').hide();
$('#time').removeClass('paused');
paused = false;
clearTimeout(timeout);
pauseTime = 0;
mils = 0;
$('#time').html('00:00:00');
$('#btnClear').click();
$('#divControls').fadeOut(function(){
$('#divStart').fadeIn()
$('#btnPause').html('<i class="icon-pause"></i> Pause');
});
});
$('#btnStart').on('click', function(){
$('#title').slideUp(function(){
adjustHeight();
});
var btn = $(this);
startTime = new Date();
clock();
$('#divStart').fadeOut(function(){
$('#divControls').fadeIn();
$('#lapInst').fadeIn();
$('#lapTimes').fadeIn();
});
});
function clock() {
$('#time').removeClass('paused');
var curTime = new Date();
mils = (curTime - startTime) + pauseTime;
var time = milToTime(mils);
formatTime(time);
var outStr = time.h +':'+time.m +':'+time.s;
document.getElementById('time').innerHTML=outStr;
timeout = setTimeout(clock,20);
}
function formatTime(time){
for(var i in time){
if(i == "mils"){
if(time[i] < 1){
time[i] = "000";
}else
if(time[i] < 10){
time[i] = "00" + time[i];
}else
if(time[i] < 100){
time[i] = "0" + time[i];
}
}else if(time[i] < 10){
time[i] = "0" + time[i];
}
}
return time;
}
function milToTime(mil){
mi = mil % 1000;
seconds = parseInt(mil / 1000) % 60;
minutes = parseInt(mil / 1000 / 60) % 60;
hours = parseInt( mil / 1000 / 3600);
return {s: seconds, m: minutes, h:hours, mils:mi};
}
$('#btnClear').on('click', function(){
$('#lapList, #btnClear').fadeOut(function(){
$('#lapList').html('').fadeIn();
$('#timeTable thead').hide();
//$('#lapInst').fadeIn();
count = 0;
});
});
});
</script>
</body>
</html>