Permalink
Browse files

js clean up, bumping version to 2.0.1

  • Loading branch information...
1 parent f5b28f8 commit e550019971b24de04415afbbf1e295b0523f9f19 @fleeting fleeting committed Jan 27, 2012
Showing with 48 additions and 43 deletions.
  1. +13 −0 jquery.simpleWeather-2.0.1.min.js
  2. +0 −14 jquery.simpleWeather-2.0.min.js
  3. +34 −28 jquery.simpleWeather.js
  4. +1 −1 package.json
@@ -0,0 +1,13 @@
+/*
+ * 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 <hello@jamesfleeting.com>
+ * Another project from monkeeCreate <http://monkeecreate.com>
+ *
+ * Version 2.0.1 - Last updated: January 26 2012
+ */
+(function($){"use strict";$.extend({simpleWeather:function(m){m=$.extend({zipcode:'76309',location:'',unit:'f',success:function(a){},error:function(a){}},m);var n=new Date();var o='http://query.yahooapis.com/v1/public/yql?format=json&rnd='+n.getFullYear()+n.getMonth()+n.getDay()+n.getHours()+'&diagnostics=true&callback=?&diagnostics=true&env=store%3A%2F%2Fdatatables.org%2Falltableswithkeys&q=';if(m.location!==''){o+='select * from weather.forecast where location in (select id from weather.search where query="'+m.location+'") and u="'+m.unit+'"'}else if(m.zipcode!==''){o+='select * from weather.forecast where location in ("'+m.zipcode+'") and u="'+m.unit+'"'}else{m.error("No location given.");return false}$.getJSON(o,function(l){if(l!==null&&l.query.results!==null){$.each(l.query.results,function(i,a){if(a.constructor.toString().indexOf("Array")!==-1){a=a[0]}var b=new Date();var c=new Date(b.toDateString()+' '+a.astronomy.sunrise);var d=new Date(b.toDateString()+' '+a.astronomy.sunset);if(b>c&&b<d){var e='d'}else{var e='n'}var f=['N','NNE','NE','ENE','E','ESE','SE','SSE','S','SSW','SW','WSW','W','WNW','NW','NNW','N'];var g=f[Math.round(a.wind.direction/22.5)];if(a.item.condition.temp<80&&a.atmosphere.humidity<40){var h=-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{var h=a.item.condition.temp}if(m.unit==="f"){var j=Math.round((5.0/9.0)*(a.item.condition.temp-32.0))}else{var j=Math.round((9.0/5.0)*a.item.condition.temp+32.0)}var k={title:a.item.title,temp:a.item.condition.temp,tempAlt:j,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:g,speed:a.wind.speed},humidity:a.atmosphere.humidity,heatindex:h,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+e+"s.png",image:"http://l.yimg.com/a/i/us/nws/weather/gr/"+a.item.condition.code+e+".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};m.success(k)})}else{if(l.query.results===null){m.error("Invalid location given.")}else{m.error("Weather could not be displayed. Try again.")}}});return this}})})(jQuery);
@@ -1,14 +0,0 @@
-/*
- * 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 <hello@jamesfleeting.com>
- * Another project from monkeeCreate <http://monkeecreate.com>
- *
- * Version 2.0 - Last updated: November 23 2011
- */
-
-(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&&currentDate<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);
@@ -8,60 +8,65 @@
* Developed by James Fleeting <hello@jamesfleeting.com>
* Another project from monkeeCreate <http://monkeecreate.com>
*
- * Version 2.0 - Last updated: November 23 2011
+ * Version 2.0.1 - Last updated: January 26 2012
*/
-
(function($) {
+ "use strict";
$.extend({
simpleWeather: function(options){
- var options = $.extend({
+ options = $.extend({
zipcode: '76309',
location: '',
unit: 'f',
success: function(weather){},
error: function(message){}
}, options);
- now = new Date(); //cachebust
+ var now = new Date();
var weatherUrl = '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(options.location != '')
+ if(options.location !== '') {
weatherUrl += 'select * from weather.forecast where location in (select id from weather.search where query="'+options.location+'") and u="'+options.unit+'"';
- else if(options.zipcode != '')
+ } else if(options.zipcode !== '') {
weatherUrl += 'select * from weather.forecast where location in ("'+options.zipcode+'") and u="'+options.unit+'"';
- else {
+ } else {
options.error("No location given.");
return false;
}
$.getJSON(
weatherUrl,
function(data) {
- if(data != null && data.query.results != null) {
+ if(data !== null && data.query.results !== null) {
$.each(data.query.results, function(i, result) {
- if (result.constructor.toString().indexOf("Array") != -1)
+ if (result.constructor.toString().indexOf("Array") !== -1) {
result = result[0];
+ }
- currentDate = new Date();
- sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise);
- sunSet = new Date(currentDate.toDateString() +' '+ result.astronomy.sunset);
- if(currentDate>sunRise && currentDate<sunSet)
- timeOfDay = 'd';
- else
- timeOfDay = 'n';
+ var currentDate = new Date();
+ var sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise);
+ var sunSet = new Date(currentDate.toDateString() +' '+ result.astronomy.sunset);
- compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];
- windDirection = compass[Math.round(result.wind.direction / 22.5)];
+ if(currentDate>sunRise && currentDate<sunSet) {
+ var timeOfDay = 'd';
+ } else {
+ var timeOfDay = 'n';
+ }
- if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40)
- heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
- else
- heatIndex = result.item.condition.temp;
+ var compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];
+ var windDirection = compass[Math.round(result.wind.direction / 22.5)];
- if(options.unit == "f")
- tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
- else
- tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
+ if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) {
+ var heatIndex = -42.379+2.04901523*result.item.condition.temp+10.14333127*result.atmosphere.humidity-0.22475541*result.item.condition.temp*result.atmosphere.humidity-6.83783*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))-5.481717*(Math.pow(10, -2))*(Math.pow(result.atmosphere.humidity, 2))+1.22874*(Math.pow(10, -3))*(Math.pow(result.item.condition.temp, 2))*result.atmosphere.humidity+8.5282*(Math.pow(10, -4))*result.item.condition.temp*(Math.pow(result.atmosphere.humidity, 2))-1.99*(Math.pow(10, -6))*(Math.pow(result.item.condition.temp, 2))*(Math.pow(result.atmosphere.humidity,2));
+ } else {
+ var heatIndex = result.item.condition.temp;
+ }
+
+ if(options.unit === "f") {
+ var tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0));
+ } else {
+ var tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0);
+ }
var weather = {
title: result.item.title,
@@ -113,10 +118,11 @@
options.success(weather);
});
} else {
- if (data.query.results == null)
+ if (data.query.results === null) {
options.error("Invalid location given.");
- else
+ } else {
options.error("Weather could not be displayed. Try again.");
+ }
}
}
);
View
@@ -1,6 +1,6 @@
{
"name": "simpleweather",
- "version": "2.0",
+ "version": "2.0.1",
"title": "simpleWeather",
"author": {
"name": "James Fleeting",

0 comments on commit e550019

Please sign in to comment.