PageSourceSearch

https://www.estoeselche.es/wp-content/plugins/tiempo/public/js/tiempo-public.js?ver=1.0.0

js estoeselche.es collected 2026-10-07 18:12:03 UTC 9,132 bytes, 260 lines download raw bytes

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 = $(".tiempo-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") || "spanish";
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.weatherwp.com/api/common/publicWeatherForLocation.php?city=' + encodeURIComponent(city) + '&country=' + encodeURIComponent(country) + '&place=' + location_for_rest + '&domain=' + document.location + '&language=' + language+ '&widget=Spanish');
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 = "Tiempo en " + city.capitalize();
65			if (language == "english") {
66				title = "Weather in " + city.capitalize();
67			}
68			var temp = response.temp + '&#176;';
69			var tempType = "C";
70			var sunrise = "Amanecer: " + response.sunrise;
71			if (language == "english") {
72				sunrise = "Sunrise: " + response.sunrise;
73			}
74			var sunset = "Puesta de sol: " + response.sunset;
75			if (language == "english") {
76				sunset = "Sunset: " + response.sunset;
77			}
78			var imageURL = response.icon;
79			var humidity = "Humedad: " + response.humidity + "%";
80			if (language == "english") {
81				humidity = "Humidity: " + response.humidity + "%";
82			}
83			var windspeedKmph = "Viento: " + response.windspeedKmph + " Kmph";
84			if (language == "english") {
85				windspeedKmph = "Wind Speed: " + response.windspeedKmph + " Kmph";
86			}
87			var chanceofrain = "Lluvia: " + 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			if(response.deepLinkAlt){
117				mainDeepLinkElm.setAttribute("title", response.deepLinkAlt);
118				mainDeepLinkElm.setAttribute("aria-label", response.deepLinkAlt);
119			}
120
121			//mainWrapElm
122			var mainWrapElm = document.createElement("div");
123			mainWrapElm.setAttribute("class", 'main_wrap ' + widthClass);
124			mainWrapElm.setAttribute("style", "background: " + backgroundColor + " ;color:" + textColor);
125
126			//title
127			var titleElm = document.createElement("div");
128			titleElm.innerHTML = title;
129			titleElm.setAttribute("class", "weather_title");
130			mainWrapElm.appendChild(titleElm);
131
132			if (isCurrent == "on") {
133				// center wrap
134				var centerWrapElm = document.createElement("div");
135				centerWrapElm.setAttribute("class", "weather_center_wrap");
136
137				// temp wrap
138				var tempWrap = document.createElement("div");
139				tempWrap.setAttribute("class", "weather_temp_wrap");
140
141				// temp
142				var tempElm = document.createElement("span");
143				tempElm.innerHTML = temp;
144				tempElm.setAttribute("class", "weather_temp");
145				tempWrap.appendChild(tempElm);
146
147				// temp type
148				var tempTypeElm = document.createElement("span");
149				tempTypeElm.innerHTML = tempType;
150				tempTypeElm.setAttribute("class", "weather_temp_type");
151				tempWrap.appendChild(tempTypeElm);
152
153				// image
154				var imageWrapElm = document.createElement("div");
155				var imageElm = document.createElement("img");
156				imageElm.setAttribute("src", imageURL);
157
158				imageElm.setAttribute("class", "weather_image");
159				imageWrapElm.setAttribute("class", "weather_image_wrap");
160				imageWrapElm.appendChild(imageElm);
161
162				centerWrapElm.appendChild(imageWrapElm);
163				centerWrapElm.appendChild(tempWrap);
164				mainWrapElm.appendChild(centerWrapElm);
165
166
167				// description
168				var descriptionElm = document.createElement("div");
169				descriptionElm.innerHTML = description;
170				descriptionElm.setAttribute("class", "weather_description");
171				mainWrapElm.appendChild(descriptionElm);
172			}
173
174			if (isSunrise == 'on') {
175				// sunrise
176				var sunriseElm = document.createElement("div");
177				sunriseElm.innerHTML = sunrise;
178				sunriseElm.setAttribute("class", "weather_sunrise"); //");
179				mainWrapElm.appendChild(sunriseElm);
180
181				// sunset
182				var sunsetElm = document.createElement("div");
183				sunsetElm.innerHTML = sunset;
184				sunsetElm.setAttribute("class", "weather_sunset"); //");
185				mainWrapElm.appendChild(sunsetElm);
186			}
187
188
189			if (isWind == 'on') {
190				var weatherDataElm = document.createElement("div");
191				weatherDataElm.setAttribute("class", "weather_data_wrap"); //"");
192
193				// humidity
194				var humidityElm = document.createElement("div");
195				humidityElm.innerHTML = humidity;
196				humidityElm.setAttribute("class", "weather_humidity"); //");
197				weatherDataElm.appendChild(humidityElm);
198				// wind
199				var windElm = document.createElement("div");
200				windElm.innerHTML = windspeedKmph;
201				windElm.setAttribute("class", "weather_wind"); //");
202				weatherDataElm.appendChild(windElm);
203				// rain
204				var chanceofrainElm = document.createElement("div");
205				chanceofrainElm.innerHTML = chanceofrain;
206				chanceofrainElm.setAttribute("class", "weather_rain"); //");
207				weatherDataElm.appendChild(chanceofrainElm);
208
209				// add to dom
210				mainWrapElm.appendChild(weatherDataElm);
211			}
212
213
214			// days
215			if (Number(days) > 0) {
216				var daysWrap = document.createElement("div");
217				daysWrap.setAttribute("class", "weather_days_wrap"); //"");
218
219				for (var i = 0; i < Number(days); i++) {
220					var dayElm = document.createElement("div");
221					var dayElmWidth = "33.3%";
222					if (Number(days) == 2 || Number(days) == 4) {
223						dayElmWidth = "50%";
224					}
225					dayElm.setAttribute("class", "weather_day_wrap"); //"width: " + dayElmWidth + "; text-align: center;margin: 10px 0px;");
226					// day name
227					var dayNameElm = document.createElement("div");
228					dayNameElm.innerHTML = daysForecast[i].dayName;
229					dayNameElm.setAttribute("class", "weather_day_name"); //"");
230					dayElm.appendChild(dayNameElm);
231
232					// day image
233					var dayImageWrapElm = document.createElement("div");
234					var dayImageElm = document.createElement("img");
235					dayImageElm.setAttribute("class", "weather_day_image"); //"");
236					dayImageElm.setAttribute("src", daysForecast[i].icon);
237					dayImageWrapElm.setAttribute("class", "weather_day_image_wrap"); //"");
238					dayImageWrapElm.appendChild(dayImageElm);
239					dayElm.appendChild(dayImageWrapElm);
240
241					// day temp
242					var dayTempElm = document.createElement("div");
243					dayTempElm.innerHTML = daysForecast[i].max + "&#176;<span class='temp-separator'>/</span>" + daysForecast[i].min + '&#176;';
244					dayTempElm.setAttribute("class", "weather_day_temp"); //"");
245					dayElm.appendChild(dayTempElm);
246
247
248					daysWrap.appendChild(dayElm);
249				}
250				mainWrapElm.appendChild(daysWrap);
251			}
252
253			mainDeepLinkElm.prepend(mainWrapElm);
254
255			weatherWidget.prepend(mainDeepLinkElm);
256		}
257
258	});
259
260})(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.