From 6b002f0c5c4c4be709957f040c0b33926cb6b0b8 Mon Sep 17 00:00:00 2001 From: James Fleeting Date: Sun, 18 Nov 2012 15:00:57 -0600 Subject: [PATCH] Added WOEID to simpleWeather, version now 2.1.0, and updated included demo. --- index.html | 181 +++++++++++++++++++----------- jquery.simpleWeather-2.0.1.min.js | 13 --- jquery.simpleWeather-2.1.min.js | 13 +++ jquery.simpleWeather.js | 47 ++++---- package.json | 8 +- 5 files changed, 155 insertions(+), 107 deletions(-) delete mode 100644 jquery.simpleWeather-2.0.1.min.js create mode 100644 jquery.simpleWeather-2.1.min.js diff --git a/index.html b/index.html index 3367b1f..0e6a88b 100644 --- a/index.html +++ b/index.html @@ -1,59 +1,128 @@ - - - - - - simpleWeather | jQuery Yahoo! Weather - + + + + + + + + + + + + + + + + + + simpleWeather - a simple jQuery plugin + + - - - - + + + +
+
+

Whoa, a weather plugin?

+

A simple jQuery plugin to display the current weather information for any location using Yahoo! Weather. Developed by James Fleeting. Download the latest version, read the docs or browse the FAQ at simpleweather.monkeecreate.com. Below you will find three examples of using simpleWeather.js.

+
+
+ +
+
+

Usage

+ +

Simply include jquery.simpleWeather.js in your site.

+ + + +

Then initialize simpleWeather, set your WOEID, US zip code or location, add a div with an ID of `weather` (or whatever you want, just change it in the init), and you are good to go.

+ + +
+
+
+ +
+
+

Simple Demo

+ +

This demo shows the common use for simpleWeather, displaying the current weather for a location, in this case Austin, Texas US. This is a bare demo with minimal styling.

+ + +
+
+
+ +
+
+

Fancy Demo

+ +

This demo is still extremely simple, just shows what you can do with a little CSS to spice it up.

+ + + +
+
+
+ +
+
+

Demo(ish)

+ +

This is not really a demo, instead it shows you all the data that simpleWeather returns and how to use it. I wouldn't just copy and paste this, think of it as a reference.

+ +
+
+
+
+ + + + + - - -

simpleWeather | jQuery Plugin

-

A simple jQuery plugin to display the weather information for any location. The data is pulled from the public Yahoo! Weather feed via the YQL API. Below you will find 2 basic usage examples. You can download the plugin from jQuery Plugins or get the full source from GitHub. For more information including docs, faq and usage visit http://simpleweather.monkeecreate.com.

- -
-

 

-
\ No newline at end of file diff --git a/jquery.simpleWeather-2.0.1.min.js b/jquery.simpleWeather-2.0.1.min.js deleted file mode 100644 index e82eaa8..0000000 --- a/jquery.simpleWeather-2.0.1.min.js +++ /dev/null @@ -1,13 +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 - * Another project from monkeeCreate - * - * 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 + * Another project from monkeeCreate + * + * Version 2.1 - Last updated: November 17 2012 + */ +(function($){"use strict";$.extend({simpleWeather:function(m){m=$.extend({zipcode:'',woeid:'2357536',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 if(m.woeid!==''){o+='select * from weather.forecast where woeid='+m.woeid+' and u="'+m.unit+'"'}else{m.error("No location given. Please provide either a US zip code, WOEID or location.");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 + * A simple jQuery plugin to display the current weather + * information for any location using Yahoo! Weather. + * + * Developed by James Fleeting <@twofivethreetwo> * Another project from monkeeCreate * - * Version 2.0.1 - Last updated: January 26 2012 + * Version 2.1 - Last updated: November 17 2012 */ (function($) { "use strict"; $.extend({ simpleWeather: function(options){ options = $.extend({ - zipcode: '76309', + zipcode: '', + woeid: '2357536', 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 if(options.woeid !== '') { + weatherUrl += 'select * from weather.forecast where woeid='+options.woeid+' and u="'+options.unit+'"'; } else { - options.error("No location given."); + options.error("No location given. Please provide either a US zip code, WOEID or location."); return false; } - + $.getJSON( weatherUrl, function(data) { @@ -42,33 +45,33 @@ 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 && currentDate1.5" }, - "description": "A simple jQuery plugin to display the weather information for any location. The data is pulled from the public Yahoo! Weather feed via the YQL API.", + "description": "A simple jQuery plugin to display the current weather information for any location using Yahoo! Weather. Developed by James Fleeting.", "keywords": [ "weather", "yahoo",