PageSourceSearch

https://www.nashobavalleyinn.com/wp-content/plugins/simple-weather/js/simple-weather.js?ver=4.1.1

js nashobavalleyinn.com collected 2026-10-07 00:30:33 UTC 16,353 bytes, 319 lines download raw bytes

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

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.