-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
315 lines (262 loc) · 10.8 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Kitchen Timer Utility">
<meta name="author" content="James Baker">
<title>Ding!</title>
<!-- Bootstrap core CSS -->
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="css/ding.css" rel="stylesheet">
<!-- HTML5 shim and Respond.js IE8 support of HTML5 elements and media queries -->
<!--[if lt IE 9]>
<script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
<script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
<![endif]-->
</head>
<body>
<a name="top"></a>
<div class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="extLink navbar-brand" href="index.html">Ding!</a>
</div>
<div class="collapse navbar-collapse">
<ul class="nav navbar-nav">
<li><a class="extLink" href="#top"><span class="glyphicon glyphicon-chevron-up"></span></a></li>
<li><a class="extLink" href="#feedme">Feed Me!</a></li>
<li><a class="extLink" href="#about">Wha?</a></li>
</ul>
</div><!--/.nav-collapse -->
</div>
</div>
<div class="container">
<div class="introduction">
<div class="page-header">
<h1>Ding! <small>Kitchen Timer</small></h1>
</div>
<a name="feedme"></a>
<div class="panel panel-default" id="panelSettings">
<div class="panel-heading">
<h3 class="panel-title">Choose Your Meal</h3>
</div>
<div class="panel-body">
<div class="row">
<div class="col-md-4">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownPresetDinner" data-toggle="dropdown">
What's for dinner?
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownPresetDinner" id="listPresetDinner">
</ul>
</div>
</div>
<div class="col-md-4">
<div class="dropdown">
<button class="btn btn-default dropdown-toggle" type="button" id="dropdownCustomDinner" data-toggle="dropdown">
What's cooking?
<span class="caret"></span>
</button>
<ul class="dropdown-menu" role="menu" aria-labelledby="dropdownCustomDinner" id="listCustomDinner">
</ul>
</div>
</div>
<div class="col-md-4">Add additional recipes and ingredients by editing the JSON files.</div>
</div>
</div>
<ul class="list-group" id="listIngredients">
</ul>
<div class="panel-footer text-right">
<a href="#" onclick="start()"><span class="glyphicon glyphicon-ok"></span> Let's Get Cooking!</a>
</div>
</div>
</div>
<div class="panel panel-default" style="display: none;" id="panelTimer">
<div class="panel-heading">
<h3 class="panel-title">Feed Me!</h3>
</div>
<div class="panel-body text-center">
<div class="jumbotron">
<h1 id="clock">00:00:00</h1>
<p><a href="#" onclick="pause()" id="pauseLink"><span class="glyphicon glyphicon-pause"></span></a> <a href="#" onclick="stop()"><span class="glyphicon glyphicon-stop"></span></a></p>
<p>Grub's up at <span id="endtime">0000</span></p>
</div>
</div>
<ul class="list-group" id="listSteps"></ul>
</div>
<a name="about"></a>
<div class="panel panel-default">
<div class="panel-heading">
<h3 class="panel-title">Wha?</h3>
</div>
<div class="panel-body">
<p class="lead">Ding! was written by me, James Baker, to help stop me overdoing the pasta or underdoing the veg.</p>
<p>It's free to use, but if you wish to thank me I'm currently raising money to take 30 Scouts from across Wiltshire to the 23rd World Scout Jamboree in Japan. We've got over £105,000 to raise, so any donations are very gratefully received. Please <a class="extLink" href="https://mydonate.bt.com/fundraisers/jamesbaker" target="_blank">donate now</a>!</p>
<p>The code is available on GitHub, and you are welcome to take the code and adapt it to your own needs. I also welcome Pull Requests that make the tool better for everybody.</p>
<p>No pizza was burnt during the making of Ding!.</p>
<p><small>Built using <a class="extLink" href="http://bootboxjs.com" target="_blank">Bootbox.js</a>, <a class="extLink" href="http://getbootstrap.com" target="_blank">Bootstrap</a>, <a class="extLink" href="https://github.com/goldfire/howler.js" target="_blank">Howler.js</a> and <a class="extLink" href="http://jquery.com" target="_blank">jQuery</a>. Trumpet sound clip by <a class="extLink" href="http://www.freesound.org/people/bone666138/sounds/198851/" target="_blank">bone666138</a>.</small></p>
</div>
</div>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<script src="js/bootbox.min.js"></script>
<script src="js/howler.min.js"></script>
<script>
var sound = new Howl({urls: ['trumpet.mp3', 'trumpet.ogg']});
var timerWorker = new Worker('js/interval.js');
var allIngredients = [];
var ingredients = [];
var timings = [];
var timerCount = 0;
var paused = false;
$('a').click(function (event){
if(!$(this).hasClass("extLink"))
event.preventDefault();
});
$.getJSON("data/ingredients.json", function(data){
allIngredients = data;
$.each(data, function(key, value){
$("#listCustomDinner").append('<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="addIngredient(\''+value.id+'\')">'+value.name+'</a></li>');
});
});
$.getJSON("data/recipes.json", function(data){
$.each(data, function(key, value){
$("#listPresetDinner").append('<li role="presentation"><a role="menuitem" tabindex="-1" href="#" onclick="addIngredients(\''+value.ingredients+'\')">'+value.name+'</a></li>');
});
});
function addIngredient(id){
if($.inArray(id, ingredients) == -1){
ingredients.push(id);
var ingredient = $.grep(allIngredients, function(e) { return e.id == id; });
if(ingredient.length > 0){
$("#listIngredients").append('<li class="list-group-item" id="ingredientsList-'+id+'"><a href="#" onclick="removeIngredient(\''+id+'\')"><span class="glyphicon glyphicon-remove"></span></a> ' + ingredient[0].name + '</li>');
}
}
}
function addIngredients(ids){
$.each(ids.split(","), function(key, value){
addIngredient(value);
});
}
function removeIngredient(id){
var index = $.inArray(id, ingredients);
if(index > -1){
ingredients.splice(index, 1);
$("#ingredientsList-"+id).remove();
}
}
function stepComplete(t){
$(t).replaceWith($('<li class="list-group-item disabled">'+t.innerText+'</li>'));
}
function start(){
paused = false;
if(ingredients.length == 0){
bootbox.alert("<h2>Don't be daft</h2><p>You need to decide what to cook before you can cook it!</p>");
return;
}
//Calculate timings
timings = [];
timings[0] = "Enjoy!";
$.each(ingredients, function(key, value){
var timeSum = 0;
var i = $.grep(allIngredients, function(e) { return e.id == value; })[0];
if(i != null){
$.each(i.steps.reverse(), function(stepKey, stepValue){
timeSum = timeSum + stepValue.time;
if(timings[timeSum] == undefined){
timings[timeSum] = stepValue.text;
}else{
timings[timeSum] += "; " + stepValue.text;
}
if(timeSum > timerCount)
timerCount = timeSum;
});
}
});
var id = 0;
$.each(timings.reverse(), function(key, value){
if(value != undefined)
$("#listSteps").append('<li class="list-group-item dingStep" id="stepsList-'+id+'" time="'+(timerCount - key)+'"><span class="badge">'+formatTime(timerCount - key)+'</span>' + value + '</li>');
id++;
});
var now = new Date();
var endTime = new Date(now.getTime() + timerCount*1000);
$("#endtime").text(formatClock(endTime.getHours(), (endTime.getMinutes()+1)));
timerWorker.onmessage = function(event){
if(event.data === 'interval.start'){
if(!paused){
timerCount--;
$("#clock").text(formatTime(timerCount));
$(".dingStep").each(function(){
if(!$(this).hasClass("disabled") && !$(this).hasClass("list-group-item-info")){
if(parseInt($(this).attr("time")) >= timerCount){
$(this).children().remove(".badge");
$(this).replaceWith($('<a href="#" class="list-group-item list-group-item-info" onclick="stepComplete(this)"><span class="glyphicon glyphicon-ok"></span> '+this.innerHTML+'</a>'));
sound.play();
}
}
});
if(timerCount == 0)
timerWorker.postMessage({stop:true});
}
}
};
timerWorker.postMessage({start:true, ms:1000});
$("#panelSettings").hide(1000);
$("#panelTimer").show(1000);
}
function stop(){
timerWorker.postMessage({stop:true});
timerCount = 0;
$("#clock").text("00:00:00");
$("#listSteps").empty();
$("#panelSettings").show(1000);
$("#panelTimer").hide(1000);
}
function pause(){
paused = !paused;
if(paused){
$("#pauseLink").html('<span class="glyphicon glyphicon-play"></span>');
}else{
$("#pauseLink").html('<span class="glyphicon glyphicon-pause"></span>');
var now = new Date();
var endTime = new Date(now.getTime() + timerCount*1000);
$("#endtime").text(formatClock(endTime.getHours(), (endTime.getMinutes()+1)));
}
}
function formatTime(seconds){
var hours = Math.floor(seconds / 3600);
var minutes = Math.floor((seconds % 3600)/60);
var seconds = Math.floor(seconds % 60);
if (hours < 10) {hours = "0"+hours;}
if (minutes < 10) {minutes = "0"+minutes;}
if (seconds < 10) {seconds = "0"+seconds;}
return hours+':'+minutes+':'+seconds;
}
function formatClock(hours, minutes){
var time = "";
if(hours < 10){
time = "0" + hours;
}else{
time = "" + hours;
}
if(minutes < 10){
time += "0" + minutes;
}else{
time += minutes;
}
return time;
}
</script>
</body>
</html>