├── .jshintrc ├── CHANGELOG.md ├── MIT-LICENSE.txt ├── README.md ├── bower.json ├── component.json ├── gulpfile.js ├── index.html ├── jquery.simpleWeather.js ├── jquery.simpleWeather.min.js ├── package.json └── simpleweather.jquery.json /.jshintrc: -------------------------------------------------------------------------------- 1 | {} 2 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # simpleWeather Changelog 2 | 3 | For a more complete changelog you can always check out the [commit log](https://github.com/monkeecreate/jquery.simpleWeather/commits/master). 4 | 5 | ## v3.1.0 - January 29 2016 6 | 7 | * Fixed location errors due to Yahoo removing geo.placefinder from their API. It has been replaced with geo.places. [#174](https://github.com/monkeecreate/jquery.simpleWeather/issues/174) 8 | * Fixed error callback to correctly return an error message. [#101](https://github.com/monkeecreate/jquery.simpleWeather/issues/101) 9 | 10 | ## v3.0.2 - June 2 2014 11 | 12 | * Fixed result issue when more than one location was returned. [#90](https://github.com/monkeecreate/jquery.simpleWeather/issues/90) 13 | 14 | ## v3.0.1 - May 22 2014 15 | 16 | * Fixed forecast thumbnail and image bug. [#88](https://github.com/monkeecreate/jquery.simpleWeather/issues/88) 17 | 18 | ## v3.0 - May 17 2014 19 | 20 | * Complete rewrite! Removed over 100 lines of code without losing functionality. 21 | * Now < 4.0 kB in size. 22 | * Added forecast thumbnail image. 23 | * Removed tomorrow in favor of forecast. 24 | * Fixed http/https issue on API call [#79](https://github.com/monkeecreate/jquery.simpleWeather/pull/79) and images. 25 | * Hat tip to [@defvayne23](https://github.com/defvayne23) for a quick code review. 26 | 27 | ## v2.7 - April 17 2014 28 | 29 | * Added gulp and a build/release process. 30 | * Fix for 3200 (not available) condition code and related image [#77](https://github.com/monkeecreate/jquery.simpleWeather/issues/77). 31 | * Fixed my assumption of query being present [#72](https://github.com/monkeecreate/jquery.simpleWeather/issues/72). Hat tip to [@rjackson](https://github.com/rjackson). 32 | * Some general code cleanup. 33 | 34 | ## v2.6 - February 26 2014 35 | 36 | * Encoding URI for API call. 37 | * Fixed formatting issues. 38 | * Fixed alt temps bug. 39 | * Hat tip to [@defvayne23](https://github.com/defvayne23) for the suggestions. 40 | 41 | ## v2.5 - February 5 2014 42 | 43 | * Removed deprecated weather.search YQL table. 44 | * Added geo.placefinder YQL table for searching locations. This allows you to get your location in a more forgiving format than before including latitude and longitude. 45 | * Removed `options.zipcode` as `options.location` now accepts any combination of city, state, and zipcode. 46 | * Removed `timeOfDay` as it was buggy and wouldn't return correctly anyways. Currently there is not a method to make this work accurately. See [#66](https://github.com/monkeecreate/jquery.simpleWeather/issues/66) for info. 47 | * Removed `http:` from api call and image source to allow for https. 48 | 49 | ## v2.4 - January 22 2014 50 | 51 | * Added four day forecast with recent Yahoo Weather API update. 52 | 53 | ## v2.3 - June 16 2013 54 | 55 | * Added `timeOfDay` for custom day/night icons. 56 | * Fix for new Yahoo API error result. 57 | 58 | ## v2.2 - April 20 2013 59 | 60 | * Added high and low alt temps. 61 | * Added alt temp unit. 62 | 63 | ## v2.1.2 - January 25 2013 64 | 65 | * Just a version bump for jQuery plugin directory. 66 | 67 | ## v2.1 - November 18 2012 68 | 69 | * Added WOEID location param for all. 70 | 71 | ## v2.0.1 - January 26 2012 72 | 73 | * Plenty of code cleanup but no additions, fixes, or deletions. 74 | 75 | ## v2.0 - November 23 2011 76 | 77 | * Added forecast condition code. 78 | 79 | ## v1.9 - October 3 2011 80 | 81 | * Added alt temp. 82 | 83 | ## v1.8 - May 15 2011 84 | 85 | * Fixed wind direction. 86 | * Added calculations for the heat index. 87 | 88 | ## v1.7 - May 8 2011 89 | 90 | * Added condition code. 91 | 92 | ## v1.6 - December 16 2010 93 | 94 | * Fixed `windDirection` bug. 95 | 96 | ## v1.5 - June 29 2010 97 | 98 | * Fixed errors in wind direction calculations. 99 | 100 | ## v1.4 - June 4 2010 101 | 102 | * Fixed issue of a location returning multiple results. 103 | 104 | ## v1.3 - May 26 2010 105 | 106 | * Fixed bug with trailing commas for IE. 107 | * Added `$.getJSON()` instead of `$.ajax()`. 108 | * Added better error message if the location is invalid. 109 | 110 | ## v1.2 - May 18 2010 111 | 112 | * Added location param for those outside the US. 113 | * Changed `thumbnail` to a hardcoded url. 114 | 115 | ## v1.1 - May 17 2010 116 | 117 | * Added `thumbnail` image. 118 | 119 | ## v1.0 - May 16 2010 120 | 121 | * Initial commit. 122 | -------------------------------------------------------------------------------- /MIT-LICENSE.txt: -------------------------------------------------------------------------------- 1 | Copyright (c) 2016 James Fleeting, http://jamesfleeting.com/ 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining 4 | a copy of this software and associated documentation files (the 5 | "Software"), to deal in the Software without restriction, including 6 | without limitation the rights to use, copy, modify, merge, publish, 7 | distribute, sublicense, and/or sell copies of the Software, and to 8 | permit persons to whom the Software is furnished to do so, subject to 9 | the following conditions: 10 | 11 | The above copyright notice and this permission notice shall be 12 | included in all copies or substantial portions of the Software. 13 | 14 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 15 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 16 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 17 | NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE 18 | LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 19 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 20 | WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 21 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # simpleWeather - jQuery Plugin [![GitHub version](https://badge.fury.io/gh/monkeecreate%2Fjquery.simpleWeather.svg)](https://badge.fury.io/gh/monkeecreate%2Fjquery.simpleWeather) 2 | 3 | A simple jQuery plugin to display current weather data for any location and doesn't get in your way. Now supports HTML5 GeoLocation! Handcrafted with ♥ from Austin, TX by [James Fleeting](http://twitter.com/fleetingftw). You can find demos and docs at [simpleweatherjs.com](https://monkeecreate.github.io/jquery.simpleWeather/). 4 | 5 | ## Get The Latest 6 | **[Bower](http://bower.io/)** 7 | ```shell 8 | bower install simpleWeather 9 | ``` 10 | 11 | **[Component(1)](http://component.io/)** 12 | ```shell 13 | component install monkeecreate/jquery.simpleWeather 14 | ``` 15 | 16 | **[CDNJS](http://cdnjs.com/libraries/jquery.simpleWeather/)** 17 | ```html 18 | 19 | ``` 20 | 21 | **Git** 22 | ```shell 23 | git clone git://github.com/monkeecreate/jquery.simpleWeather.git 24 | ``` 25 | 26 | **Zip File** 27 | > Download the latest version at [simpleweatherjs.com](https://monkeecreate.github.io/jquery.simpleWeather/) 28 | 29 | ## Alternatives 30 | 31 | * [SimplerWeather](https://github.com/BrookeDot/SimplerWeather) uses the DarkSky API and includes a php proxy to help keep your API key secret. 32 | 33 | ## Questions? 34 | If you have any questions or problems hit me up on [twitter](http://twitter.com/fleetingftw) or create a [new issue](https://github.com/monkeecreate/jquery.simpleWeather/issues/new). Don't forget to check the documentation and FAQ at [simpleweatherjs.com](https://monkeecreate.github.io/jquery.simpleWeather/). 35 | -------------------------------------------------------------------------------- /bower.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simpleWeather", 3 | "description": "A simple jQuery plugin to display current weather data for any location and doesn't get in your way. Handcrafted with ♥ from Boston, MA by James Fleeting.", 4 | "main": "jquery.simpleWeather.js", 5 | "version": "3.1.0", 6 | "homepage": "http://simpleweatherjs.com", 7 | "authors": [ 8 | "James Fleeting " 9 | ], 10 | "license": "MIT", 11 | "dependencies": { 12 | "jquery": ">= 1.2.0" 13 | }, 14 | "ignore": [ 15 | "**/.*", 16 | "node_modules", 17 | "bower_components", 18 | "test", 19 | "tests" 20 | ], 21 | "keywords": [ 22 | "jquery", 23 | "javascript", 24 | "weather", 25 | "plugin", 26 | "simple" 27 | ] 28 | } 29 | -------------------------------------------------------------------------------- /component.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simpleWeather", 3 | "repo": "monkeecreate/jquery.simpleWeather", 4 | "description": "A simple jQuery plugin to display current weather data for any location and doesn't get in your way. Handcrafted with ♥ from Boston, MA by James Fleeting.", 5 | "version": "3.1.0", 6 | "main": "jquery.simpleWeather.js", 7 | "scripts": [ 8 | "jquery.simpleWeather.js" 9 | ], 10 | "dependencies": { 11 | "components/jquery": "*" 12 | }, 13 | "author": "James Fleeting", 14 | "keywords": [ 15 | "jquery", 16 | "javascript", 17 | "weather", 18 | "plugin", 19 | "simple", 20 | "monkeecreate" 21 | ], 22 | "license": "MIT", 23 | "demo": "http://simpleweatherjs.com" 24 | } 25 | -------------------------------------------------------------------------------- /gulpfile.js: -------------------------------------------------------------------------------- 1 | var gulp = require('gulp'), 2 | uglify = require('gulp-uglify'), 3 | jshint = require('gulp-jshint'), 4 | rename = require('gulp-rename'), 5 | bump = require('gulp-bump'), 6 | notify = require('gulp-notify'), 7 | git = require('gulp-git'), 8 | size = require('gulp-size'), 9 | pkg = require('./package.json'); 10 | 11 | var source = "jquery.simpleWeather.js", 12 | sourceMin = "jquery.simpleWeather.min.js"; 13 | 14 | gulp.task('lint', function () { 15 | return gulp.src(source) 16 | .pipe(jshint('.jshintrc')) 17 | .pipe(jshint.reporter('jshint-stylish')); 18 | }); 19 | 20 | gulp.task('build', ['lint'], function () { 21 | return gulp.src(source) 22 | .pipe(rename(sourceMin)) 23 | .pipe(uglify({preserveComments: 'some'})) 24 | .pipe(size()) 25 | .pipe(gulp.dest('./')); 26 | }); 27 | 28 | gulp.task('bump', function () { 29 | return gulp.src(['./bower.json', './component.json', 'simpleweather.jquery.json']) 30 | .pipe(bump({version: pkg.version})) 31 | .pipe(gulp.dest('./')); 32 | }); 33 | 34 | gulp.task('tag', ['bump'], function () { 35 | return gulp.src('./') 36 | .pipe(git.commit('Version '+pkg.version)) 37 | .pipe(git.tag(pkg.version, 'Version '+pkg.version)) 38 | .pipe(git.push('monkee', 'master', '--tags')) 39 | .pipe(gulp.dest('./')); 40 | }); 41 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | simpleWeather - a simple jQuery plugin 18 | 19 | 20 | 52 | 53 | 54 | 55 | 56 |
57 |
58 |

