-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweather.js
More file actions
74 lines (66 loc) · 2.34 KB
/
weather.js
File metadata and controls
74 lines (66 loc) · 2.34 KB
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
var ipURL = "https://freegeoip.net/json/";
function getIPInfo() {
$.ajax({
type: 'GET',
url: ipURL,
dataType: 'jsonp',
beforeSend: function () {
$(".spinner").fadeIn(2000);
},
success: function (iPDATA) {
//console.log(iPDATA);
var Longitude = iPDATA.longitude;
var Latitude = iPDATA.latitude;
var weatherURL = "https://api.darksky.net/forecast/1c5a660a1db62d4d3a423f21f1ae089b/"+ Latitude + "," + Longitude + "?exclude=hourly,daily,flags";
getWeather(weatherURL);
$(".info").fadeIn(2000).html(iPDATA.city + ", " + iPDATA.country_name);
$(".spinner").fadeOut(1000);
}
});
}
function getWeather(URL) {
$.ajax({
type: 'GET',
url: URL,
dataType: 'jsonp',
success: function (wDATA) {
//console.log(wDATA);
// Start Forcast Icons Canvas
var wICON = new Skycons();
wICON.add("weatherICON", wDATA.currently.icon);
wICON.play();
////////////////////////////////////////////////////
$(".pressure span").fadeIn(2000).html(wDATA.currently.pressure);
$(".humidity span").fadeIn(2000).html(wDATA.currently.humidity);
$(".visibility span").fadeIn(2000).html(wDATA.currently.visibility);
$(".windspeed span").fadeIn(2000).html(wDATA.currently.windSpeed);
$(".temperature").fadeIn(2000).html(wDATA.currently.summary + " <span class='temp badge'>" + wDATA.currently.temperature + " F</span>");
var temp = wDATA.currently.temperature;
changeCF(temp);
}
});
}
///////////////////////////
function changeCF(temp) {
function setCelsius() {
var cel = (temp - 32) * 5/9;
return Math.round(cel);
}
function setFahrenheit() {
return temp;
}
$('#tm').on("click", function () {
tm = $("#tm");
if(tm.val() == "C"){
$(tm).html("Fahrenheit").val("F");
$(".temp").html(setFahrenheit() + " F");
} else{
$(tm).html("Celsius").val("C");
$(".temp").html(setCelsius() + " C");
}
});
}
// Initiate jQuery //
$(document).ready(function(){
getIPInfo();
});