forked from mmachenry/how-much-snow
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhowmuchsnow.js
50 lines (44 loc) · 1.23 KB
/
howmuchsnow.js
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
function useGeolocation(position){
var lat = position.coords.latitude;
var lon = position.coords.longitude;
var url = "/?geo=1&lat=" + lat + "&lon=" + lon;
var req = new XMLHttpRequest();
var result = "empty";
req.open("GET", url, true);
req.onreadystatechange = function () {
if (req.readyState === 4){
result = JSON.parse(req.responseText);
if (result.inches === "") {
$("#out_of_range_msg").show();
} else {
$("#snow").html(result.inches).css("font-size", "120pt");
$("body").css("text-align", "center");
$("#coordinates").html(result.coords);
}
}
};
req.send(null);
}
function onDenied () {
$("#coordinates").html("Location permission denied.");
}
// ellipsis animation
var dots = 0;
function animateDots() {
if (dots < 3) {
$('#dots').append('.');
dots++;
} else {
$('#dots').html('');
dots = 0;
}
}
$(function (){
setInterval(animateDots, 600);
if (geoPosition.init()) {
geoPosition.getCurrentPosition(useGeolocation, onDenied);
}
else {
$("#snow").html("Sorry, we can't get your location.");
}
});