-
Notifications
You must be signed in to change notification settings - Fork 4
/
index.html
140 lines (140 loc) · 3.95 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
<html>
<head>
<meta charset="UTF-8">
<title>Document</title>
<script src="dist/measure.js"></script>
<script src="src/measureDensity.js"></script>
<link rel="stylesheet" href="normalize.min.css">
<style>
html { font-size: 300%; }
body { padding: 100px; text-align: center; }
select { -webkit-appearance: none; padding-left: 10px; }
input, select { text-align:center; width: 100%; padding: 0 10px; }
#amount, #density, #units { font-size: 30px; }
#amount, #density { color: #ddd; }
.col { width: 30%; float: left; }
.gut {
width: 5%;
float: left;
font-size: 25px;
color: #ddd;
padding-top: 164px;
}
</style>
</head>
<body>
<div class="col">
<p>Amount</p>
<input type="text" placeholder="eg. 1/2 cup" onkeyup="onAmountChange(this)">
<p id="amount"></p>
</div>
<div class="gut" style="display:none">
of
</div>
<div class="col" style="display:none">
<p>Material</p>
<select id="material" onchange="onMaterialChange(this)">
</select>
<p id="density"></p>
</div>
<div class="gut">
as
</div>
<div class="col">
<p>Units</p>
<select id="unit" onchange="onUnitChange(this)">
<optgroup label="Volume">
<option value="1">teaspoons</option>
<option value="2">tablespoons</option>
<option value="3">fluidounces</option>
<option value="4">shots</option>
<option value="5">gills</option>
<option value="6">cups</option>
<option value="7">pints</option>
<option value="8">fifths</option>
<option value="9">quarts</option>
<option value="10">gallons</option>
</optgroup>
<optgroup label="Mass">
<option value="11">g</option>
<option value="12">kg</option>
</optgroup>
</select>
<p id="units"></p>
</div>
<script>
var m = measure();
var s = document.getElementById('unit');
var amount = document.getElementById('amount');
var density = document.getElementById('density');
var material = document.getElementById('material');
var units = document.getElementById('units');
var selectedUnitValue = 1;
function updateDisplay() {
// amount
if (m.ml) {
amount.innerHTML = 'Volume<br>' + m.ml + 'ml';
} else {
amount.innerHTML = 'Mass<br>' + m.g + 'g';
}
// material
density.innerHTML = 'Density<br>' + m.d + 'g/ml';
// units
units.innerHTML = ' <br>';
switch(selectedUnitValue) {
case 1:
return units.innerHTML += m.teaspoons();
case 2:
return units.innerHTML += m.tablespoons();
case 3:
return units.innerHTML += m.fluidounces();
case 4:
return units.innerHTML += m.shots();
case 5:
return units.innerHTML += m.gills();
case 6:
return units.innerHTML += m.cups();
case 7:
return units.innerHTML += m.pints();
case 8:
return units.innerHTML += m.fifths();
case 9:
return units.innerHTML += m.quarts();
case 10:
return units.innerHTML += m.gallons();
case 11:
return units.innerHTML += m.grams();
case 12:
return units.innerHTML += m.kilograms();
}
}
function onAmountChange(el) {
m = measure(el.value);
m.d = Number(material.options[material.selectedIndex].value);
updateDisplay();
}
function onMaterialChange(el) {
m.d = Number(el.options[el.selectedIndex].value);
updateDisplay();
}
function onUnitChange(el) {
selectedUnitValue = Number(el.options[el.selectedIndex].value);
updateDisplay();
}
// load density select
for (var i = 0, l = MeasureDensity.length; i < l; i ++) {
var v = MeasureDensity[i];
var o = document.createElement('option');
o.setAttribute('value', v.value);
o.innerHTML = v.name;
material.appendChild(o);
}
function onMaterialChange(el) {
var density = el.value;
m.d = Number(density);
density.innerHTML = 'Density<br>' + density;
onUnitChange(s);
}
</script>
</body>
</html>