1 line
9.7 KiB
JavaScript
1 line
9.7 KiB
JavaScript
|
$(document).ready(function(){getLocation();$(window).on("load",function(){getIconsPlay(),setTimeout(function(){$("#preloader").velocity({opacity:.1,translateY:"-80px"},{duration:400,complete:function(){$("#hola").velocity({translateY:"-100%"},{duration:1e3,easing:[.7,0,.3,1],complete:function(){}})}})},1e3)})});function getFormattedAddress(a){var b=[["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"]],c={};b=b.reverse();var d=1;return b.forEach(function(b,e){e++;for(var f,g=0;g<b.length;g++)if(f=b[g],void 0!==a[f]){c[d]=1==e?a[f]:a[f]+", "+c[d-1],d++;break}}),c}$(".getCurrentCity").on("click",function(){$(".daysList").html(""),getIconsPlay(),getLocation()}),$(".getCity").on("click",function(){$(".daysList").html("");var a=$(".cityVal").val();$.ajax("https://nominatim.openstreetmap.org/search?q="+a+"&format=json").done(function(a){console.log(a);var b=a[0];$.when($.ajax("https://nominatim.openstreetmap.org/reverse?format=json&lat="+b.lat+"&lon="+b.lon+""),$.ajax({type:"Post",url:"https://api.darksky.net/forecast/7872f3201f558ed1217c55b409c43f75/"+b.lat+","+b.lon+"?units=us&lang=en",beforeSend:function(a){a&&a.overrideMimeType&&a.overrideMimeType("application/j-son;charset=UTF-8")},dataType:"jsonp",beforeSend:function(){console.log(b.lat)}})).done(function(a,c){var d=a[0],e=c[0],f=setAddress(d);lati=b.lat,longt=b.lon,showWeather(e)})})});function showPosition(a){$.when($.ajax("https://nominatim.openstreetmap.org/reverse?format=json&lat="+a.coords.latitude+"&lon="+a.coords.longitude+""),$.ajax({type:"Post",url:"https://api.darksky.net/forecast/7872f3201f558ed1217c55b409c43f75/"+a.coords.latitude+","+a.coords.longitude+"?units=us&lang=en",beforeSend:function(a){a&&a.overrideMimeType&&a.overrideMimeType("application/j-son;charset=UTF-8")},dataType:"jsonp",beforeSend:function(){console.log(a.coords.latitude)},complete:function(){console.log(a.coords.longitude)}})).done(function(b,c){var d=b[0],e=c[0];console.log("showPosition",d);var f=setAddress(d);$(".cityVal").val(f[4]),$(".cityVal").next("span").toggle(!!$(".cityVal").val()),lati=a.coords.latitude,longt=a.coords.longitude,showWeather(e)})}function setAddress(a){var b=getFormattedAddress(a.address);return console.log("Formatted:",b),$(".checkout__final-text").html(b[3]),PlaceName=b[4],b}function showWeather(a){iconn=a.currently.icon,currTemp=a.currently.temperature.toString().replace(",",".").split(".")[0]+"°F / "+Math.round(toCelsius(a.currently.temperature.toString().replace(",",".").split(".")[0]))+"°C",summaryDay=a.daily.summary,getIconsKind();new Date(1e3*parseInt(a.currently.time,10));htmlCurrentWeather();for(var b=0;b<a.daily.data.length;b++)iconn=a.daily.data[b].icon,inumber=b,summary=a.daily.data[b].summary,temper="High: "+a.daily.data[b].temperatureMax.toString().replace(",",".").split(".")[0]+"°F / "+Math.round(toCelsius(a.daily.data[b].temperatureMax.toString().replace(",",".").split(".")[0]))+"°C",mintemper="Low: "+Math.round(a.daily.data[b].temperatureMin)+"°F / "+Math.round(toCelsius(a.daily.data[b].temperatureMin))+"°C",humidty="Humidty: "+toPercent(a.daily.data[b].humidity),windspid="Wind Speed: "+a.daily.data[b].windSpeed+" MPH / "+toKPH(a.daily.data[b].windSpeed)+" KPH",getIconsKind(),dday=new Date(1e3*parseInt(a.daily.data[b].time,10)),ddday=dday.toString().substring(0,15),appendDaysList();getIconsPlay()}function getIconsPlay(){$(".skycons-element").each(function(){var a,b,c;return b=new Skycons({color:"#FFE066"}),a=$(this).attr("id"),c=$(this).data("skycons"),b.add(a,Skycons[c]),b.play()});var a=new Skycons;a.set("clear-day",Skycons.CLEAR_DAY),a.set("clear-night",Skycons.CLEAR_NIGHT),a.set("partly-cloudy-day",Skycons.PARTLY_CLOUDY_DAY),a.set("partly-cloudy-night",Skycons.PARTLY_CLOUDY_NIGHT),a.s
|