Pessoal, fico com vergonha, mas esta vida de aprendiz .. :)
function geo_init() {
if ($(".overlay").removeClass("loaded", "error"), $(".overlay").empty(), geoLocationLoading("initial loading..."), $(".weather > div").css({
marginLeft: "50px",
opacity: "0"
}), $(".weather .location > span").empty(), $(".weather .header .icone").empty(), $(".weather .header div > span").empty(), $(".weather .header .temp").empty(), $(".weather .status").empty(), navigator.geolocation) {
var a = setTimeout(function() {
geoLocationLoading("HTML5 geolocation prompt Timeout,<br /> Attempting IP Based Location"), console.log("HTML5 geolocation Prompt Timeout, Attempting IP Based Location"), geolocFail()
}, 15e3);
WatchID = navigator.geolocation.watchPosition(function(b) {
clearTimeout(a);
var c = b.coords.latitude,
d = b.coords.longitude;
geoLocationLoading("HTML5 geolocation User Granted"), console.log("HTML5 geolocation User Granted"), geocodeLatLng(c, d)
}, function(b) {
clearTimeout(a), 1 === b.code ? (geoLocationLoading(b.message + ",<br /> Attempting IP Based geolocation"), console.log(b.message + ", Attempting IP Based geolocation"), geolocFail()) : 2 === b.code ? (geoLocationLoading(b.message + ",<br /> Attempting IP Based geolocation"), console.log(b.message + ", Attempting IP Based geolocation"), geolocFail()) : 3 === b.code ? (geoLocationLoading(b.message + ",<br /> Attempting IP Based geolocation"), console.log(b.message + ", Attempting IP Based geolocation"), geolocFail()) : (geoLocationLoading("HTML5 geolocation Unknown Error,<br /> Attempting IP Based geolocation"), console.log("HTML5 geolocation Unknown Error, Attempting IP Based geolocation"), geolocFail())
}, {
maximumAge: 1e5,
timeout: 12e3,
enableHighAccuracy: !0
})
} else geoLocationLoading("HTML5 geolocation not available,<br /> Attempting IP Based geolocation"), console.log("HTML5 geolocation not available, Attempting IP Based geolocation"), geolocFail()
}
function geocodeLatLng(a, b) {
var c = "";
c = "<br/>HTML5 GEO LOCATION PROVIDED DATA", $(".status").html(c), get_weather(a, b)
}
function geolocFail() {
var a = "";
if (a = "<br/>MAXMIND GEOIP API PROVIDED DATA", $(".status").html(a), "undefined" != geoip_latitude() || "" !== geoip_latitude()) {
var b = geoip_latitude(),
c = geoip_longitude();
get_weather(b, c)
} else geoLocationLoading("IP based geolocation Error"), console.log("IP based geolocation Error")
}
function GetTodayDate() {
var a = new Array("January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"),
b = new Date,
c = b.getDate(),
d = "";
d = 1 == c || 21 == c || 31 == c ? "st" : 2 == c || 22 == c ? "nd" : 3 == c || 23 == c ? "rd" : "th";
var e = b.getMonth(),
f = b.getFullYear(),
g = c + "<SUP>" + d + "</SUP> " + a[e] + " " + f + " ";
return g
}
function get_avg_temp(a, b) {
return averageTem = (parseInt(a, 10) + parseInt(b, 10)) / 2
}
function get_custom_icon(a) {
switch (a) {
case "chanceflurries":
return "\ue010";
case "chancerain":
return "\ue011";
case "chancesleet":
return "\ue016";
case "chancesnow":
return "\ue016";
case "chanceflurries":
return "\ue016";
case "chancetstorms":
return "\ue00f";
case "clear":
return "\ue001";
case "cloudy":
return "\ue018";
case "flurries":
return "\ue016";
case "fog":
return "\ue00c";
case "hazy":
return "\ue017";
case "mostlycloudy":
return "\ue018";
case "mostlysunny":
return "\ue001";
case "partlycloudy":
return "\ue007";
case "partlysunny":
return "\ue007";
case "sleet":
return "\ue016";
case "rain":
return "\ue011";
case "snow":
return "\ue016";
case "tstorms":
return "\ue00e";
case "":
console.log("no weather icon found");
break;
default:
return console.log("no weather icon found, placing the default one"), "icon-cloudy"
}
}
function animateEach() {
$(".overlay").addClass("loaded"), $(".weather > div").each(function(a) {
$(this).delay(800 * a++).animate({
opacity: 1,
marginLeft: "0px"
}, "slow")
})
}
function geoLocationError(a) {
$(".overlay").addClass("error"), $(".overlay").html("<div class='errorMsg'>" + a + "</div>"), $(".overlay").attr("data-icon", "\ue02b")
}
function geoLocationLoading(a) {
$(".overlay").addClass("loading"), $(".overlay").html("<div class='LoadingMsg'>" + a + "</div>")
}
function get_weather(a, b) {
var c = a,
d = b;
wu_query = c + "," + d, wu_url = wu_base_url + "/" + wu_api_key + "/" + wu_features + "/q/" + wu_query + ".json", $.ajax({
url: wu_url,
dataType: "jsonp",
timeout: 5e3,
success: function(a) {
if ($(".clima").show(), a.response.error) a.response.error.description ? geoLocationError("Sorry Weather not available " + a.response.error.description) : a.response.error.type ? geoLocationError("Sorry Weather not available " + a.response.error.type) : geoLocationError("Sorry Weather not available");
else {
var b = a.location.city;
", " + a.location.country, a.location.wuiurl;
var e = a.forecast.simpleforecast.forecastday[0],
f = e.icon,
g = get_custom_icon(f),
h = e.high.celsius,
i = e.low.celsius;
$(".clima .icone").attr("data-icon", g), $(".clima h3").html(b + " "), $(".max span").html(h + " °"), $(".min span").html(i + " °"), setTimeout(animateEach, 2e3), navigator.geolocation.clearWatch(WatchID)
}
},
error: function(a, b, c) {
c ? (geoLocationError("Sorry, Ajax Error! " + c), console.log("errorStatus:" + b), console.log("errorThrown:" + c)) : geoLocationError("Sorry, Unknown Ajax Error!")
}
})
}
geo_init();