-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.html
405 lines (354 loc) · 14.3 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
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>How much will fiber cost me?</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
<style>
#laketown-calculator {
max-width: 1024px;
margin: auto;
text-align: center;
}
#laketown-calculator p {
text-align: left;
}
#laketown-calculator a {
color: #296BB0;
}
sup {
font-size: 60%;
line-height: 1;
}
sup > a {
text-decoration: none;
}
table {
width: 100%;
border-collapse: collapse;
}
th, td {
padding: .5em;
vertical-align: middle;
}
th {
text-align: right;
}
th[scope=row] {
text-align: right;
}
td {
border-left: solid 1px #ccc;
text-align: right;
white-space: nowrap;
}
tbody {
border-bottom: solid 1px #ccc;
}
tbody tr:nth-child(odd) {
background: #e7e7e7;
}
form {
display: inline-block;
text-align: left;
float: left;
}
input {
font-size: 130%;
font-family: inherit;
text-align: right;
}
input[type="number"][size="6"] {
width: 4em;
width: 6ch;
}
input[type="number"][size="5"] {
width: 3em;
width: 5ch;
}
.note {
color: #aaa;
font-size: 80%;
text-indent: -1.1ch;
}
#laketown-calculator .call-to-action {
clear: left;
margin-top: 5em;
text-align: center;
}
#annual_savings {
font-size: 130%;
font-weight: bold;
}
figure {
display: inline-block;
margin-top: 3em;
}
figcaption {
margin: 1em auto;
}
@media screen and (max-width: 750px) {
input, table {
font-size: 16px;
}
input[type="range"] {
display: block;
}
figure {
margin-right: auto;
margin-left: auto;
}
}
@media only screen and (-webkit-min-device-pixel-ratio: 2), only screen and (min-resolution: 200dpi) {
canvas {
width: 335px;
height: 450px;
}
}
</style>
<div id="laketown-calculator" class="container">
<p>Laketown Township <a href="http://www.laketowntwp.org/news-you-can-use/laketown-gig/">votes on May 3rd</a> to build a state-of-the-art fiber optic network to every home. With it will come a small millage and cheap access to 100-120 <abbr title="Megabits per second">Mbps</abbr> broadband and inexpensive TV & Phone service too. Use the calculator below to see how much you could save!</p>
<div class="phase" id="results">
<form action="#results" id="costs" data-phase="phase1">
<h2>Enter your home’s taxable value<sup><a href="#taxable-lookup">1</a></sup></h2>
<table>
<tbody>
<tr>
<th scope="row">Taxable Value</th>
<td>
$ <input type="number" inputmode="numeric" name="taxable_value" size="6" id="taxable_value" value="100000">
</td>
</tr>
</tbody>
</table>
<h2>Enter your monthly costs</h2>
<table>
<thead>
<tr>
<th></th>
<th>Current Monthly Cost</th>
<th>Future Monthly Cost</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">Internet<sup><a href="#bundles">2</a></sup></th>
<td>$ <input type="number" size="5" inputmode="numeric" name="internet" id="internet" class="service" value="75"></td>
<td>
<input type="range" min="25" max="40" value="32" id="projected-internet" class="projection" name="projected_internet">
<output data-name="projected_internet" id="projected-internet-display">$32</output><sup><a href="#fiber-cost">3</a></sup>
</td>
</tr><tr>
<th scope="row">Phone<sup><a href="#phone-cost">4</a></sup></th>
<td>$ <input type="number" size="5" inputmode="numeric" name="phone" id="phone" class="service" value="40"></td>
<td>$ <input type="number" size="5" inputmode="numeric" name="projected_phone" id="projected-phone" class="projection" value="9"></td>
</tr><tr>
<th scope="row">TV/Video<sup><a href="#video-cost">5</a></sup></th>
<td>$ <input type="number" size="5" inputmode="numeric" name="video" id="video" class="service" value="25"></td>
<td>$ <input type="number" size="5" inputmode="numeric" name="projected_video" id="projected-video" class="projection" value="25"></td>
</tr>
<tr>
<th scope="row">Fiber Millage</th>
<td>—</td>
<td><output data-name="fiber_millage" id="fiber_millage"></output></td>
</tr>
</tbody>
<tfoot>
<tr>
<th scope="row">Total</th>
<td><output data-name="current_monthly" id="current_monthly"></output></td>
<td><output data-name="projected_total" id="projected_total"></output></td>
</tr>
<tr>
<th scope="row">Annual Savings</th>
<td></td>
<td><output data-name="annual_savings" id="annual_savings"></output></td>
</tfoot>
</table>
</form>
<figure>
<figcaption>Monthly Costs</figcaption>
<canvas id="graph" width="335" height="450"></canvas>
</figure>
</div>
<p class="call-to-action">Ready to help the campaign? Head to the <a href="http://laketownfiberopticyes.com">Fiber Optic YES!</a> website or <a href="http://facebook.com/Laketown-Fiber-Optic-YES-1801402866754094/">Facebook Page</a></a>
<p class="note" id="taxable-lookup"><sup>1</sup> Don’t know your taxable value? No problem. You can find it by calling the township at <a href="tel:+16163353050" class="tel">(616) 335-3050</a>
or visiting the <a href="https://allegancounty.is.bsasoftware.com/bsa.is/TaxServices/ServiceTaxSearch.aspx?i=3&appid=1&unit=380">Allegan County website</a> and searching for your address.
</p>
<p class="note" id="bundles"><sup>2</sup> If you have a bundled plan including internet with phone, or video, just fill in the internet field.</p>
<p class="note" id="fiber-cost"><sup>3</sup> $25–40 is the projected monthly cost of 100–120 <abbr title="Megabits per second">Mbps</abbr> broadband internet in the Laketown plan. The more people who sign up, the lower the cost.</p>
<p class="note" id="phone-cost"><sup>4</sup> Landline phones start at $40 for most residents. Switching to an internet-based phone provider like Vonage or magicJack can be $9/month or less.</p>
<p class="note" id="video-cost"><sup>5</sup> Estimates based on average basic cable package.</p>
</div>
<script>
Results = {};
Calculator = {
init: function () {
var projected_internet = document.getElementById('projected-internet');
this.values = document.querySelectorAll("#costs .service");
this.projections = document.querySelectorAll("#costs .projection");
this.taxable_value = document.querySelectorAll("#taxable_value");
this.addListeners(this.values);
this.addListeners(this.projections);
this.addListeners(this.taxable_value);
projected_internet.addEventListener("change", Calculator.updateProjection);
projected_internet.addEventListener("input", Calculator.updateProjection);
this.computeValues();
Calculator.updateProjection();
},
addListeners: function (values) {
var idx = 0;
while (idx < values.length) {
values[idx].addEventListener("keypress", this.procede);
values[idx].addEventListener("focus", this.procede);
values[idx].addEventListener("change", Calculator.updateProjection);
values[idx].addEventListener("keyup", this.wait);
idx += 1;
}
},
procede: function () {
window.clearTimeout(window.delay);
},
wait: function () {
window.delay = window.setTimeout(Calculator.updateProjection, 500);
},
parseNumber: function (number) {
if ((typeof number === 'string' || number instanceof String) && number.length) {
return parseFloat(number.replace(/[^\d|\.]/g, ""));
}
return parseFloat(+number);
},
sum: function (values) {
var idx = 0,
total = 0;
while (idx < values.length) {
if (values[idx].value) {
total += Calculator.parseNumber(values[idx].value);
Results[values[idx].getAttribute('name')] = values[idx].value;
} else {
Results[values[idx].getAttribute('name')] = 0;
}
idx += 1;
}
return total;
},
computeValues: function () {
var values = Calculator.values,
projections = Calculator.projections,
taxable_value = Calculator.taxable_value[0];
Results.fiber_millage = Math.round(100 * (Calculator.parseNumber(taxable_value.value) * 0.0016572) / 12) / 100.00;
// projected_monthly is without millage
Results.projected_monthly = Calculator.sum(projections);
Results.current_monthly = Calculator.sum(values);
// projected_total is projected_monthly + fiber_millage
Results.projected_total = Calculator.parseNumber(Results.projected_monthly) + Calculator.parseNumber(Results.fiber_millage);
Results.projected_total = Math.round(Results.projected_total * 100) / 100;
Results.annual_savings = Calculator.parseNumber(12 * Results.current_monthly) - Calculator.parseNumber(12 * Results.projected_total);
Results.annual_savings = Math.round(Results.annual_savings * 100) / 100;
this.updateUIValues();
},
updateUIValues: function() {
for (var id in Results) {
var element = document.getElementById(id);
if (element) {
element.textContent = Calculator.formatCurrency(Results[id]);
}
}
document.getElementById('projected-internet-display').value = "$" + document.getElementById('projected-internet').value;
},
formatCurrency: function(n) {
n = parseFloat(n);
return "$" + n.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, "$1,");
},
updateProjection: function (event) {
var projected_total = (Results.projected_total - Results.projected_internet + parseInt(this.value, 10)),
projected_monthly = projected_total - Results.fiber_millage;
Calculator.computeValues();
Calculator.graph();
},
graph: function () {
var graph = document.getElementById("graph"),
projectionRect,
currentRect,
millageRect,
ymax,
startTime,
backingScale = function (pixels) {
if ('devicePixelRatio' in window) {
if (window.devicePixelRatio > 1) {
return window.devicePixelRatio * pixels;
}
}
return pixels;
},
setScaleFactor = function(canvas) {
var scaleFactor = backingScale(1);
if (1 < scaleFactor) {
canvas.width = 335 * scaleFactor;
canvas.height = 450 * scaleFactor;
}
// update the context for the new canvas scale
return context = canvas.getContext("2d");
},
context = setScaleFactor(graph),
drawRectangle = function (myRectangle, context, color) {
context.fillStyle = color;
context.fillRect(
backingScale(myRectangle.x),
backingScale(myRectangle.y),
backingScale(myRectangle.w),
backingScale(myRectangle.h));
},
drawLegend = function (formatCurrency) {
drawRectangle({x: 40, y: 400, w: 20, h: 20}, context, "#8c999e");
drawRectangle({x: 40, y: 360, w: 20, h: 20}, context, "#296bb0");
drawRectangle({x: 40, y: 320, w: 20, h: 20}, context, "#a6d15e");
context.font= "normal " + backingScale(12) + "px 'Ubuntu Mono', 'Roboto Mono', 'Segoe Mono', Consolas, Menlo, monospace";
context.fillStyle = "#666";
context.fillText(formatCurrency(Results.fiber_millage) + " Fiber Millage", backingScale(70), backingScale(335));
context.fillText(formatCurrency(Results.projected_monthly) + " Future Monthly Services", backingScale(70), backingScale(375));
context.fillText(formatCurrency(Results.current_monthly) + " Current Monthly Services", backingScale(70), backingScale(415));
},
drawAxis = function () {
context.fillStyle = "#666";
context.fillText("$0", 0, backingScale(300));
context.moveTo(backingScale(25), 0);
context.lineTo(backingScale(30.5), 0);
context.lineTo(backingScale(30.5), backingScale(300));
context.moveTo(backingScale(25), backingScale(300));
context.lineTo(backingScale(300), backingScale(300));
context.strokeStyle = "#ccc";
context.stroke();
context.fillText("$" + Math.floor(ymax), 0, backingScale(13));
},
measureRects = function (difference, projected_monthly, projected_total) {
var current, projection, millage;
if (difference < 0) {
ymax = Results.projected_total;
current = 300 * (Results.current_monthly / ymax);
projection = 300 * (projected_monthly / ymax)
millage = 300 * (Results.fiber_millage / ymax)
currentRect = {x: 40, y: 300, w: 80, h: -current};
millageRect = {x: 160, y: 300 - projection, w: 80, h: -millage};
} else {
ymax = Results.current_monthly;
projection = 300 * (projected_monthly / ymax)
millage = Results.fiber_millage / ymax;
currentRect = {x: 40, y: 300, w: 80, h: -300};
millageRect = {x: 160, y: 300 - projection, w: 80, h: -(300 * millage)};
}
projectionRect = {x: 160, y: 300, w: 80, h: -(projection)};
drawRectangle(currentRect, context, "#8c999e");
drawRectangle(millageRect, context, "#a6d15e");
drawRectangle(projectionRect, context, "#296BB0");
};
context.clearRect(0,0,backingScale(335), backingScale(450));
measureRects(Results.current_monthly - Results.projected_total, Results.projected_monthly, Results.projected_total);
drawLegend(this.formatCurrency);
drawAxis(ymax);
}
};
Calculator.init();
</script>
</body>
</html>