/* * 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 * Another project from monkeeCreate * * Version 2.0.1 - Last updated: January 26 2012 */ (function($) { "use strict"; $.extend({ simpleWeather: function(options){ options = $.extend({ zipcode: '', location: '', unit: 'f', success: function(weather){}, error: function(message){} }, options); 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 !== '') { 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 !== '') { weatherUrl += 'select * from weather.forecast where location in ("'+options.zipcode+'") and u="'+options.unit+'"'; } else { options.error("No location given."); return false; } $.getJSON( weatherUrl, function(data) { if(data !== null && data.query.results !== null) { $.each(data.query.results, function(i, result) { if (result.constructor.toString().indexOf("Array") !== -1) { result = result[0]; } var currentDate = new Date(); var sunRise = new Date(currentDate.toDateString() +' '+ result.astronomy.sunrise); var sunSet = new Date(currentDate.toDateString() +' '+ result.astronomy.sunset); if(currentDate>sunRise && currentDate