' + ddday + '
\' + summary + '
\$(document).ready(function() { // get current location function getLocation(); var iconn; var dday; var ddday; var iconId; var inumber; var summary; var lati; var longt; var temper; var mintemper; var humidty; var windspid; var currTemp; var summaryDay; var PlaceName; var cityName; var teka; $(window).on("load", function() { // when window load icons play function getIconsPlay(); // loading animation function setTimeout(function() { $("#preloader").velocity( { opacity: 0.1, translateY: "-80px" }, { duration: 400, complete: function() { $("#hola").velocity( { translateY: "-100%" }, { duration: 1000, easing: [0.7, 0, 0.3, 1], complete: function() {} } ); } } ); }, 1000); }); }); function getFormattedAddress(address) { var order = [ ["house_number", "street_number"], ["house", "building", "public_building"], [ "road", "footway", "street", "street_name", "residential", "path", "pedestrian", "road_reference", "road_reference_intl" ], ["village", "hamlet", "locality"], ["neighbourhood", "suburb", "city_district"], ["city", "town"], ["county", "local_administrative_area", "county_code"], ["state", "province", "state_code"], ["country", "country_name"] ]; var formatted = {}; order = order.reverse(); var currentCount = 1; order.forEach(function(component, index) { index++; for (var i = 0; i < component.length; i++) { var alias = component[i]; if (address[alias] !== undefined) { if (index == 1) formatted[currentCount] = address[alias]; else formatted[currentCount] = address[alias] + ", " + formatted[currentCount - 1]; currentCount++; break; } } }); return formatted; } $(".getCurrentCity").on("click", function() { //get current city click function $(".daysList").html(""); getIconsPlay(); //get icons play function getLocation(); //get current location function }); // google map api // document.write(''); $(".getCity").on("click", function() { $(".daysList").html(""); var keyword = $(".cityVal").val(); $.ajax( "https://nominatim.openstreetmap.org/search?q=" + keyword + "&format=json" ).done(function(data) { console.log(data); var coords = data[0]; $.when( $.ajax( "https://nominatim.openstreetmap.org/reverse?format=json&lat=" + coords.lat + "&lon=" + coords.lon + "" ), $.ajax({ type: "Post", url: "https://api.darksky.net/forecast/7872f3201f558ed1217c55b409c43f75/" + coords.lat + "," + coords.lon + "?units=us&lang=en", beforeSend: function(x) { if (x && x.overrideMimeType) { x.overrideMimeType("application/j-son;charset=UTF-8"); } }, dataType: "jsonp", beforeSend: function() { console.log(coords.lat); } }) ).done(function(addressCallResult, weatherCallResult) { var addressData = addressCallResult[0]; var weatherData = weatherCallResult[0]; var address = setAddress(addressData); lati = coords.lat; longt = coords.lon; showWeather(weatherData); }); }); }); //get input val city weather click function function showPosition(position) { //get current city weather show document ready $.when( $.ajax( "https://nominatim.openstreetmap.org/reverse?format=json&lat=" + position.coords.latitude + "&lon=" + position.coords.longitude + "" ), $.ajax({ type: "Post", url: "https://api.darksky.net/forecast/7872f3201f558ed1217c55b409c43f75/" + position.coords.latitude + "," + position.coords.longitude + "?units=us&lang=en", beforeSend: function(x) { if (x && x.overrideMimeType) { x.overrideMimeType("application/j-son;charset=UTF-8"); } }, dataType: "jsonp", beforeSend: function() { console.log(position.coords.latitude); }, complete: function() { console.log(position.coords.longitude); } }) ).done(function(addressCallResult, weatherCallResult) { var addressData = addressCallResult[0]; var weatherData = weatherCallResult[0]; console.log("showPosition", addressData); var address = setAddress(addressData); $(".cityVal").val(address[4]); $(".cityVal") .next("span") .toggle(Boolean($(".cityVal").val())); lati = position.coords.latitude; longt = position.coords.longitude; showWeather(weatherData); }); } function setAddress(addressData) { var address = getFormattedAddress(addressData.address); console.log("Formatted:", address); $(".checkout__final-text").html(address[3]); PlaceName = address[4]; return address; } function showWeather(weatherData) { iconn = weatherData.currently.icon; currTemp = weatherData.currently.temperature .toString() .replace(",", ".") .split(".")[0] + "°F" + " / " + Math.round( toCelsius( weatherData.currently.temperature .toString() .replace(",", ".") .split(".")[0] ) ) + "°C"; summaryDay = weatherData.daily.summary; getIconsKind(); var d = new Date(parseInt(weatherData.currently.time, 10) * 1000); htmlCurrentWeather(); for (var i = 0; i < weatherData.daily.data.length; i++) { iconn = weatherData.daily.data[i].icon; inumber = i; summary = weatherData.daily.data[i].summary; temper = "High: " + weatherData.daily.data[i].temperatureMax .toString() .replace(",", ".") .split(".")[0] + "°F" + " / " + Math.round( toCelsius( weatherData.daily.data[i].temperatureMax .toString() .replace(",", ".") .split(".")[0] ) ) + "°C"; mintemper = "Low: " + Math.round(weatherData.daily.data[i].temperatureMin) + "°F" + " / " + Math.round(toCelsius(weatherData.daily.data[i].temperatureMin)) + "°C"; humidty = "Humidty: " + toPercent(weatherData.daily.data[i].humidity); windspid = "Wind Speed: " + weatherData.daily.data[i].windSpeed + " MPH" + " / " + toKPH(weatherData.daily.data[i].windSpeed) + " KPH"; getIconsKind(); dday = new Date(parseInt(weatherData.daily.data[i].time, 10) * 1000); ddday = dday.toString().substring(0, 15); appendDaysList(); } getIconsPlay(); // getMapPlace(); } function getIconsPlay() { $(".skycons-element").each(function() { var canvasId, skycons, weatherSetting; skycons = new Skycons({ color: "#FFE066" }); canvasId = $(this).attr("id"); weatherSetting = $(this).data("skycons"); skycons.add(canvasId, Skycons[weatherSetting]); return skycons.play(); }); var icons = new Skycons(); icons.set("clear-day", Skycons.CLEAR_DAY); icons.set("clear-night", Skycons.CLEAR_NIGHT); icons.set("partly-cloudy-day", Skycons.PARTLY_CLOUDY_DAY); icons.set("partly-cloudy-night", Skycons.PARTLY_CLOUDY_NIGHT); icons.set("cloudy", Skycons.CLOUDY); icons.set("rain", Skycons.RAIN); icons.set("sleet", Skycons.SLEET); icons.set("snow", Skycons.SNOW); icons.set("wind", Skycons.WIND); icons.set("fog", Skycons.FOG); icons.play(); } //get icons play function function getIconsKind() { if (iconn == "clear-day") { iconn = "CLEAR_DAY"; } else if (iconn == "clear-night") { iconn = "CLEAR_NIGHT"; } else if (iconn == "partly-cloudy-day") { iconn = "PARTLY_CLOUDY_DAY"; } else if (iconn == "partly-cloudy-night") { iconn = "PARTLY_CLOUDY_NIGHT"; } else if (iconn == "cloudy") { iconn = "CLOUDY"; } else if (iconn == "rain") { iconn = "RAIN"; } else if (iconn == "sleet") { iconn = "SLEET"; } else if (iconn == "snow") { iconn = "SNOW"; } else if (iconn == "wind") { iconn = "WIND"; } else if (iconn == "fog") { iconn = "FOG"; } } //get icons kind function(skycons icons are playin uppercase) function appendDaysList() { $(".daysList") .append( '
' + summary + '
\" + mintemper + "
\" + humidty + "
\" + windspid + '
\' + summaryDay + "
\