1if(typeof SimpleWeather.locale !== 'undefined' ){ 2 moment.defineLocale('en-SimpleWeather', SimpleWeather.locale); 3 moment.locale('en-SimpleWeather'); 4} 5 6Vue.filter('moment', function (date, format, convert) { 7 var offset = SimpleWeather.locale.gmtOffset; 8 var sign = offset.toString().indexOf('-') === 0 ? '-' : '+'; 9 hours = parseInt( offset / 3600 ); 10 hours = hours < 10 ? '0' + hours : hours; 11 minutes = offset % 3600; 12 minutes = minutes < 10 ? '0' + minutes : minutes; 13 var utc = sign + hours + ':' + minutes; 14 moment.defineLocale('en-SimpleWeather', SimpleWeather.locale); 15 moment.locale('en-SimpleWeather'); 16 return convert !== false ? moment(date * 1000).utcOffset(utc).format(format) : moment(date * 1000).format(format); 17}); 18 19var simple_weather_apps = []; 20 21Array.prototype.forEach.call( document.querySelectorAll('div.simple-weather--vue'), function(el, index){ 22 23 var id = el.getAttribute('id').replace( 'simple-weather--', '' ); 24 25 simple_weather_apps[index] = new Vue({ 26 el: '#simple-weather--' + id, 27 mounted: function() { 28 var vm = this; 29 var classes = [ 'simple-weather--vue-mounted' ]; 30 31 if( typeof vm.atts.text_align !== 'undefined' && vm.atts.text_align !== null && vm.atts.text_align.length > 0 ){ 32 classes.push( 'simple-weather--text-' + vm.atts.text_align ); 33 } 34 35 if( typeof vm.atts.style !== 'undefined' && vm.atts.style !== null && vm.atts.style.length > 0 ){ 36 classes.push( 'simple-weather--view-' + vm.atts.style ); 37 } 38 39 if( typeof vm.atts.display !== 'undefined' && vm.atts.display === 'block' ){ 40 classes.push( 'simple-weather--display-block' ); 41 } 42 43 if( typeof vm.show_date !== 'undefined' && ! vm.filter_var( vm.atts.show_date ) ){ 44 classes.push( 'simple-weather--hidden-date' ); 45 } 46 47 vm.$el.className += ' ' + classes.join( ' ' ); 48 49 if(typeof vm.feed !== 'undefined' && Object.keys(vm.feed).length === 0 && vm.feed.constructor === Object ){ 50 vm.get_weather(); 51 } 52 }, 53 data: function(){ 54 55 var vm = this; 56 var error = ' '; 57 var atts = typeof window['SimpleWeatherAtts'] !== 'undefined' && typeof window['SimpleWeatherAtts'][id] !== 'undefined' ? window['SimpleWeatherAtts'][id] : {}; 58 var feed = {}; 59 var feed_current_weather = {}; 60 61 if( typeof atts.station !== 'undefined' && atts.station === 'darksky' ){ 62 if( typeof window['SimpleWeatherFeeds'] !== 'undefined' && typeof window['SimpleWeatherFeeds'][id] !== 'undefined' && typeof window['SimpleWeatherFeeds'][id].forecast !== 'undefined' ){ 63 feed = window['SimpleWeatherFeeds'][id].forecast.daily; 64 feed_current_weather = typeof window['SimpleWeatherFeeds'][id].forecast.currently !== 'undefined' ? window['SimpleWeatherFeeds'][id].forecast.currently : {}; 65 } else if( typeof window['SimpleWeatherFeeds'] !== 'undefined' && typeof window['SimpleWeatherFeeds'][id] !== 'undefined' && typeof window['SimpleWeatherFeeds'][id].errors !== 'undefined' ){ 66 for( var i in window['SimpleWeatherFeeds'][id].errors ){ 67 if (! window['SimpleWeatherFeeds'][id].errors.hasOwnProperty(i)) continue; 68 if( [ 'could_not_get_location', 'no_api' ].indexOf( i ) >= 0 ) error = window['SimpleWeatherFeeds'][id].errors[i][0]; 69 } 70 } 71 } else { 72 if( typeof window['SimpleWeatherFeeds'] !== 'undefined' && typeof window['SimpleWeatherFeeds'][id] !== 'undefined' ){ 73 feed = window['SimpleWeatherFeeds'][id].forecast; 74 feed_current_weather = typeof window['SimpleWeatherFeeds'][id].current !== 'undefined' ? window['SimpleWeatherFeeds'][id].current : {}; 75 } 76 } 77 78 return { 79 atts: atts, 80 feed: feed, 81 feed_current_weather: feed_current_weather, 82 visible: [], 83 error: error 84 } 85 }, 86 filters: { 87 temp: function(temp){ 88 return typeof temp !== 'undefined' ? parseInt( temp ) : ''; 89 } 90 }, 91 computed: { 92 units: function(){ 93 return typeof this.atts.units !== 'undefined' && this.atts.units === 'imperial' ? 'F' : 'C'; 94 }, 95 units_wind: function(){ 96 return typeof this.atts.units !== 'undefined' && this.atts.units === 'imperial' ? 'mph' : 'kph'; 97 }, 98 current_weather: function(){ 99 var vm = this; 100 var out = {}; 101 102 if( vm.weather_station === 'openweather' ){ 103 if(typeof vm.feed_current_weather.weather !== 'undefined' && typeof vm.feed_current_weather.weather[0].id !== 'undefined' ){ 104 out.id = vm.feed_current_weather.weather[0].id; 105 out.desc = vm.feed_current_weather.weather[0].description; 106 } 107 if(typeof vm.feed_current_weather.dt !== 'undefined' ) out.dt = vm.feed_current_weather.dt; 108 if(typeof vm.feed_current_weather.main !== 'undefined' && typeof vm.feed_current_weather.main.temp !== 'undefined' ){ 109 out.temp = vm.feed_current_weather.main.temp; 110 out.humidity = Math.ceil( vm.feed_current_weather.main.humidity ); 111 } 112 if(typeof vm.feed_current_weather.clouds !== 'undefined' ) out.clouds = Math.ceil( vm.feed_current_weather.clouds.all ); 113 if(typeof vm.feed_current_weather.wind !== 'undefined' ) { 114 out.wind = {}; 115 out.wind.deg = vm.getWindDirection( vm.feed_current_weather.wind.deg ); 116 out.wind.speed = vm.units === 'metric' ? vm.feed_current_weather.wind.speed * 3.6 : vm.feed_current_weather.wind.speed * 3.6 / 1.609344; 117 out.wind.speed = Math.ceil(out.wind.speed); 118 } 119 if(typeof vm.feed_current_weather.name !== 'undefined' ) out.name = vm.feed_current_weather.name; 120 } 121 122 if( vm.weather_station === 'darksky' ){ 123 if(typeof vm.feed_current_weather.icon !== 'undefined' ) out.id = vm.feed_current_weather.icon; 124 if(typeof vm.feed_current_weather.summary !== 'undefined' ) out.desc = vm.feed_current_weather.summary; 125 if(typeof vm.feed_current_weather.humidity !== 'undefined' ) out.humidity = Math.ceil( vm.feed_current_weather.humidity * 100 ); 126 if(typeof vm.feed_current_weather.cloudCover !== 'undefined' ) out.clouds = Math.ceil( vm.feed_current_weather.cloudCover * 100 ); 127 128 if(typeof vm.feed_current_weather.windBearing !== 'undefined' && typeof vm.feed_current_weather.windSpeed !== 'undefined' ) { 129 out.wind = {}; 130 if(typeof vm.feed_current_weather.windBearing !== 'undefined' ) out.wind.deg = vm.getWindDirection( vm.feed_current_weather.windBearing ); 131 if(typeof vm.feed_current_weather.windSpeed !== 'undefined' ) out.wind.speed = vm.feed_current_weather.windSpeed; 132 } 133 134 if(typeof vm.feed_current_weather.time !== 'undefined' ) out.dt = vm.feed_current_weather.time; 135 if(typeof vm.feed_current_weather.temperature !== 'undefined' ) out.temp = vm.feed_current_weather.temperature; 136 } 137 return out; 138 }, 139 weather_feed: function(){ 140 var vm = this; 141 var out = []; 142 var dt = moment().utcOffset(this.get_utc_offset()); 143 var days = {}; 144 145 if( vm.weather_station === 'openweather' ){ 146 if( typeof vm.feed !== 'undefined' && typeof vm.feed.list !== 'undefined' ){ 147 148 vm.feed.list.forEach(function(val, index){ 149 150 var dayname = val.dt_txt.split( ' ' ); 151 dayname = dayname[0].replace('-', '_'); 152 153 if( typeof days[dayname] !== 'undefined' ){ 154 days[dayname].push( val.main.temp ); 155 } else { 156 days[dayname] = [ val.main.temp ]; 157 } 158 }); 159 160 vm.feed.list.forEach(function(val, index){ 161 162 var dayname = val.dt_txt.split( ' ' ); 163 dayname = dayname[0].replace('-', '_'); 164 165 if( ! dt.isSame( val.dt * 1000, 'day' ) ) { 166 167 var max = typeof days[dayname] !== 'undefined' ? days[dayname].reduce(function(a, b) { 168 return Math.max(a, b); 169 }) : null; 170 171 var min = typeof days[dayname] !== 'undefined' ? days[dayname].reduce(function(a, b) { 172 return Math.min(a, b); 173 }) : null; 174 175 out.push({ 176 dt: val.dt, 177 id: val.weather[0].id, 178 temp: max, 179 temp_min: min 180 }); 181 182 } 183 184 dt = moment( val.dt * 1000 ).utcOffset( vm.get_utc_offset() ); 185 186 }); 187 } 188 189 } 190 191 if( vm.weather_station === 'darksky' ){ 192 if( typeof vm.feed !== 'undefined' && typeof vm.feed.data !== 'undefined' ){ 193 vm.feed.data.forEach(function(val, index){ 194 195 if( ! dt.isSame( val.time * 1000, 'day' ) && dt.isBefore( val.time * 1000, 'day' ) ){ 196 out.push({ 197 dt: val.time, 198 id: val.icon, 199 temp: val.apparentTemperatureMax, 200 temp_min: val.apparentTemperatureMin 201 }); 202 } 203 last = moment(val.time * 1000).utcOffset( vm.get_utc_offset() ).format('YYYY/MM/DD'); 204 dt = moment(val.time * 1000).utcOffset( vm.get_utc_offset() ); 205 }); 206 } 207 } 208 return out.length > 0 ? out : false;
209 }, 210 weather_station : function(){ 211 var vm = this; 212 return typeof vm.atts.station !== 'undefined' && vm.atts.station === 'darksky' ? 'darksky' : 'openweather'; 213 }, 214 style: function(){ 215 var vm = this; 216 if( typeof vm.atts.style === 'undefined' ) return 'inline'; 217 return vm.atts.style; 218 } 219 }, 220 methods: { 221 in_darkSky_feed: function(){ 222 var vm = this; 223 }, 224 get_utc_offset: function(){ 225 var vm = this; 226 var offset = SimpleWeather.locale.gmtOffset; 227 var sign = offset.toString().indexOf('-') === 0 ? '-' : '+'; 228 hours = parseInt( offset / 3600 ); 229 hours = hours < 10 ? '0' + hours : hours; 230 minutes = offset % 3600; 231 minutes = minutes < 10 ? '0' + minutes : minutes; 232 var utc = sign + hours + ':' + minutes; 233 return utc; 234 }, 235 getWindDirection: function($deg){ 236 if ($deg >= 0 && $deg < 22.5) return 'N'; 237 else if ($deg >= 22.5 && $deg < 45) return 'NNE'; 238 else if ($deg >= 45 && $deg < 67.5) return 'NE'; 239 else if ($deg >= 67.5 && $deg < 90) return 'ENE'; 240 else if ($deg >= 90 && $deg < 122.5) return 'E'; 241 else if ($deg >= 112.5 && $deg < 135) return 'ESE'; 242 else if ($deg >= 135 && $deg < 157.5) return 'SE'; 243 else if ($deg >= 157.5 && $deg < 180) return 'SSE'; 244 else if ($deg >= 180 && $deg < 202.5) return 'S'; 245 else if ($deg >= 202.5 && $deg < 225) return 'SSW'; 246 else if ($deg >= 225 && $deg < 247.5) return 'SW'; 247 else if ($deg >= 247.5 && $deg < 270) return 'WSW'; 248 else if ($deg >= 270 && $deg < 292.5) return 'W'; 249 else if ($deg >= 292.5 && $deg < 315) return 'WNW'; 250 else if ($deg >= 315 && $deg < 337.5) return 'NW'; 251 else if ($deg >= 337.5 && $deg < 360) return 'NNW'; 252 else return; 253 }, 254 getWeatherIcon: function( day ){ 255 return this.weather_station === 'darksky' ? 'sw-forecast-io-' + day.id : 'sw-owm-' + day.id; 256 }, 257 isset: function( $key ){ 258 return typeof vm.atts[$key] !== 'undefined' && vm.atts[$key] !== null && vm.atts[$key].length > 0; 259 }, 260 hasCurrentWeather: function(){ 261 var vm = this; 262 return vm.filter_var( vm.atts.show_current ) && Object.keys(vm.current_weather).length > 0; 263 }, 264 isDayVisible: function(index, day){ 265 var vm = this; 266 var out = false; 267 var days = parseInt( vm.atts.days ); 268 if( vm.filter_var( vm.atts.show_current ) && moment( vm.current_weather.dt * 1000 ).utcOffset(this.get_utc_offset()).isSame( day.dt * 1000, 'day' ) ) return false; 269 return index < days; 270 }, 271 filter_var: function( test ){ 272 return [1, true, 'on', 'true', '1', 'yes'].indexOf(test) >= 0 ? true : false; 273 }, 274 get_weather: function(){ 275 var vm = this; 276 vm.$http.post( 277 window.SimpleWeather.rest_route + 'simple-weather/v1/get_weather/', 278 vm.atts, 279 { 280 emulateJSON: true 281 } 282 ).then(vm.successCallback, vm.errorCallback); 283 }, 284 successCallback: function(response){ 285 var vm = this; 286 if( vm.filter_var( window.SimpleWeather.settings.console_log ) ) console.log(response); 287 if( vm.weather_station === 'openweather' ){ 288 if( response.status >= 200 && response.status <= 202 ){ 289 if( typeof response.body.current !== 'undefined' ){ 290 vm.feed_current_weather = response.body.current; 291 } 292 if( typeof response.body.forecast !== 'undefined' ){ 293 vm.feed = response.body.forecast; 294 } 295 } 296 } 297 298 if( vm.weather_station === 'darksky' ){ 299 if( response.status >= 200 && response.status <= 202 ){ 300 if( typeof response.body.forecast !== 'undefined' && typeof response.body.forecast.currently !== 'undefined' ){ 301 vm.feed_current_weather = response.body.forecast.currently; 302 } 303 if( typeof response.body.forecast && typeof response.body.forecast.daily !== 'undefined' ){ 304 vm.feed = response.body.forecast.daily; 305 } 306 } 307 } 308 309 }, 310 errorCallback: function(response){ 311 var vm = this; 312 if( vm.filter_var( window.SimpleWeather.settings.console_log ) ) console.log(response); 313 if( typeof response.body.code !== 'undefined' && [ 'could_not_get_location', 'no_api' ].indexOf( response.body.code ) >= 0 ){ 314 vm.error = response.body.message; 315 } 316 } 317 } 318 }); 319 320});
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.