forked from monkeecreate/jquery.simpleWeather
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.simpleWeather-2.0.min.js
18 lines (17 loc) · 7.14 KB
/
jquery.simpleWeather-2.0.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
/*
* simpleWeather
*
* A simple jQuery plugin to display the weather information
* for a location. Weather is pulled from the public Yahoo!
* Weather feed via their api.
*
* Developed by James Fleeting <[email protected]>
* Another project from monkeeCreate <http://monkeecreate.com>
*
* Version 2.0 - Last updated: November 23 2011
*/
<<<<<<< HEAD:jquery.simpleWeather-1.9.min.js
(function(d){d.extend({simpleWeather:function(b){b=d.extend({zipcode:"76309",location:"",unit:"f",success:function(){},error:function(){}},b);now=new Date;var c="http://query.yahooapis.com/v1/public/yql?format=json&rnd="+now.getFullYear()+now.getMonth()+now.getDay()+now.getHours()+"&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=";if(""!=b.location)c+='select * from weather.forecast where location in (select id from weather.search where query="'+b.location+'") and u="'+b.unit+'"';else if(""!=b.zipcode)c+='select * from weather.forecast where location in ("'+b.zipcode+'") and u="'+b.unit+'"';else return b.error("No location given."),!1;d.getJSON(c,function(c){null!=c&&null!=c.query.results?d.each(c.query.results,function(c,a){-1!=a.constructor.toString().indexOf("Array")&&(a=a[0]);currentDate=new Date;sunRise=new Date(currentDate.toDateString()+" "+a.astronomy.sunrise);sunSet=new Date(currentDate.toDateString()+" "+a.astronomy.sunset);timeOfDay=currentDate>sunRise&¤tDate<sunSet?"d":"n";compass="N,NNE,NE,ENE,E,ESE,SE,SSE,S,SSW,SW,WSW,W,WNW,NW,NNW,N".split(",");windDirection=compass[Math.round(a.wind.direction/22.5)];heatIndex=80>a.item.condition.temp&&40>a.atmosphere.humidity?-42.379+2.04901523*a.item.condition.temp+10.14333127*a.atmosphere.humidity-0.22475541*a.item.condition.temp*a.atmosphere.humidity-6.83783*Math.pow(10,-3)*Math.pow(a.item.condition.temp,2)-5.481717*Math.pow(10,-2)*Math.pow(a.atmosphere.humidity,2)+1.22874*Math.pow(10,-3)*Math.pow(a.item.condition.temp,2)*a.atmosphere.humidity+8.5282*Math.pow(10,-4)*a.item.condition.temp*Math.pow(a.atmosphere.humidity,2)-1.99*Math.pow(10,-6)*Math.pow(a.item.condition.temp,2)*Math.pow(a.atmosphere.humidity,2):a.item.condition.temp;tempAlt="f"==b.unit?Math.round(5/9*(a.item.condition.temp-32)):Math.round(1.8*a.item.condition.temp+32);b.success({title:a.item.title,temp:a.item.condition.temp,tempAlt:tempAlt,code:a.item.condition.code,units:{temp:a.units.temperature,distance:a.units.distance,pressure:a.units.pressure,speed:a.units.speed},currently:a.item.condition.text,high:a.item.forecast[0].high,low:a.item.forecast[0].low,forecast:a.item.forecast[0].text,wind:{chill:a.wind.chill,direction:windDirection,speed:a.wind.speed},humidity:a.atmosphere.humidity,heatindex:heatIndex,pressure:a.atmosphere.pressure,rising:a.atmosphere.rising,visibility:a.atmosphere.visibility,sunrise:a.astronomy.sunrise,sunset:a.astronomy.sunset,description:a.item.description,thumbnail:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.condition.code+timeOfDay+"s.png",image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.condition.code+timeOfDay+".png",today:{high:a.item.forecast[0].high,low:a.item.forecast[0].low,forecast:a.item.forecast[0].text,code:a.item.forecast[0].code,date:a.item.forecast[0].date,day:a.item.forecast[0].day,image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.forecast[0].code+"d.png"},tomorrow:{high:a.item.forecast[1].high,low:a.item.forecast[1].low,forecast:a.item.forecast[1].text,code:a.item.forecast[1].code,date:a.item.forecast[1].date,day:a.item.forecast[1].day,image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.forecast[1].code+"d.png"},city:a.location.city,country:a.location.country,region:a.location.region,updated:a.item.pubDate,link:a.item.link})}):null==c.query.results?b.error("Invalid location given."):b.error("Weather could not be displayed. Try again.")});return this}})})(jQuery);
=======
(function($){$.extend({simpleWeather:function(d){var d=$.extend({zipcode:'76309',location:'',unit:'f',success:function(a){},error:function(a){}},d);now=new Date();var e='http://query.yahooapis.com/v1/public/yql?format=json&rnd='+now.getFullYear()+now.getMonth()+now.getDay()+now.getHours()+'&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=';if(d.location!='')e+='select * from weather.forecast where location in (select id from weather.search where query="'+d.location+'") and u="'+d.unit+'"';else if(d.zipcode!='')e+='select * from weather.forecast where location in ("'+d.zipcode+'") and u="'+d.unit+'"';else{d.error("No location given.");return false}$.getJSON(e,function(c){if(c!=null&&c.query.results!=null){$.each(c.query.results,function(i,a){if(a.constructor.toString().indexOf("Array")!=-1)a=a[0];currentDate=new Date();sunRise=new Date(currentDate.toDateString()+' '+a.astronomy.sunrise);sunSet=new Date(currentDate.toDateString()+' '+a.astronomy.sunset);if(currentDate>sunRise&¤tDate<sunSet)timeOfDay='d';else timeOfDay='n';compass=['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'];windDirection=compass[Math.round(a.wind.direction/22.5)];if(a.item.condition.temp<80&&a.atmosphere.humidity<40)heatIndex=-42.379+2.04901523*a.item.condition.temp+10.14333127*a.atmosphere.humidity-0.22475541*a.item.condition.temp*a.atmosphere.humidity-6.83783*(Math.pow(10,-3))*(Math.pow(a.item.condition.temp,2))-5.481717*(Math.pow(10,-2))*(Math.pow(a.atmosphere.humidity,2))+1.22874*(Math.pow(10,-3))*(Math.pow(a.item.condition.temp,2))*a.atmosphere.humidity+8.5282*(Math.pow(10,-4))*a.item.condition.temp*(Math.pow(a.atmosphere.humidity,2))-1.99*(Math.pow(10,-6))*(Math.pow(a.item.condition.temp,2))*(Math.pow(a.atmosphere.humidity,2));else heatIndex=a.item.condition.temp;if(d.unit=="f")tempAlt=Math.round((5.0/9.0)*(a.item.condition.temp-32.0));else tempAlt=Math.round((9.0/5.0)*a.item.condition.temp+32.0);var b={title:a.item.title,temp:a.item.condition.temp,tempAlt:tempAlt,code:a.item.condition.code,todayCode:a.item.forecast[0].code,units:{temp:a.units.temperature,distance:a.units.distance,pressure:a.units.pressure,speed:a.units.speed},currently:a.item.condition.text,high:a.item.forecast[0].high,low:a.item.forecast[0].low,forecast:a.item.forecast[0].text,wind:{chill:a.wind.chill,direction:windDirection,speed:a.wind.speed},humidity:a.atmosphere.humidity,heatindex:heatIndex,pressure:a.atmosphere.pressure,rising:a.atmosphere.rising,visibility:a.atmosphere.visibility,sunrise:a.astronomy.sunrise,sunset:a.astronomy.sunset,description:a.item.description,thumbnail:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.condition.code+timeOfDay+"s.png",image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.condition.code+timeOfDay+".png",tomorrow:{high:a.item.forecast[1].high,low:a.item.forecast[1].low,forecast:a.item.forecast[1].text,code:a.item.forecast[1].code,date:a.item.forecast[1].date,day:a.item.forecast[1].day,image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.forecast[1].code+"d.png"},city:a.location.city,country:a.location.country,region:a.location.region,updated:a.item.pubDate,link:a.item.link};d.success(b)})}else{if(c.query.results==null)d.error("Invalid location given.");else d.error("Weather could not be displayed. Try again.")}});return this}})})(jQuery);
>>>>>>> upstream/master:jquery.simpleWeather-2.0.min.js