-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.html
278 lines (261 loc) · 5.91 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
<!doctype html>
<html>
<head>
<title>Food.js</title>
<meta charset="utf-8">
<meta name="description" content="A cookbook for minimalists.">
<meta name="keywords" content="Cook book, programming, code, minimalism, food, cooking, cookbook, javascript, efficient, lightweight, small, user friendly, easy">
<meta name="viewport" content="width=device-width, maximum-scale=1, initial-scale=1, user-scalable=yes">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="shortcut icon" type="image/png" href="food.js.png">
<link rel="apple-touch-icon" href="food.js.png">
<link rel="shortcut icon" type="image/png" href="food.js.png">
<script>
var recipes = {
"Baba Ghanoush":{
"Baked Eggplant":454,
"Lemon Juice":59,
"Extra Virgin Olive Oil":59,
"Tahini":59,
"Garlic":3,
"Salt":1,
"Pepper":1
},
"Buttermilk Pancakes":{
"Eggs":157,
"Milk":851,
"Apple Cider Vinegar":45,
"Melted Butter":76,
"Flour":359,
"Sugar":38,
"Baking Powder":30,
"Baking Soda":16,
"Salt":5
},
"Cheese Biscuit Cookies":{
"Margarine":227,
"Sharp Cheddar Cheese":227,
"Unsifted Flour":283,
"Red Pepper Flakes":1.5,
"Salt":1.5
// bake 12 minutes @ 375
},
"Coffee":{
"Grounds":22,
"Water":355
},
"Cole Slaw":{
"Cabbage":250,
"Carrots":65,
"Red Onion":100,
"Mayonaise":45,
"Dijon Mustard":20,
"Dill Pickle":45,
"Pickle Brine":35,
"Honey":2,
"Dill":0.2,
"Salt":0.2,
"Pepper":0.2,
},
"Cranberry Sauce":{
"Cranberries":250,
"Brown Sugar":100,
"Orange Juice":100,
"Clementine Zest":2
},
"Grits":{
"Stone Ground Grits":109,
"Water":573,
"Chicken Boullion": 6,
"Half & Half": 130,
"Acidic Cheeses": 84
},
"Invention":{
"Perspiration":93,
"Electricity":6,
"Evaporation":4,
"Butterscotch Ripple":2
},
"Mashed Potatoes":{
"Peeled Rinsed Potatoes": 900,
"Salt": 31,
// boil in salty water
"Butter":50,
"Garlic":5,
"Olive Oil":108,
"Milk": 10
},
"Pimm's Cup":{
"Pimm's No. 1":73,
"Ginger Ale":196,
"Water":130,
"Cucumber":19,
"Lemon":19
},
"Orange Beef":{
"Ground Beef": 450,
"Garlic":12,
"Brown Sugar":100,
"Soy Sauce":100,
"Orange Juice":100,
"Broccoli":100,
"Green Onion":6
},
"Pajeon (Scallion Pancakes)":{
"Egg": 52,
"All Purpose Wheat Flour": 125,
"Water": 118,
"Kimchi Brine": 44,
"Salt": 2,
},
"Porridge":{
"Rolled Oats": 50,
"Water": 250,
"Milk": 100,
"Other": 60
},
"Rice":{
"Rice":205,
"Water":473
},
"Squash Soup":{
"Baked Squash Meat": 1130,
"Chicken Stock": 1180,
"Onion": 220,
"Unsalted Butter": 28,
"Garlic": 10,
"Honey": 6,
"Cayenne Pepper": 2,
"Black Pepper": 2,
"Oregano": 2,
"Nutmeg": 2,
},
};
</script>
<link href='https://fonts.googleapis.com/css?family=PT+Serif:400italic,700' rel='stylesheet' type='text/css'>
<style>
*{
box-sizing:border-box;
font-size:6vw;
}
body{
background-color:#f7f1e6;
font-family:"PT Serif", Trebuchet MS, Trebuchet, serif;
}
input{
width:30%;
font-weight:700;
font-size:150%;
text-align:right;
border:0;
background-color:#afefee;
border-radius:0.1em;
padding:0 0.1em;
}
label{
font-weight:400;
padding-left:0.5em;
color:#227878;
font-style:italic;
}
hr{
margin:0.5em;
border:0;
}
ul{
margin-left:1em;
list-style:circle;
}
h1,a{
color:#46332c;
}
a{
padding:0 0.25em;
text-decoration:none;
border-radius:0.2em;
}
a:hover, a:active{
color:white;
background-color:#46332c;
}
.logo{
border:solid 1px #46332c;
}
</style>
</head>
<body>
<h1>
<a class="logo" href="javascript:renderMenu()">Food.js</a>
<span id="recipeName"></span>
</h1>
<div id="content"></div>
<script>
var content_el = document.getElementById('content');
var recipeName_el = document.getElementById('recipeName');
function renderMenu(){
recipeName_el.innerHTML = '';
document.title = 'Food.js';
location.hash = '';
var ui = ['<ul>'];
for(key in recipes){
ui.push('<li><a href="javascript:renderRecipe(\''+escape(key.replace('\'','\\\''))+'\')">'+key+'</a></li>');
}
ui.push('</ul>')
content_el.innerHTML = ui.join('');
}
var elementList = [];
function update(changed){
var scalar = changed.value / changed.dataset.original;
for(i=0; i<elementList.length; i++){
if(elementList[i] !== changed){
var value = elementList[i].dataset.original * scalar;
if(value < 1)
value = value.toPrecision(1);
else
value = Math.round(value);
elementList[i].value = value;
}
}
}
function renderRecipe(recipe){
location.hash = recipe;
recipe = unescape(recipe);
if(recipes[recipe] === undefined){
renderMenu();
return;
}
recipeName_el.innerHTML = recipe;
document.title = `${recipe} - Food.js`;
// make UI for each ingredient
var ui = [];
var total = 0;
for(ingredient in recipes[recipe]){
ui.push('<input type="number" inputmode="numeric" pattern="[0-9]*" min="0" value="',recipes[recipe][ingredient],'" data-original="',recipes[recipe][ingredient],'" />');
ui.push('<label>',ingredient,'</label>');
ui.push('<hr>');
total += recipes[recipe][ingredient];
}
ui.push('<input type="number" inputmode="numeric" pattern="[0-9]*" min="0" value="',total,'" data-original="',total,'" />');
ui.push('<label>Total</label>');
content_el.innerHTML = ui.join('');
// bind event handlers
elementList = document.querySelectorAll('input');
for(i=0; i<elementList.length; i++){
elementList[i].oninput = function(){
update(this);
}
}
}
function renderPage(){
if(location.hash === undefined){
renderMenu();
}else{
renderRecipe(unescape(location.hash.replace('#','')));
}
}
renderPage();
window.addEventListener('hashchange', renderPage);
</script>
</body>
</html>