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 = $(".meteo-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") || "french"; 25 var location_for_rest = city.replace(" ", "_") + "," + country; 26 loadXMLDoc(weatherWidget, city, country, language, location_for_rest); 27 } 28 } 29 function loadXMLDoc(weatherWidget, city, country, language, location_for_rest) { 30 var xhr = new XMLHttpRequest(); 31 xhr.onload = function () { 32 // Process our return data 33 if (xhr.status >= 200 && xhr.status < 300) { 34 // Runs when the request is successful 35 handleResponse(JSON.parse(xhr.responseText), weatherWidget, city, country, language); 36 } else { 37 // Runs when it's not 38 console.log(xhr.responseText); 39 } 40 }; 41 xhr.open('GET', 'https://www.meteoart.com/weather/rests/publicWeatherForLocation.php?city=' + encodeURIComponent(city) + '&country=' + encodeURIComponent(country) + '&place=' + location_for_rest + '&domain=' + document.location + '&language=' + language); 42 xhr.send(); 43 } 44 45 46 function handleResponse(response, weatherWidget, city, country, language) { 47 48 var days = weatherWidget.getAttribute("data-days"); 49 var widgetInputWidth = weatherWidget.getAttribute("data-width"); 50 var isCurrent = weatherWidget.getAttribute("data-current"); 51 var isWind = weatherWidget.getAttribute("data-wind"); 52 var isSunrise = weatherWidget.getAttribute("data-sunrise"); 53 var backgroundColor = weatherWidget.getAttribute("data-background"); 54 if (!backgroundColor || backgroundColor === '' || backgroundColor === '#becffb') { 55 backgroundColor = 'linear-gradient(to left, #d3dfff, #fbfcff)'; 56 } 57 var textColor = weatherWidget.getAttribute("data-text-color"); 58 if (!textColor || textColor === '') { 59 textColor = 'black'; 60 } 61 62 //console.log(response); 63 var deepLink = response.deepLink; 64 var title = "Météo à " + city.capitalize(); 65 if (language === "english") { 66 title = "Weather in " + city.capitalize(); 67 } 68 var temp = response.temp + '°'; 69 var tempType = "C"; 70 var sunrise = "Lever du soleil: " + response.sunrise; 71 if (language === "english") { 72 sunrise = "Sunrise: " + response.sunrise; 73 } 74 var sunset = "Coucher du soleil: " + response.sunset; 75 if (language === "english") { 76 sunset = "Sunset: " + response.sunset; 77 } 78 var imageURL = response.icon; 79 var humidity = "Humidité: " + response.humidity + "%"; 80 if (language === "english") { 81 humidity = "Humidity: " + response.humidity + "%"; 82 } 83 var windspeedKmph = "Vent: " + response.windspeedKmph + "Kmph"; 84 if (language === "english") { 85 windspeedKmph = "Wind Speed: " + response.windspeedKmph + "Kmph"; 86 } 87 var chanceofrain = "Pluie: " + response.chanceofrain + "%"; 88 if (language === "english") { 89 chanceofrain = "Chance for rain: " + response.chanceofrain + "%"; 90 } 91 var daysForecast = response.days; 92 var description = response.description; 93 94 95 // set tight if user asked for not 100% 96 if (widgetInputWidth === 'tight') { 97 $(weatherWidget).addClass('tight'); 98 } else { 99 $(weatherWidget).addClass('maxwidth'); 100 } 101 102 // get widget width 103 var widgetWidth = $(weatherWidget).width(); 104 var widthClass = "regular"; 105 if (widgetWidth < 200) { 106 widthClass = "super-small"; 107 } else if (widgetWidth < 300) { 108 widthClass = "small"; 109 } 110 111 112 // wrap deep link 113 var mainDeepLinkElm = document.createElement("a"); 114 mainDeepLinkElm.setAttribute("href", deepLink); 115 mainDeepLinkElm.setAttribute("target", "_blank"); 116 117 //mainWrapElm 118 var mainWrapElm = document.createElement("div"); 119 mainWrapElm.setAttribute("class", 'main_wrap ' + widthClass); 120 mainWrapElm.setAttribute("style", "background: " + backgroundColor + " ;color:" + textColor); 121 122 //title 123 var titleElm = document.createElement("div"); 124 titleElm.innerHTML = title; 125 titleElm.setAttribute("class", "weather_title"); 126 mainWrapElm.appendChild(titleElm); 127 128 if (isCurrent === "on") { 129 // center wrap 130 var centerWrapElm = document.createElement("div"); 131 centerWrapElm.setAttribute("class", "weather_center_wrap"); 132 133 // temp wrap 134 var tempWrap = document.createElement("div"); 135 tempWrap.setAttribute("class", "weather_temp_wrap"); 136 137 // temp 138 var tempElm = document.createElement("span"); 139 tempElm.innerHTML = temp; 140 tempElm.setAttribute("class", "weather_temp"); 141 tempWrap.appendChild(tempElm); 142 143 // temp type 144 var tempTypeElm = document.createElement("span"); 145 tempTypeElm.innerHTML = tempType; 146 tempTypeElm.setAttribute("class", "weather_temp_type"); 147 tempWrap.appendChild(tempTypeElm); 148 149 // image 150 var imageWrapElm = document.createElement("div"); 151 var imageElm = document.createElement("img"); 152 imageElm.setAttribute("src", imageURL); 153 154 imageElm.setAttribute("class", "weather_image"); 155 imageWrapElm.setAttribute("class", "weather_image_wrap"); 156 imageWrapElm.appendChild(imageElm); 157 158 centerWrapElm.appendChild(imageWrapElm); 159 centerWrapElm.appendChild(tempWrap); 160 mainWrapElm.appendChild(centerWrapElm); 161 162 163 // description 164 var descriptionElm = document.createElement("div"); 165 descriptionElm.innerHTML = description; 166 descriptionElm.setAttribute("class", "weather_description"); 167 mainWrapElm.appendChild(descriptionElm); 168 } 169 170 if (isSunrise === 'on') { 171 // sunrise 172 var sunriseElm = document.createElement("div"); 173 sunriseElm.innerHTML = sunrise; 174 sunriseElm.setAttribute("class", "weather_sunrise"); //"); 175 mainWrapElm.appendChild(sunriseElm); 176 177 // sunset 178 var sunsetElm = document.createElement("div"); 179 sunsetElm.innerHTML = sunset; 180 sunsetElm.setAttribute("class", "weather_sunset"); //"); 181 mainWrapElm.appendChild(sunsetElm); 182 } 183 184 185 if (isWind === 'on') { 186 var weatherDataElm = document.createElement("div"); 187 weatherDataElm.setAttribute("class", "weather_data_wrap"); //""); 188 189 // humidity 190 var humidityElm = document.createElement("div"); 191 humidityElm.innerHTML = humidity; 192 humidityElm.setAttribute("class", "weather_humidity"); //"); 193 weatherDataElm.appendChild(humidityElm); 194 // wind 195 var windElm = document.createElement("div"); 196 windElm.innerHTML = windspeedKmph; 197 windElm.setAttribute("class", "weather_wind"); //"); 198 weatherDataElm.appendChild(windElm); 199 // rain 200 var chanceofrainElm = document.createElement("div"); 201 chanceofrainElm.innerHTML = chanceofrain; 202 chanceofrainElm.setAttribute("class", "weather_rain"); //"); 203 weatherDataElm.appendChild(chanceofrainElm); 204 205 // add to dom 206 mainWrapElm.appendChild(weatherDataElm); 207 } 208 209 210 // days 211 if (Number(days) > 0) { 212 var daysWrap = document.createElement("div"); 213 daysWrap.setAttribute("class", "weather_days_wrap"); //""); 214 215 for (var i = 0; i < Number(days); i++) { 216 var dayElm = document.createElement("div"); 217 var dayElmWidth = "33.3%"; 218 if (Number(days) === 2 || Number(days) === 4) { 219 dayElmWidth = "50%"; 220 } 221 dayElm.setAttribute("class", "weather_day_wrap"); //"width: " + dayElmWidth + "; text-align: center;margin: 10px 0px;"); 222 // day name 223 var dayNameElm = document.createElement("div"); 224 dayNameElm.innerHTML = daysForecast[i].dayName; 225 dayNameElm.setAttribute("class", "weather_day_name"); //""); 226 dayElm.appendChild(dayNameElm); 227 228 // day image 229 var dayImageWrapElm = document.createElement("div"); 230 var dayImageElm = document.createElement("img"); 231 dayImageElm.setAttribute("class", "weather_day_image"); //""); 232 dayImageElm.setAttribute("src", daysForecast[i].icon); 233 dayImageWrapElm.setAttribute("class", "weather_day_image_wrap"); //""); 234 dayImageWrapElm.appendChild(dayImageElm); 235 dayElm.appendChild(dayImageWrapElm); 236 237 // day temp 238 var dayTempElm = document.createElement("div"); 239 dayTempElm.innerHTML = daysForecast[i].min + "/" + daysForecast[i].max + '°' + "C"; 240 dayTempElm.setAttribute("class", "weather_day_temp"); //""); 241 dayElm.appendChild(dayTempElm); 242 243 daysWrap.appendChild(dayElm); 244 } 245 mainWrapElm.appendChild(daysWrap); 246 } 247
248 mainDeepLinkElm.prepend(mainWrapElm); 249 250 weatherWidget.prepend(mainDeepLinkElm); 251 } 252 253 }); 254 255})(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.