Skip to content
This repository has been archived by the owner on Jan 23, 2019. It is now read-only.

Commit

Permalink
js clean up, bumping version to 2.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
fleeting committed Jan 27, 2012
1 parent f5b28f8 commit e550019
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 43 deletions.
13 changes: 13 additions & 0 deletions jquery.simpleWeather-2.0.1.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 0 additions & 14 deletions jquery.simpleWeather-2.0.min.js

This file was deleted.

62 changes: 34 additions & 28 deletions jquery.simpleWeather.js
Expand Up @@ -8,60 +8,65 @@
* Developed by James Fleeting <hello@jamesfleeting.com> * Developed by James Fleeting <hello@jamesfleeting.com>
* Another project from monkeeCreate <http://monkeecreate.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($) { (function($) {
"use strict";
$.extend({ $.extend({
simpleWeather: function(options){ simpleWeather: function(options){
var options = $.extend({ options = $.extend({
zipcode: '76309', zipcode: '76309',
location: '', location: '',
unit: 'f', unit: 'f',
success: function(weather){}, success: function(weather){},
error: function(message){} error: function(message){}
}, options); }, 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='; 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+'"'; 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+'"'; weatherUrl += 'select * from weather.forecast where location in ("'+options.zipcode+'") and u="'+options.unit+'"';
else { } else {
options.error("No location given."); options.error("No location given.");
return false; return false;
} }


$.getJSON( $.getJSON(
weatherUrl, weatherUrl,
function(data) { function(data) {
if(data != null && data.query.results != null) { if(data !== null && data.query.results !== null) {
$.each(data.query.results, function(i, result) { $.each(data.query.results, function(i, result) {
if (result.constructor.toString().indexOf("Array") != -1) if (result.constructor.toString().indexOf("Array") !== -1) {
result = result[0]; result = result[0];
}


currentDate = new Date(); var currentDate = new Date();
sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise); var sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise);
sunSet = new Date(currentDate.toDateString() +' '+ result.astronomy.sunset); var sunSet = new Date(currentDate.toDateString() +' '+ result.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']; if(currentDate>sunRise && currentDate<sunSet) {
windDirection = compass[Math.round(result.wind.direction / 22.5)]; var timeOfDay = 'd';
} else {
var timeOfDay = 'n';
}


if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) var compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'];
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)); var windDirection = compass[Math.round(result.wind.direction / 22.5)];
else
heatIndex = result.item.condition.temp;


if(options.unit == "f") if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) {
tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0)); 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 } else {
tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0); 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 = { var weather = {
title: result.item.title, title: result.item.title,
Expand Down Expand Up @@ -113,10 +118,11 @@
options.success(weather); options.success(weather);
}); });
} else { } else {
if (data.query.results == null) if (data.query.results === null) {
options.error("Invalid location given."); options.error("Invalid location given.");
else } else {
options.error("Weather could not be displayed. Try again."); options.error("Weather could not be displayed. Try again.");
}
} }
} }
); );
Expand Down
2 changes: 1 addition & 1 deletion package.json
@@ -1,6 +1,6 @@
{ {
"name": "simpleweather", "name": "simpleweather",
"version": "2.0", "version": "2.0.1",
"title": "simpleWeather", "title": "simpleWeather",
"author": { "author": {
"name": "James Fleeting", "name": "James Fleeting",
Expand Down

0 comments on commit e550019

Please sign in to comment.