1(function ($) { 2 'use strict'; 3 /** 4 * All of the code for your public-facing JavaScript source 5 * should reside in this file. 6 * 7 * Note: It has been assumed you will write jQuery code here, so the 8 * $ function reference has been prepared for usage within the scope 9 * of this function. 10 * 11 * This enables you to define handlers, for when the DOM is ready: 12 */ 13 $(function () { 14 String.prototype.capitalize = function () { 15 return this.charAt(0).toUpperCase() + this.slice(1) 16 }; 17 18 var weatherWidgets = $(".weer-widget"); 19 for (var i = 0; i < weatherWidgets.length; i++) { 20 var weatherWidget = weatherWidgets[i]; 21 if (weatherWidget) { 22 var city = weatherWidget.getAttribute("data-city"); 23 var country = weatherWidget.getAttribute("data-country"); 24 var language = weatherWidget.getAttribute("data-language") || "dutch"; 25 var location_for_rest = city.replace(" ", "_") + "," + country; 26 loadXMLDoc(weatherWidget, city, country, language, location_for_rest); 27 } 28 } 29 30 function loadXMLDoc(weatherWidget, city, country, language, location_for_rest) { 31 var xhr = new XMLHttpRequest(); 32 xhr.onload = function () { 33 // Process our return data 34 if (xhr.status >= 200 && xhr.status < 300) { 35 // Runs when the request is successful 36 handleResponse(JSON.parse(xhr.responseText), weatherWidget, city, country, language); 37 } else { 38 // Runs when it's not 39 console.log(xhr.responseText); 40 } 41 }; 42 xhr.open('GET', 'https://www.weatherwp.com/api/common/publicWeatherForLocation.php?city=' + encodeURIComponent(city) + '&country=' + encodeURIComponent(country) + '&place=' + location_for_rest + '&domain=' + document.location + '&language=' + language+ '&widget=Dutch'); 43 xhr.send(); 44 } 45 46 47 function handleResponse(response, weatherWidget, city, country, language) { 48 var header = weatherWidget.getAttribute("data-header"); 49 var widgetInputWidth = weatherWidget.getAttribute("data-width"); 50 var days = weatherWidget.getAttribute("data-days"); 51 var isCurrent = weatherWidget.getAttribute("data-current"); 52 var isWind = weatherWidget.getAttribute("data-wind"); 53 var isSunrise = weatherWidget.getAttribute("data-sunrise"); 54 var backgroundColor = weatherWidget.getAttribute("data-background"); 55 if (!backgroundColor || backgroundColor === '' || backgroundColor === '#becffb') { 56 backgroundColor = '#407cea'; 57 } 58 var textColor = weatherWidget.getAttribute("data-text-color"); 59 if (!textColor || textColor === '') { 60 textColor = 'white'; 61 } 62 63 //console.log(response); 64 var deepLink = response.deepLink; 65 var title = "Het weer in " + city.capitalize(); 66 if (language === "english") { 67 title = "Weather in " + city.capitalize(); 68 } 69 if (header !== '') { 70 title = header; 71 } 72 73 74 var temp = response.temp + '°'; 75 var tempType = "C"; 76 var sunrise = '<div class="sun-label">Zonsopkomst</div><div class="sun-value">' + response.sunrise + '</div>'; 77 if (language === "english") { 78 sunrise = '<div class="sun-label">Sunrise</div><div class="sun-value">' + response.sunrise + '</div>'; 79 } 80 var sunset = '<div class="sun-label">Zonsondergang</div><div class="sun-value">' + response.sunset + '</div>'; 81 if (language === "english") { 82 sunset = '<div class="sun-label">Sunset</div><div class="sun-value">' + response.sunset + '</div>'; 83 } 84 var imageURL = response.icon; 85 // var humidity = "Vochtigheid: " + response.humidity + "%"; 86 // if (language === "english") { 87 // humidity = "Humidity: " + response.humidity + "%"; 88 // } 89 var humidity = response.humidity + "%"; 90 91 // var windspeedKmph = "Windsnelheid: " + response.windspeedKmph + "Kmph"; 92 // if (language === "english") { 93 // windspeedKmph = "Wind Speed: " + response.windspeedKmph + "Kmph"; 94 // } 95 var windspeedKmph = response.windspeedKmph + "Km/h"; 96 97 // var chanceofrain = "Kans op regen: " + response.chanceofrain + "%"; 98 // if (language === "english") { 99 // chanceofrain = "Chance for rain: " + response.chanceofrain + "%"; 100 // } 101 var chanceofrain = response.chanceofrain + "%"; 102 var daysForecast = response.days; 103 var description = response.description; 104 105 106 // set tight if user asked for not 100% 107 if (widgetInputWidth === 'tight') { 108 $(weatherWidget).addClass('tight'); 109 } else { 110 $(weatherWidget).addClass('maxwidth'); 111 } 112 113 114 115 //mainWrapElm 116 var mainWrapElm = document.createElement("div"); 117 118 mainWrapElm.setAttribute("style", "background-color: " + backgroundColor + " ;color:" + textColor); 119 120 //title 121 var titleElm = document.createElement("div"); 122 titleElm.innerHTML = title; 123 titleElm.setAttribute("class", "weather_widget_title"); 124 mainWrapElm.appendChild(titleElm); 125 126 // wrap deep link 127 var mainDeepLinkElm = document.createElement("a"); 128 mainDeepLinkElm.setAttribute("href", deepLink); 129 mainDeepLinkElm.setAttribute("target", "_blank"); 130 mainDeepLinkElm.setAttribute("title", title); 131 132 133 if (isCurrent === "on") { 134 // center wrap 135 var centerWrapElm = document.createElement("div"); 136 centerWrapElm.setAttribute("class", "weather_center_wrap"); 137 138 // temp wrap 139 var tempWrap = document.createElement("div"); 140 tempWrap.setAttribute("class", "weather_temp_wrap"); 141 142 // temp 143 var tempElm = document.createElement("span"); 144 tempElm.innerHTML = temp; 145 tempElm.setAttribute("class", "weather_temp"); 146 tempWrap.appendChild(tempElm); 147 148 // temp type 149 var tempTypeElm = document.createElement("span"); 150 tempTypeElm.innerHTML = tempType; 151 tempTypeElm.setAttribute("class", "weather_temp_type"); 152 tempWrap.appendChild(tempTypeElm); 153 154 // image 155 var imageWrapElm = document.createElement("div"); 156 var imageElm = document.createElement("img"); 157 imageElm.setAttribute("src", imageURL); 158 159 imageElm.setAttribute("class", "weather_image"); 160 imageWrapElm.setAttribute("class", "weather_image_wrap"); 161 imageWrapElm.appendChild(imageElm); 162 163 centerWrapElm.appendChild(imageWrapElm); 164 centerWrapElm.appendChild(tempWrap); 165 mainWrapElm.appendChild(centerWrapElm); 166 167 168 // description 169 var descriptionElm = document.createElement("div"); 170 descriptionElm.innerHTML = description; 171 descriptionElm.setAttribute("class", "weather_description"); 172 // mainWrapElm.appendChild(descriptionElm); 173 } 174 175 176 if (isWind === 'on') { 177 var weatherDataElm = document.createElement("div"); 178 weatherDataElm.setAttribute("class", "weather_data_wrap"); //""); 179 180 // humidity 181 var humidityElm = document.createElement("div"); 182 humidityElm.innerHTML = humidity; 183 humidityElm.setAttribute("class", "weather_humidity"); //"); 184 weatherDataElm.appendChild(humidityElm); 185 // wind 186 var windElm = document.createElement("div"); 187 windElm.innerHTML = windspeedKmph; 188 windElm.setAttribute("class", "weather_wind"); //"); 189 weatherDataElm.appendChild(windElm); 190 // rain 191 var chanceofrainElm = document.createElement("div"); 192 chanceofrainElm.innerHTML = chanceofrain; 193 chanceofrainElm.setAttribute("class", "weather_rain"); //"); 194 weatherDataElm.appendChild(chanceofrainElm); 195 196 // add to dom 197 mainWrapElm.appendChild(weatherDataElm); 198 } 199 200 if (isSunrise === 'on') { 201 var sunSection = document.createElement("div"); 202 sunSection.setAttribute("class", "sun-section"); 203 204 205 // sunrise 206 var sunriseElm = document.createElement("div"); 207 sunriseElm.innerHTML = sunrise; 208 sunriseElm.setAttribute("class", "weather_sunrise"); 209 sunSection.appendChild(sunriseElm); 210 211 // sunset 212 var sunsetElm = document.createElement("div"); 213 sunsetElm.innerHTML = sunset; 214 sunsetElm.setAttribute("class", "weather_sunset"); 215 sunSection.appendChild(sunsetElm); 216 217 218 mainWrapElm.appendChild(sunSection); 219 } 220 221 // background mask 222 var daysBGWrap = document.createElement("div"); 223 daysBGWrap.setAttribute("class", "widget-bg-mask"); 224 daysBGWrap.setAttribute("style", "background-color: " + backgroundColor + " ;color:" + textColor); 225 mainWrapElm.appendChild(daysBGWrap); 226 227 228 // days 229 if (Number(days) > 0) { 230 var daysWrap = document.createElement("div"); 231 daysWrap.setAttribute("class", "weather_days_wrap"); //""); 232 233 for (var i = 0; i < Number(days); i++) { 234 var dayElm = document.createElement("div"); 235 var dayElmWidth = "33.3%"; 236 if (Number(days) === 2 || Number(days) === 4) { 237 dayElmWidth = "50%"; 238 } 239 dayElm.setAttribute("class", "weather_day_wrap"); //"width: " + dayElmWidth + "; text-align: center;margin: 10px 0px;"); 240 // day name 241 var dayNameElm = document.createElement("div"); 242 dayNameElm.innerHTML = daysForecast[i].dayName; 243 dayNameElm.setAttribute("class", "weather_day_name"); //""); 244 dayElm.appendChild(dayNameElm); 245 246 // day image 247 var dayImageWrapElm = document.createElement("div"); 248 var dayImageElm = document.createElement("img"); 249 dayImageElm.setAttribute("class", "weather_day_image"); //""); 250 dayImageElm.setAttribute("src", daysForecast[i].icon); 251 dayImageWrapElm.setAttribute("class", "weather_day_image_wrap"); //""); 252 dayImageWrapElm.appendChild(dayImageElm); 253 dayElm.appendChild(dayImageWrapElm); 254 255 // day temp 256 var dayTempElm = document.createElement("div"); 257 dayTempElm.innerHTML = daysForecast[i].min + "/" + daysForecast[i].max + '°' + "C"; 258 dayTempElm.setAttribute("class", "weather_day_temp"); //""); 259 dayElm.appendChild(dayTempElm); 260 daysWrap.appendChild(dayElm); 261 } 262 mainWrapElm.appendChild(daysWrap); 263 } 264 265
266 mainDeepLinkElm.prepend(mainWrapElm); 267 268 weatherWidget.prepend(mainDeepLinkElm); 269 270 271 // get widget width 272 var widgetWidth = $(weatherWidget).width(); 273 var widthClass = "regular"; 274 if (widgetWidth < 200) { 275 widthClass = "super-small"; 276 } else if (widgetWidth < 300) { 277 widthClass = "small"; 278 } 279 var ratio = widgetWidth / 375; 280 281 $(weatherWidget).find('.main_wrap').addClass(widthClass); 282 283 284 if (widgetWidth > 500) { 285 $(weatherWidget).find('.weather_sunrise').css({"margin-top": "20px"}); 286 $(weatherWidget).find('.weather_sunset').css({"margin-top": "20px"}); 287 } 288 var sunNewHeight = ratio * 70; 289 var sunNewPadding = ratio * 10; 290 var sunStyle = "" 291 if (widgetWidth > 375) { 292 $(weatherWidget).find('.sun-section').css({"height": sunNewHeight + "px", "padding": "0 " + sunNewPadding + "%"}); 293 } 294 if (widgetWidth > 500) { 295 $(weatherWidget).find('.sun-section').css({ 296 "height": "115px", 297 "margin": "70px auto 0 auto", 298 "max-width": "500px", 299 "background-position": "center" 300 }); 301 } 302 303 // set the height of the mask image 304 var newHeight = ratio * 65; 305 $(weatherWidget).find('.widget-bg-mask').css({ 306 "height": newHeight + "px" 307 }); 308 } 309 }); 310 311})(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.