Whoa, a weather plugin?

59 |

A simple jQuery plugin to display current weather data for any location and doesn't get in your way. Developed by James Fleeting. Download the latest version, read the docs or browse the FAQ at simpleweather.js.

60 |
61 |
62 | 63 |
64 |
65 |

Usage/Demo

66 | 67 |

See the Pen simpleWeather.demo.js by James Fleeting (@fleeting) on CodePen.

68 | 69 |
70 |
71 |
72 |
73 | 74 | 75 | 76 | 77 | 78 | -------------------------------------------------------------------------------- /jquery.simpleWeather.js: -------------------------------------------------------------------------------- 1 | /*! simpleWeather v3.1.0 - http://simpleweatherjs.com */ 2 | (function($) { 3 | 'use strict'; 4 | 5 | function getAltTemp(unit, temp) { 6 | if(unit === 'f') { 7 | return Math.round((5.0/9.0)*(temp-32.0)); 8 | } else { 9 | return Math.round((9.0/5.0)*temp+32.0); 10 | } 11 | } 12 | 13 | $.extend({ 14 | simpleWeather: function(options){ 15 | options = $.extend({ 16 | location: '', 17 | woeid: '', 18 | unit: 'f', 19 | success: function(weather){}, 20 | error: function(message){} 21 | }, options); 22 | 23 | var now = new Date(); 24 | var weatherUrl = 'https://query.yahooapis.com/v1/public/yql?format=json&rnd=' + now.getFullYear() + now.getMonth() + now.getDay() + now.getHours() + '&diagnostics=true&callback=?&q='; 25 | 26 | if(options.location !== '') { 27 | /* If latitude/longitude coordinates, need to format a little different. */ 28 | var location = ''; 29 | if(/^(\-?\d+(\.\d+)?),\s*(\-?\d+(\.\d+)?)$/.test(options.location)) { 30 | location = '(' + options.location + ')'; 31 | } else { 32 | location = options.location; 33 | } 34 | 35 | weatherUrl += 'select * from weather.forecast where woeid in (select woeid from geo.places(1) where text="' + location + '") and u="' + options.unit + '"'; 36 | } else if(options.woeid !== '') { 37 | weatherUrl += 'select * from weather.forecast where woeid=' + options.woeid + ' and u="' + options.unit + '"'; 38 | } else { 39 | options.error('Could not retrieve weather due to an invalid location.'); 40 | return false; 41 | } 42 | 43 | $.getJSON( 44 | encodeURI(weatherUrl), 45 | function(data) { 46 | if(data !== null && data.query !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') { 47 | var result = data.query.results.channel, 48 | weather = {}, 49 | forecast, 50 | compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N'], 51 | image404 = 'https://s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png'; 52 | 53 | weather.title = result.item.title; 54 | weather.temp = result.item.condition.temp; 55 | weather.code = result.item.condition.code; 56 | weather.todayCode = result.item.forecast[0].code; 57 | weather.currently = result.item.condition.text; 58 | weather.high = result.item.forecast[0].high; 59 | weather.low = result.item.forecast[0].low; 60 | weather.text = result.item.forecast[0].text; 61 | weather.humidity = result.atmosphere.humidity; 62 | weather.pressure = result.atmosphere.pressure; 63 | weather.rising = result.atmosphere.rising; 64 | weather.visibility = result.atmosphere.visibility; 65 | weather.sunrise = result.astronomy.sunrise; 66 | weather.sunset = result.astronomy.sunset; 67 | weather.description = result.item.description; 68 | weather.city = result.location.city; 69 | weather.country = result.location.country; 70 | weather.region = result.location.region; 71 | weather.updated = result.item.pubDate; 72 | weather.link = result.item.link; 73 | weather.units = {temp: result.units.temperature, distance: result.units.distance, pressure: result.units.pressure, speed: result.units.speed}; 74 | weather.wind = {chill: result.wind.chill, direction: compass[Math.round(result.wind.direction / 22.5)], speed: result.wind.speed}; 75 | 76 | if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) { 77 | weather.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)); 78 | } else { 79 | weather.heatindex = result.item.condition.temp; 80 | } 81 | 82 | if(result.item.condition.code == '3200') { 83 | weather.thumbnail = image404; 84 | weather.image = image404; 85 | } else { 86 | weather.thumbnail = 'https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/' + result.item.condition.code + 'ds.png'; 87 | weather.image = 'https://s.yimg.com/zz/combo?a/i/us/nws/weather/gr/' + result.item.condition.code + 'd.png'; 88 | } 89 | 90 | weather.alt = {temp: getAltTemp(options.unit, result.item.condition.temp), high: getAltTemp(options.unit, result.item.forecast[0].high), low: getAltTemp(options.unit, result.item.forecast[0].low)}; 91 | if(options.unit === 'f') { 92 | weather.alt.unit = 'c'; 93 | } else { 94 | weather.alt.unit = 'f'; 95 | } 96 | 97 | weather.forecast = []; 98 | for(var i=0;i=0.8.0", 26 | "npm": ">=1.2.10" 27 | }, 28 | "licenses": [ 29 | { 30 | "type": "MIT" 31 | } 32 | ], 33 | "devDependencies": { 34 | "gulp": "latest", 35 | "gulp-bump": "latest", 36 | "gulp-git": "^1.7.0", 37 | "gulp-jshint": "latest", 38 | "gulp-notify": "latest", 39 | "gulp-rename": "latest", 40 | "gulp-size": "latest", 41 | "gulp-uglify": "latest", 42 | "jshint-stylish": "latest" 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /simpleweather.jquery.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "simpleweather", 3 | "title": "jQuery.simpleWeather", 4 | "description": "A simple jQuery plugin to display current weather data for any location and doesn't get in your way. Handcrafted with ♥ from Boston, MA by James Fleeting.", 5 | "keywords": [ 6 | "weather", 7 | "yahoo", 8 | "simpleweather", 9 | "simple", 10 | "monkeecreate", 11 | "weather-data" 12 | ], 13 | "version": "3.1.0", 14 | "author": { 15 | "name": "James Fleeting", 16 | "email": "hello@jamesfleeting.com", 17 | "url": "http://jamesfleeting.com" 18 | }, 19 | "licenses": [ 20 | { 21 | "type": "MIT", 22 | "url": "https://github.com/monkeecreate/jquery.simpleWeather/blob/master/MIT-LICENSE.txt" 23 | } 24 | ], 25 | "bugs": "https://github.com/monkeecreate/jquery.simpleWeather/issues", 26 | "homepage": "http://simpleweatherjs.com", 27 | "docs": "http://simpleweatherjs.com", 28 | "download": "http://simpleweatherjs.com", 29 | "demo": "http://simpleweatherjs.com", 30 | "dependencies": { 31 | "jquery": ">=1.2" 32 | }, 33 | "maintainers": [ 34 | { 35 | "name": "James Fleeting", 36 | "email": "hello@jamesfleeting.com", 37 | "url": "http://jamesfleeting.com" 38 | } 39 | ] 40 | } 41 | --------------------------------------------------------------------------------