This repository was archived by the owner on Jan 23, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathjquery.simpleWeather.min.js
More file actions
13 lines (13 loc) · 6.49 KB
/
jquery.simpleWeather.min.js
File metadata and controls
13 lines (13 loc) · 6.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
/*
* simpleWeather
* http://simpleweatherjs.com
*
* A simple jQuery plugin to display current weather data
* for any location and doesn't get in your way.
*
* Developed by James Fleeting <@fleetingftw> <http://iwasasuperhero.com>
* Another project from monkeeCreate <http://monkeecreate.com>
*
* Version 2.7.0 - Last updated: April 17 2014
*/
!function(e){"use strict";e.extend({simpleWeather:function(t){t=e.extend({location:null,woeid:"2357536",unit:"f",success:function(){},error:function(){}},t);var o,i;if(t.location)i='select * from weather.forecast where woeid in (select woeid from geo.placefinder where text="'+t.location+'" and gflags="R") and u="'+t.unit+'"';else{if(!t.woeid)return t.error("Could not retrieve weather due to an invalid location."),!1;i="select * from weather.forecast where woeid="+t.woeid+' and u="'+t.unit+'"'}return o="https://query.yahooapis.com/v1/public/yql?q="+i+' and u="f"&format=json&diagnostics=true&callback=',e.getJSON(encodeURI(o),function(o){null!==o&&null!==o.query&&null!==o.query.results&&"Yahoo! Weather Error"!==o.query.results.channel.description?e.each(o.query.results,function(e,o){-1!==o.constructor.toString().indexOf("Array")&&(o=o[0]);var i,r=[],a=[],s=["N","NNE","NE","ENE","E","ESE","SE","SSE","S","SSW","SW","WSW","W","WNW","NW","NNW","N"],c=s[Math.round(o.wind.direction/22.5)];i=o.item.condition.temp<80&&o.atmosphere.humidity<40?-42.379+2.04901523*o.item.condition.temp+10.14333127*o.atmosphere.humidity-.22475541*o.item.condition.temp*o.atmosphere.humidity-6.83783*Math.pow(10,-3)*Math.pow(o.item.condition.temp,2)-5.481717*Math.pow(10,-2)*Math.pow(o.atmosphere.humidity,2)+1.22874*Math.pow(10,-3)*Math.pow(o.item.condition.temp,2)*o.atmosphere.humidity+8.5282*Math.pow(10,-4)*o.item.condition.temp*Math.pow(o.atmosphere.humidity,2)-1.99*Math.pow(10,-6)*Math.pow(o.item.condition.temp,2)*Math.pow(o.atmosphere.humidity,2):o.item.condition.temp,"f"===t.unit?(r.unit="c",r.temp=Math.round(5/9*(o.item.condition.temp-32)),r.high=Math.round(5/9*(o.item.forecast[0].high-32)),r.low=Math.round(5/9*(o.item.forecast[0].low-32)),r.forecastOneHigh=Math.round(5/9*(o.item.forecast[1].high-32)),r.forecastOneLow=Math.round(5/9*(o.item.forecast[1].low-32)),r.forecastTwoHigh=Math.round(5/9*(o.item.forecast[2].high-32)),r.forecastTwoLow=Math.round(5/9*(o.item.forecast[2].low-32)),r.forecastThreeHigh=Math.round(5/9*(o.item.forecast[3].high-32)),r.forecastThreeLow=Math.round(5/9*(o.item.forecast[3].low-32)),r.forecastFourHigh=Math.round(5/9*(o.item.forecast[4].high-32)),r.forecastFourLow=Math.round(5/9*(o.item.forecast[4].low-32))):(r.unit="f",r.temp=Math.round(1.8*o.item.condition.temp+32),r.high=Math.round(1.8*o.item.forecast[0].high+32),r.low=Math.round(1.8*o.item.forecast[0].low+32),r.forecastOneHigh=Math.round(1.8*(o.item.forecast[1].high+32)),r.forecastOneLow=Math.round(1.8*(o.item.forecast[1].low+32)),r.forecastTwoHigh=Math.round(1.8*(o.item.forecast[2].high+32)),r.forecastTwoLow=Math.round(1.8*(o.item.forecast[2].low+32)),r.forecastThreeHigh=Math.round(1.8*(o.item.forecast[3].high+32)),r.forecastThreeLow=Math.round(1.8*(o.item.forecast[3].low+32)),r.forecastFourHigh=Math.round(1.8*(o.item.forecast[4].high+32)),r.forecastFourLow=Math.round(1.8*(o.item.forecast[4].low+32))),"3200"==o.item.condition.code?(a.thumbnail="//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png",a.image="//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"):(a.thumbnail="//l.yimg.com/a/i/us/nws/weather/gr/"+o.item.condition.code+"ds.png",a.image="//l.yimg.com/a/i/us/nws/weather/gr/"+o.item.condition.code+"d.png"),a.forecastOne="3200"==o.item.forecast[1].code?"//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png":"//l.yimg.com/a/i/us/nws/weather/gr/"+o.item.forecast[1].code+"d.png",a.forecastTwo="3200"==o.item.forecast[2].code?"//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png":"//l.yimg.com/a/i/us/nws/weather/gr/"+o.item.forecast[2].code+"d.png",a.forecastThree="3200"==o.item.forecast[3].code?"//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png":"//l.yimg.com/a/i/us/nws/weather/gr/"+o.item.forecast[3].code+"d.png",a.forecastFour="3200"==o.item.forecast[4].code?"//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png":"//l.yimg.com/a/i/us/nws/weather/gr/"+o.item.forecast[4].code+"d.png";var m={title:o.item.title,temp:o.item.condition.temp,tempAlt:r.temp,code:o.item.condition.code,todayCode:o.item.forecast[0].code,units:{temp:o.units.temperature,distance:o.units.distance,pressure:o.units.pressure,speed:o.units.speed,tempAlt:r.unit},currently:o.item.condition.text,high:o.item.forecast[0].high,highAlt:r.high,low:o.item.forecast[0].low,lowAlt:r.low,forecast:o.item.forecast[0].text,wind:{chill:o.wind.chill,direction:c,speed:o.wind.speed},humidity:o.atmosphere.humidity,heatindex:i,pressure:o.atmosphere.pressure,rising:o.atmosphere.rising,visibility:o.atmosphere.visibility,sunrise:o.astronomy.sunrise,sunset:o.astronomy.sunset,description:o.item.description,thumbnail:a.thumbnail,image:a.image,tomorrow:{high:o.item.forecast[1].high,highAlt:r.forecastOneHigh,low:o.item.forecast[1].low,lowAlt:r.forecastOneLow,forecast:o.item.forecast[1].text,code:o.item.forecast[1].code,date:o.item.forecast[1].date,day:o.item.forecast[1].day,image:a.forecastOne},forecasts:{one:{high:o.item.forecast[1].high,highAlt:r.forecastOneHigh,low:o.item.forecast[1].low,lowAlt:r.forecastOneLow,forecast:o.item.forecast[1].text,code:o.item.forecast[1].code,date:o.item.forecast[1].date,day:o.item.forecast[1].day,image:a.forecastOne},two:{high:o.item.forecast[2].high,highAlt:r.forecastTwoHigh,low:o.item.forecast[2].low,lowAlt:r.forecastTwoLow,forecast:o.item.forecast[2].text,code:o.item.forecast[2].code,date:o.item.forecast[2].date,day:o.item.forecast[2].day,image:a.forecastTwo},three:{high:o.item.forecast[3].high,highAlt:r.forecastThreeHigh,low:o.item.forecast[3].low,lowAlt:r.forecastThreeLow,forecast:o.item.forecast[3].text,code:o.item.forecast[3].code,date:o.item.forecast[3].date,day:o.item.forecast[3].day,image:a.forecastThree},four:{high:o.item.forecast[4].high,highAlt:r.forecastFourHigh,low:o.item.forecast[4].low,lowAlt:r.forecastFourLow,forecast:o.item.forecast[4].text,code:o.item.forecast[4].code,date:o.item.forecast[4].date,day:o.item.forecast[4].day,image:a.forecastFour}},city:o.location.city,country:o.location.country,region:o.location.region,updated:o.item.pubDate,link:o.item.link};t.success(m)}):t.error(null===o.query.results?"An invalid WOEID or location was provided.":"There was an error retrieving the latest weather information. Please try again.")}),this}})}(jQuery);