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