|
8 | 8 | * Developed by James Fleeting <@fleetingftw> <http://iwasasuperhero.com> |
9 | 9 | * Another project from monkeeCreate <http://monkeecreate.com> |
10 | 10 | * |
11 | | - * Version 2.6.0 - Last updated: February 26 2014 |
| 11 | + * Version 2.7.0 - Last updated: April 17 2014 |
12 | 12 | */ |
13 | 13 | (function($) { |
14 | 14 | "use strict"; |
|
23 | 23 | }, options); |
24 | 24 |
|
25 | 25 | var now = new Date(); |
26 | | - |
27 | 26 | var weatherUrl = '//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='; |
28 | 27 | if(options.location !== '') { |
29 | 28 | weatherUrl += 'select * from weather.forecast where woeid in (select woeid from geo.placefinder where text="'+options.location+'" and gflags="R") and u="'+options.unit+'"'; |
|
37 | 36 | $.getJSON( |
38 | 37 | encodeURI(weatherUrl), |
39 | 38 | function(data) { |
40 | | - if(data !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') { |
| 39 | + if(data !== null && data.query !== null && data.query.results !== null && data.query.results.channel.description !== 'Yahoo! Weather Error') { |
41 | 40 | $.each(data.query.results, function(i, result) { |
42 | 41 | if (result.constructor.toString().indexOf("Array") !== -1) { |
43 | 42 | result = result[0]; |
44 | 43 | } |
45 | 44 |
|
| 45 | + var altTemps = [], heatIndex, images = []; |
46 | 46 | var compass = ['N', 'NNE', 'NE', 'ENE', 'E', 'ESE', 'SE', 'SSE', 'S', 'SSW', 'SW', 'WSW', 'W', 'WNW', 'NW', 'NNW', 'N']; |
47 | 47 | var windDirection = compass[Math.round(result.wind.direction / 22.5)]; |
48 | 48 |
|
49 | 49 | if(result.item.condition.temp < 80 && result.atmosphere.humidity < 40) { |
50 | | - 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)); |
| 50 | + 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)); |
51 | 51 | } else { |
52 | | - var heatIndex = result.item.condition.temp; |
| 52 | + heatIndex = result.item.condition.temp; |
53 | 53 | } |
54 | 54 |
|
55 | 55 | if(options.unit === "f") { |
56 | | - var unitAlt = "c"; |
57 | | - var tempAlt = Math.round((5.0/9.0)*(result.item.condition.temp-32.0)); |
58 | | - var highAlt = Math.round((5.0/9.0)*(result.item.forecast[0].high-32.0)); |
59 | | - var lowAlt = Math.round((5.0/9.0)*(result.item.forecast[0].low-32.0)); |
60 | | - var tomorrowHighAlt = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0)); |
61 | | - var tomorrowLowAlt = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0)); |
62 | | - var forecastOneHighAlt = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0)); |
63 | | - var forecastOneLowAlt = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0)); |
64 | | - var forecastTwoHighAlt = Math.round((5.0/9.0)*(result.item.forecast[2].high-32.0)); |
65 | | - var forecastTwoLowAlt = Math.round((5.0/9.0)*(result.item.forecast[2].low-32.0)); |
66 | | - var forecastThreeHighAlt = Math.round((5.0/9.0)*(result.item.forecast[3].high-32.0)); |
67 | | - var forecastThreeLowAlt = Math.round((5.0/9.0)*(result.item.forecast[3].low-32.0)); |
68 | | - var forecastFourHighAlt = Math.round((5.0/9.0)*(result.item.forecast[4].high-32.0)); |
69 | | - var forecastFourLowAlt = Math.round((5.0/9.0)*(result.item.forecast[4].low-32.0)); |
| 56 | + altTemps.unit = "c"; |
| 57 | + altTemps.temp = Math.round((5.0/9.0)*(result.item.condition.temp-32.0)); |
| 58 | + altTemps.high = Math.round((5.0/9.0)*(result.item.forecast[0].high-32.0)); |
| 59 | + altTemps.low = Math.round((5.0/9.0)*(result.item.forecast[0].low-32.0)); |
| 60 | + altTemps.forecastOneHigh = Math.round((5.0/9.0)*(result.item.forecast[1].high-32.0)); |
| 61 | + altTemps.forecastOneLow = Math.round((5.0/9.0)*(result.item.forecast[1].low-32.0)); |
| 62 | + altTemps.forecastTwoHigh = Math.round((5.0/9.0)*(result.item.forecast[2].high-32.0)); |
| 63 | + altTemps.forecastTwoLow = Math.round((5.0/9.0)*(result.item.forecast[2].low-32.0)); |
| 64 | + altTemps.forecastThreeHigh = Math.round((5.0/9.0)*(result.item.forecast[3].high-32.0)); |
| 65 | + altTemps.forecastThreeLow = Math.round((5.0/9.0)*(result.item.forecast[3].low-32.0)); |
| 66 | + altTemps.forecastFourHigh = Math.round((5.0/9.0)*(result.item.forecast[4].high-32.0)); |
| 67 | + altTemps.forecastFourLow = Math.round((5.0/9.0)*(result.item.forecast[4].low-32.0)); |
| 68 | + } else { |
| 69 | + altTemps.unit = "f"; |
| 70 | + altTemps.temp = Math.round((9.0/5.0)*result.item.condition.temp+32.0); |
| 71 | + altTemps.high = Math.round((9.0/5.0)*result.item.forecast[0].high+32.0); |
| 72 | + altTemps.low = Math.round((9.0/5.0)*result.item.forecast[0].low+32.0); |
| 73 | + altTemps.forecastOneHigh = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0)); |
| 74 | + altTemps.forecastOneLow = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0)); |
| 75 | + altTemps.forecastTwoHigh = Math.round((9.0/5.0)*(result.item.forecast[2].high+32.0)); |
| 76 | + altTemps.forecastTwoLow = Math.round((9.0/5.0)*(result.item.forecast[2].low+32.0)); |
| 77 | + altTemps.forecastThreeHigh = Math.round((9.0/5.0)*(result.item.forecast[3].high+32.0)); |
| 78 | + altTemps.forecastThreeLow = Math.round((9.0/5.0)*(result.item.forecast[3].low+32.0)); |
| 79 | + altTemps.forecastFourHigh = Math.round((9.0/5.0)*(result.item.forecast[4].high+32.0)); |
| 80 | + altTemps.forecastFourLow = Math.round((9.0/5.0)*(result.item.forecast[4].low+32.0)); |
| 81 | + } |
| 82 | + |
| 83 | + if(result.item.condition.code == "3200") { |
| 84 | + images.thumbnail = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"; |
| 85 | + images.image = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"; |
70 | 86 | } else { |
71 | | - var unitAlt = "f"; |
72 | | - var tempAlt = Math.round((9.0/5.0)*result.item.condition.temp+32.0); |
73 | | - var highAlt = Math.round((9.0/5.0)*result.item.forecast[0].high+32.0); |
74 | | - var lowAlt = Math.round((9.0/5.0)*result.item.forecast[0].low+32.0); |
75 | | - var tomorrowHighAlt = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0)); |
76 | | - var tomorrowLowAlt = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0)); |
77 | | - var forecastOneHighAlt = Math.round((9.0/5.0)*(result.item.forecast[1].high+32.0)); |
78 | | - var forecastOneLowAlt = Math.round((9.0/5.0)*(result.item.forecast[1].low+32.0)); |
79 | | - var forecastTwoHighAlt = Math.round((9.0/5.0)*(result.item.forecast[2].high+32.0)); |
80 | | - var forecastTwoLowAlt = Math.round((9.0/5.0)*(result.item.forecast[2].low+32.0)); |
81 | | - var forecastThreeHighAlt = Math.round((9.0/5.0)*(result.item.forecast[3].high+32.0)); |
82 | | - var forecastThreeLowAlt = Math.round((9.0/5.0)*(result.item.forecast[3].low+32.0)); |
83 | | - var forecastFourHighAlt = Math.round((9.0/5.0)*(result.item.forecast[4].high+32.0)); |
84 | | - var forecastFourLowAlt = Math.round((9.0/5.0)*(result.item.forecast[4].low+32.0)); |
| 87 | + images.thumbnail = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"ds.png"; |
| 88 | + images.image = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"d.png"; |
85 | 89 | } |
86 | 90 |
|
| 91 | + if(result.item.forecast[1].code == "3200") |
| 92 | + images.forecastOne = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"; |
| 93 | + else |
| 94 | + images.forecastOne = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png"; |
| 95 | + |
| 96 | + if(result.item.forecast[2].code == "3200") |
| 97 | + images.forecastTwo = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"; |
| 98 | + else |
| 99 | + images.forecastTwo = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[2].code+"d.png"; |
| 100 | + |
| 101 | + if(result.item.forecast[3].code == "3200") |
| 102 | + images.forecastThree = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"; |
| 103 | + else |
| 104 | + images.forecastThree = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[3].code+"d.png"; |
| 105 | + |
| 106 | + if(result.item.forecast[4].code == "3200") |
| 107 | + images.forecastFour = "//s.yimg.com/os/mit/media/m/weather/images/icons/l/44d-100567.png"; |
| 108 | + else |
| 109 | + images.forecastFour = "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[4].code+"d.png"; |
| 110 | + |
87 | 111 | var weather = { |
88 | 112 | title: result.item.title, |
89 | 113 | temp: result.item.condition.temp, |
90 | | - tempAlt: tempAlt, |
| 114 | + tempAlt: altTemps.temp, |
91 | 115 | code: result.item.condition.code, |
92 | 116 | todayCode: result.item.forecast[0].code, |
93 | 117 | units:{ |
94 | 118 | temp: result.units.temperature, |
95 | 119 | distance: result.units.distance, |
96 | 120 | pressure: result.units.pressure, |
97 | 121 | speed: result.units.speed, |
98 | | - tempAlt: unitAlt |
| 122 | + tempAlt: altTemps.unit |
99 | 123 | }, |
100 | 124 | currently: result.item.condition.text, |
101 | 125 | high: result.item.forecast[0].high, |
102 | | - highAlt: highAlt, |
| 126 | + highAlt: altTemps.high, |
103 | 127 | low: result.item.forecast[0].low, |
104 | | - lowAlt: lowAlt, |
| 128 | + lowAlt: altTemps.low, |
105 | 129 | forecast: result.item.forecast[0].text, |
106 | 130 | wind:{ |
107 | 131 | chill: result.wind.chill, |
|
116 | 140 | sunrise: result.astronomy.sunrise, |
117 | 141 | sunset: result.astronomy.sunset, |
118 | 142 | description: result.item.description, |
119 | | - thumbnail: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"ds.png", |
120 | | - image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.condition.code+"d.png", |
| 143 | + thumbnail: images.thumbnail, |
| 144 | + image: images.image, |
121 | 145 | tomorrow:{ |
122 | 146 | high: result.item.forecast[1].high, |
123 | | - highAlt: tomorrowHighAlt, |
| 147 | + highAlt: altTemps.forecastOneHigh, |
124 | 148 | low: result.item.forecast[1].low, |
125 | | - lowAlt: tomorrowLowAlt, |
| 149 | + lowAlt: altTemps.forecastOneLow, |
126 | 150 | forecast: result.item.forecast[1].text, |
127 | 151 | code: result.item.forecast[1].code, |
128 | 152 | date: result.item.forecast[1].date, |
129 | 153 | day: result.item.forecast[1].day, |
130 | | - image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png" |
| 154 | + image: images.forecastOne |
131 | 155 | }, |
132 | 156 | forecasts:{ |
133 | 157 | one:{ |
134 | 158 | high: result.item.forecast[1].high, |
135 | | - highAlt: forecastOneHighAlt, |
| 159 | + highAlt: altTemps.forecastOneHigh, |
136 | 160 | low: result.item.forecast[1].low, |
137 | | - lowAlt: forecastOneLowAlt, |
| 161 | + lowAlt: altTemps.forecastOneLow, |
138 | 162 | forecast: result.item.forecast[1].text, |
139 | 163 | code: result.item.forecast[1].code, |
140 | 164 | date: result.item.forecast[1].date, |
141 | 165 | day: result.item.forecast[1].day, |
142 | | - image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[1].code+"d.png" |
| 166 | + image: images.forecastOne |
143 | 167 | }, |
144 | 168 | two:{ |
145 | 169 | high: result.item.forecast[2].high, |
146 | | - highAlt: forecastTwoHighAlt, |
| 170 | + highAlt: altTemps.forecastTwoHigh, |
147 | 171 | low: result.item.forecast[2].low, |
148 | | - lowAlt: forecastTwoLowAlt, |
| 172 | + lowAlt: altTemps.forecastTwoLow, |
149 | 173 | forecast: result.item.forecast[2].text, |
150 | 174 | code: result.item.forecast[2].code, |
151 | 175 | date: result.item.forecast[2].date, |
152 | 176 | day: result.item.forecast[2].day, |
153 | | - image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[2].code+"d.png" |
| 177 | + image: images.forecastTwo |
154 | 178 | }, |
155 | 179 | three:{ |
156 | 180 | high: result.item.forecast[3].high, |
157 | | - highAlt: forecastThreeHighAlt, |
| 181 | + highAlt: altTemps.forecastThreeHigh, |
158 | 182 | low: result.item.forecast[3].low, |
159 | | - lowAlt: forecastThreeLowAlt, |
| 183 | + lowAlt: altTemps.forecastThreeLow, |
160 | 184 | forecast: result.item.forecast[3].text, |
161 | 185 | code: result.item.forecast[3].code, |
162 | 186 | date: result.item.forecast[3].date, |
163 | 187 | day: result.item.forecast[3].day, |
164 | | - image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[3].code+"d.png" |
| 188 | + image: images.forecastThree |
165 | 189 | }, |
166 | 190 | four:{ |
167 | 191 | high: result.item.forecast[4].high, |
168 | | - highAlt: forecastFourHighAlt, |
| 192 | + highAlt: altTemps.forecastFourHigh, |
169 | 193 | low: result.item.forecast[4].low, |
170 | | - lowAlt: forecastFourLowAlt, |
| 194 | + lowAlt: altTemps.forecastFourLow, |
171 | 195 | forecast: result.item.forecast[4].text, |
172 | 196 | code: result.item.forecast[4].code, |
173 | 197 | date: result.item.forecast[4].date, |
174 | 198 | day: result.item.forecast[4].day, |
175 | | - image: "//l.yimg.com/a/i/us/nws/weather/gr/"+result.item.forecast[4].code+"d.png" |
| 199 | + image: images.forecastFour |
176 | 200 | }, |
177 | 201 | }, |
178 | 202 | city: result.location.city, |
|
0 commit comments