Skip to content

Commit 3828c23

Browse files
committed
Fix the demo
* Replace `Number.parseInt()` with `Number.parseFloat()`. Thank you @zhblinder. * Update library version used. * Clean up code.
1 parent b522502 commit 3828c23

File tree

1 file changed

+33
-16
lines changed

1 file changed

+33
-16
lines changed

docs/index.html

Lines changed: 33 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,11 @@
33
<head>
44
<meta charset="UTF-8">
55
<title>KosherZmanim demo</title>
6-
<script src="https://unpkg.com/kosher-zmanim@0.6.0/dist/kosher-zmanim.min.js"></script>
6+
<!--
7+
This demo uses the unminified version, so that it's easier to step through using the debugger.
8+
In production, you should use the minified build: `kosher-zmanim.min.js`
9+
-->
10+
<script src="https://unpkg.com/kosher-zmanim@0.8.0/dist/kosher-zmanim.js"></script>
711
</head>
812
<body>
913
<h2>KosherZmanim demo</h2>
@@ -16,12 +20,12 @@ <h2>KosherZmanim demo</h2>
1620
<td><input id="date"/></td>
1721
</tr>
1822
<tr>
19-
<td><label for="timeZoneId">Timezone ID</label></td>
20-
<td><input id="timeZoneId" value="America/New_York"/></td>
23+
<td><label for="time-zone-id">Timezone ID</label></td>
24+
<td><input id="time-zone-id" value="America/New_York"/></td>
2125
</tr>
2226
<tr>
23-
<td><label for="locationName">Location Name</label></td>
24-
<td><input id="locationName" value="Lakewood"/></td>
27+
<td><label for="location-name">Location Name</label></td>
28+
<td><input id="location-name" value="Lakewood"/></td>
2529
</tr>
2630
<tr>
2731
<td><label for="latitude">Latitude</label></td>
@@ -49,23 +53,36 @@ <h2>KosherZmanim demo</h2>
4953

5054
<script>
5155
(function() {
52-
// Get the date
53-
document.querySelector("input#date").value = new Date().toISOString();
56+
const dateEl = document.querySelector('input#date');
57+
const timeZoneIdEl = document.querySelector('input#time-zone-id');
58+
const locationNameEl = document.querySelector('input#location-name');
59+
const latitudeEl = document.querySelector('input#latitude');
60+
const longitudeEl = document.querySelector('input#longitude');
61+
const elevationEl = document.querySelector('input#elevation');
62+
const complexEl = document.querySelector('input#complex');
63+
const calculateButtonEl = document.querySelector('button#calculate');
64+
const outputEl = document.querySelector('#output');
65+
66+
// Initialize the date field with the current date
67+
dateEl.value = new Date().toISOString();
5468

5569
// Add a listener for the Calculate button
56-
document.querySelector("button#calculate").addEventListener("click", function() {
70+
calculateButtonEl.addEventListener('click', () => {
5771
const options = {
58-
date: document.querySelector("input#date").value,
59-
timeZoneId: document.querySelector("input#timeZoneId").value,
60-
locationName: document.querySelector("input#locationName").value,
61-
latitude: Number.parseInt(document.querySelector("input#latitude").value),
62-
longitude: Number.parseInt(document.querySelector("input#longitude").value),
63-
elevation: Number.parseInt(document.querySelector("input#elevation").value),
64-
complexZmanim: document.querySelector("input#complex").checked,
72+
date: dateEl.value,
73+
timeZoneId: timeZoneIdEl.value,
74+
locationName: locationNameEl.value,
75+
latitude: Number.parseFloat(latitudeEl.value),
76+
longitude: Number.parseFloat(longitudeEl.value),
77+
elevation: Number.parseFloat(elevationEl.value),
78+
complexZmanim: complexEl.checked,
6579
};
6680

81+
// Calculate the zmanim to a JSON object
82+
const json = KosherZmanim.getZmanimJson(options);
83+
6784
// Output the results
68-
document.querySelector("#output").innerText = JSON.stringify(KosherZmanim.getZmanimJson(options), null, 2);
85+
outputEl.innerText = JSON.stringify(json, null, 2);
6986
});
7087
})();
7188
</script>

0 commit comments

Comments
 (0)