-
Notifications
You must be signed in to change notification settings - Fork 9
/
jquery.simplerWeather.min.js
12 lines (11 loc) · 2.14 KB
/
jquery.simplerWeather.min.js
1
2
3
4
5
6
7
8
9
10
11
12
/*
simplerWeather v1.0.0
Author: Brooke.
URL: https://github.com/BrookeDot/SimplerWeather
License: MIT
Based on SimpleWeather -- https://github.com/monkeecreate/jquery.simpleWeather
Simple Weather Java Switches to DarkSky */
(function(f){function e(b,e){return"f"===b?Math.round(5/9*(e-32)):Math.round(1.8*e+32)}f.extend({simplerWeather:function(b){b=f.extend({location:"",units:"f",authmethod:"apikey",apikey:"",proxyurl:"",forecast:"true",forecastdays:"4",success:function(b){},error:function(b){}},b);var g="c"===b.units.toLowerCase()?"si":"us";f.getJSON(encodeURI(function(c){if(/^\-?\d+(\.\d+)?,\s*\-?\d+(\.\d+)$/.test(b.location))var a=b.location.split(","),e=a[0],a=a[1];else b.error("Could not retrieve weather due to an invalid location. Must enter location as latitude,longitude");
if("apikey"===c&&""!==b.apikey)return"https://api.darksky.net/forecast/"+encodeURIComponent(b.apikey)+"/"+e+","+a+"/?units="+g+"&exclude=minutely,hourly,alerts,flags";if("proxy"===c&&""!==b.proxyurl)return encodeURI(b.proxyurl+"?lat="+e+"&lon="+a+"&units="+g);b.error("Could not retrieve weather due to an invalid api key or proxy setting.")}(b.authmethod)),function(c){if(null!==c){var a={};a.temp=c.currently.temperature;a.currently=c.currently.summary;a.icon=c.currently.icon;a.pressure=c.currently.pressure;
a.humidity=c.currently.humidity;a.visibility=c.currently.visibility;a.updated=c.currently.time;a.high=c.daily.data[0].temperatureHigh;a.low=c.daily.data[0].temperatureLow;a.sunrise=c.daily.data[0].sunriseTime;a.sunset=c.daily.data[0].sunsetTime;a.description=c.daily.data[0].summary;a.attributionlink="https://darksky.net/";a.unit=b.units.toLowerCase();a.altunit="f"===a.unit?"c":"f";a.alt={temp:e(b.units,a.temp),high:e(b.unit,a.high),low:e(b.unit,a.low)};if(b.forcast&&"NaN"!==parseInt(b.forecastdays)){a.forecast=
[];for(var f=0;f<b.forecastdays;f++){var d=c.daily.data[f];d.date=d.time;d.summary=d.summary;d.high=d.temperatureHigh;d.low=d.temperatureLow;d.icon=d.icon;d.alt={high:e(b.units,d.temperatureHigh),low:e(b.units,d.temperatureLow)};a.forecast.push(d)}}b.success(a)}else b.error("There was a problem retrieving the latest weather information.")});return this}})})(jQuery);