1/*! 2 3Name: Open Weather 4Dependencies: jQuery, OpenWeatherMap API 5Author: Michael Lynch 6Author URL: https://michaelynch.com 7Date Created: August 28, 2013 8Licensed under the MIT license 9 10*/ 11 12;(function($) { 13 14 $.fn.openWeather = function(options) { 15 16 //return if no element was bound 17 //so chained events can continue 18 if(!this.length) { 19 return this; 20 } 21 22 //define default parameters 23 var defaults = { 24 descriptionTarget: null, 25 maxTemperatureTarget: null, 26 minTemperatureTarget: null, 27 windSpeedTarget: null, 28 humidityTarget: null, 29 sunriseTarget: null, 30 sunsetTarget: null, 31 placeTarget: null, 32 iconTarget: null, 33 customIcons: null, 34 units: 'c', 35 city: null, 36 lat: null, 37 lng: null, 38 key: null, 39 lang: 'pl', 40 success: function() {}, 41 error: function(message) {} 42 } 43 44 //define plugin 45 var plugin = this; 46 47 //define element 48 var el = $(this); 49 50 //api URL 51 var apiURL; 52 53 //define settings 54 plugin.settings = {} 55 56 //merge defaults and options 57 plugin.settings = $.extend({}, defaults, options); 58 59 //define settings namespace 60 var s = plugin.settings; 61 62 //define basic api endpoint 63 apiURL = 'https://api.openweathermap.org/data/2.5/weather?lang='+s.lang; 64 65 //if city isn't null 66 if(s.city != null) { 67 68 //define API url using city (and remove any spaces in city) 69 apiURL += '&q='+s.city.replace(' ', ''); 70 71 } else if(s.lat != null && s.lng != null) { 72 73 //define API url using lat and lng 74 apiURL += '&lat='+s.lat+'&lon='+s.lng; 75 } 76 77 //if api key was supplied 78 if(s.key != null) { 79 80 //append api key paramater 81 apiURL += '&APPID=' + s.key; 82 83 } 84 85 //format time function 86 var formatTime = function(unixTimestamp) { 87 88 //define milliseconds using unix time stamp 89 var milliseconds = unixTimestamp * 1000; 90 91 //create a new date using milliseconds 92 var date = new Date(milliseconds); 93 94 //define hours 95 var hours = date.getHours(); 96 97 //if hours are greater than 12 98 if(hours > 12) { 99 100 //calculate remaining hours in the day 101 hoursRemaining = 24 - hours; 102 103 //define hours as the reamining hours subtracted from a 12 hour day 104 hours = 12 - hoursRemaining; 105 } 106 107 //define minutes 108 var minutes = date.getMinutes(); 109 110 //convert minutes to a string 111 minutes = minutes.toString(); 112 113 //if minutes has less than 2 characters 114 if(minutes.length < 2) { 115 116 //add a 0 to minutes 117 minutes = 0 + minutes; 118 } 119 120 //construct time using hours and minutes 121 var time = hours + ':' + minutes; 122 123 return time; 124 } 125 126 $.ajax({ 127 type: 'GET', 128 url: apiURL, 129 dataType: 'jsonp', 130 success: function(data) { 131 //console.log(apiURL); 132 //if units are 'f' 133 if(s.units == 'f') { 134 135 //define temperature as fahrenheit 136 var temperature = Math.round(((data.main.temp - 273.15) * 1.8) + 32) + '°F'; 137 138 //define min temperature as fahrenheit 139 var minTemperature = Math.round(((data.main.temp_min - 273.15) * 1.8) + 32) + '°F'; 140 141 //define max temperature as fahrenheit 142 var maxTemperature = Math.round(((data.main.temp_max - 273.15) * 1.8) + 32) + '°F'; 143 144 } else { 145 146 //define temperature as celsius 147 var temperature = Math.round(data.main.temp - 273.15) + '°C'; 148 149 //define min temperature as celsius 150 var minTemperature = Math.round(data.main.temp_min - 273.15) + '°C'; 151 152 //define max temperature as celsius 153 var maxTemperature = Math.round(data.main.temp_max - 273.15) + '°C'; 154 155 } 156 157 //set temperature 158 el.html(temperature); 159 160 //if minTemperatureTarget isn't null 161 if(s.minTemperatureTarget != null) { 162 163 //set minimum temperature 164 $(s.minTemperatureTarget).text(minTemperature); 165 } 166 167 //if maxTemperatureTarget isn't null 168 if(s.maxTemperatureTarget != null) { 169 170 //set maximum temperature 171 $(s.maxTemperatureTarget).text(maxTemperature); 172 } 173 174 //set weather description 175 $(s.descriptionTarget).text(data.weather[0].description); 176 177 //if iconTarget and default weather icon aren't null 178 if(s.iconTarget != null && data.weather[0].icon != null) { 179 180 //if customIcons isn't null 181 if(s.customIcons != null) { 182 183 //define the default icon name 184 var defaultIconFileName = data.weather[0].icon; 185 186 var iconName; 187 188 var timeOfDay; 189 190 //if default icon name contains the letter 'd' 191 if(defaultIconFileName.indexOf('d') != -1) { 192 193 //define time of day as day 194 timeOfDay = 'day'; 195 196 } else { 197 198 //define time of day as night 199 timeOfDay = 'night'; 200 } 201 202 if(defaultIconFileName == '01d' || defaultIconFileName == '01n') { 203 204 iconName = 'clear'; 205 206 } 207 208 //if icon is clouds 209 if(defaultIconFileName == '02d' || defaultIconFileName == '02n') { 210 211 iconName = 'f_clouds'; 212 213 } 214 215 //if icon is scattered clouds 216 if(defaultIconFileName == '03d' || defaultIconFileName == '03n') { 217 218 iconName = 's_clouds'; 219 220 } 221 222 223 //if icon is broken clouds 224 if(defaultIconFileName == '04d' || defaultIconFileName == '04n') { 225 226 iconName = 'b_clouds'; 227 228 } 229 230 //if icon is shower rain 231 if(defaultIconFileName == '09d' || defaultIconFileName == '09n') { 232 233 iconName = 'sh_rain'; 234 235 } 236 237 //if icon is rain 238 if(defaultIconFileName == '10d' || defaultIconFileName == '10n') { 239 240 iconName = 'rain'; 241 242 } 243 244 //if icon is thunderstorm 245 if(defaultIconFileName == '11d' || defaultIconFileName == '11n') { 246 247 iconName = 'storm'; 248 249 } 250 251 //if icon is snow 252 if(defaultIconFileName == '13d' || defaultIconFileName == '13n') { 253 254 iconName = 'snow'; 255 256 } 257 258 //if icon is mist 259 if(defaultIconFileName == '50d' || defaultIconFileName == '50n') { 260 261 iconName = 'mist'; 262 263 } 264 265 //define custom icon URL 266 var iconURL = s.customIcons+timeOfDay+'/'+iconName+'.png'; 267 268 } else { 269 270 //define icon URL using default icon 271 var iconURL = 'https://openweathermap.org/img/w/'+data.weather[0].icon+'.png'; 272 273 } 274 275 //set iconTarget src attribute as iconURL 276 $(s.iconTarget).attr('src', iconURL); 277 $(s.iconTarget).attr('alt', data.weather[0].description); 278 279 } 280 281 //if placeTarget isn't null 282 if(s.placeTarget != null) { 283 284 //set humidity 285 $(s.placeTarget).text(data.name + ', ' + data.sys.country); 286 } 287 288 //if windSpeedTarget isn't null 289 if(s.windSpeedTarget != null) { 290 291 //set wind speed 292 $(s.windSpeedTarget).text(Math.round(data.wind.speed * 3.6) + ' km/h'); //data.wind.speed w m/s 293 } 294 295 //if humidityTarget isn't null 296 if(s.humidityTarget != null) { 297 298 //set humidity 299 $(s.humidityTarget).text(data.main.humidity + '%'); 300 } 301 302 //if sunriseTarget isn't null 303 if(s.sunriseTarget != null) { 304
305 var sunrise = formatTime(data.sys.sunrise); 306 307 //set humidity 308 $(s.sunriseTarget).text(sunrise + ' AM'); 309 } 310 311 //if sunriseTarget isn't null 312 if(s.sunsetTarget != null) { 313 314 var sunset = formatTime(data.sys.sunset); 315 316 //set humidity 317 $(s.sunsetTarget).text(sunset + ' PM'); 318 } 319 320 //run success callback 321 s.success.call(this); 322 323 }, 324 325 error: function(jqXHR, textStatus, errorThrown) { 326 327 //run error callback 328 s.error.call(this, textStatus); 329 } 330 331 });//ajax 332 333 }//fn 334 335})(jQuery);
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.