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.set("cloudy",Skycons.CLOUDY),a.set("rain",Skycons.RAIN),a.set("sleet",Skycons.SLEET),a.set("snow",Skycons.SNOW),a.set("wind",Skycons.WIND),a.set("fog",Skycons.FOG),a.play()}function getIconsKind(){"clear-day"==iconn?iconn="CLEAR_DAY":"clear-night"==iconn?iconn="CLEAR_NIGHT":"partly-cloudy-day"==iconn?iconn="PARTLY_CLOUDY_DAY":"partly-cloudy-night"==iconn?iconn="PARTLY_CLOUDY_NIGHT":"cloudy"==iconn?iconn="CLOUDY":"rain"==iconn?iconn="RAIN":"sleet"==iconn?iconn="SLEET":"snow"==iconn?iconn="SNOW":"wind"==iconn?iconn="WIND":"fog"==iconn&&(iconn="FOG")}function appendDaysList(){$(".daysList").append("<div class=\"col-md-3 col-sm-12\"> <div class=\"card-container manual-flip\"> <div class=\"card\"> <div class=\"front paint-area\"> <div class=\"cover\"> <img src=\"bgimg/rotating_card_thumb.png\"/> </div> <div class=\"user\"> <canvas class=\"skycons-element\" height=\"100%\" width=\"100%\" data-skycons=\""+iconn+"\" id=\"weatherIcon"+inumber+"\"></canvas> </div> <div class=\"content\"> <div class=\"main\"> <h3 class=\"name\">"+ddday+"</h3> <p class=\"profession\">"+summary+"</p> <h4><i class=\"fa fa-sun-o fa-fw text-muted\"></i>"+temper+"</h4> </div> <div class=\"footer\"> <button type=\"button\" class=\"btn btn-simple\" onclick=\"rotateCard(this)\"> <i class=\"fa fa-mail-forward\"></i> More Information </button> </div> </div> </div> <!-- end front panel --> <div class=\"back paint-area\"> <div class=\"header\"> <h5 class=\"motto\">"+ddday+"</h5> </div> <div class=\"content\"> <div class=\"main\"> <h4 class=\"text-center\">"+summary+"</h4> <p>"+mintemper+"</p> <p>"+humidty+"</p> <p>"+windspid+"</p> </div> </div> <div class=\"footer\"> <button type=\"button\" class=\"btn btn-simple\" rel=\"tooltip\" title=\"Flip Card\" onclick=\"rotateCard(this)\"> <i class=\"fa fa-reply\"></i> Back </button> </div> </div> <!-- end back panel --> </div> <!-- end card --> </div> <!-- end card-container --> </div>").addClass("animated pulse")}function htmlCurrentWeather(){$(".currentWeather").html("<div class=\"col-md-12\"> <div class=\"card-container manual-flip\"> <div class=\"card\"> <div class=\"front paint-area\"> <div class=\"cover\"> <img src=\"bgimg/rotating_card_thumb.jpg\"/> </div> <div class=\"user\"> <canvas class=\"skycons-element\" height=\"100%\" width=\"100%\" data-skycons=\""+iconn+"\" id=\"weatherIcon999\"></canvas> </div> <div class=\"content\"> <div class=\"main\"> <h3>Current Weather</h3> <h2><i class=\"fa fa-map-marker fa-fw text-muted\"></i> "+PlaceName+"</h2> <h3 class=\"name\">"+currTemp+"</h3> <p class=\"profession\">"+summaryDay+"</p> </div> </div> </div> <!-- end front panel --> </div> <!-- end card --> </div> <!-- end card-container --> </div>").addClass("animated pulse")}$(".cityVal").keyup(function(a){13==a.keyCode&&$(".getCity").click();var b=$(this);b.next("span").toggle(!!b.val())}),$("#searchclear").hide($(this).prev(".cityVal").val()),$("#searchclear").on("click",function(){$(this).prev(".cityVal").val("").focus(),$(this).hide()});function getMapPlace(){var a={center:new google.maps.LatLng(lati,longt),zoom:15,mapTypeId:google.maps.MapTypeId.ROADMAP},b=new google.maps.InfoWindow,c=new google.maps.LatLngBounds,d=new google.maps.Map(document.getElementById("dvMap"),a);navigator.geolocation.getCurrentPosition(function(){var a=new google.maps.LatLng(lati,longt),b=new google.maps.Marker({position:a,title:"Your Location",draggable:!0,map:d}),c=new google.maps.InfoWindow({content:"<div id=\"infodiv\" style=\"width: 300px\">300px wide infowindow! if the mouse is not here, will close after 3 seconds</div>"});google.maps.event.addListener(b,"dragend",function(){c.open(d,b),d.setCenter(b.getPosition())}),google.maps.event.addListener(b,"mouseover",function(){c.open(d,b)}),google.maps.event.addListener(b,"mouseout",function(){t=setTimeout(function(){c.close()},3e3)}),google.maps.event.addListener(c,"domready",function(){$("#infodiv").on("mouseenter",function(){clearTimeout(t)}).on("mouseleave",function(){t=setTimeout(function(){c.close()},1e3)})}),d.setCenter(b.getPosition())}),$(window).on("resize",function(){var a=d.getCenter();google.maps.event.trigger(d,"resize"),d.setCenter(a)})}function getLocation(){navigator.geolocation?navigator.geolocation.getCurrentPosition(showPosition):console.log("Geolocation is not supported by this browser.")}(function(){[].slice.call(document.querySelectorAll(".checkout")).forEach(function(a){var b=a.querySelector(".checkout__button"),c=a.querySelector(".checkout__cancel");b.addEventListener("click",function(b){b.preventDefault(),classie.add(a,"checkout--active")}),c.addEventListener("click",function(){classie.remove(a,"checkout--active")})})})(),$().ready(function(){$("[rel=\"tooltip\"]").tooltip()});function rotateCard(a){var b=$(a).closest(".card-container");console.log(b),b.hasClass("hover")?b.removeClass("hover"):b.addClass("hover")}(function(a){"use strict";function b(a){return new RegExp("(^|\\s+)"+a+"(\\s+|$)")}function c(a,b){var c=d(a,b)?f:e;c(a,b)}var d,e,f;"classList"in document.documentElement?(d=function(a,b){return a.classList.contains(b)},e=function(a,b){a.classList.add(b)},f=function(a,b){a.classList.remove(b)}):(d=function(a,d){return b(d).test(a.className)},e=function(a,b){d(a,b)||(a.className=a.className+" "+b)},f=function(a,d){a.className=a.className.replace(b(d)," ")});var g={hasClass:d,addClass:e,removeClass:f,toggleClass:c,has:d,add:e,remove:f,toggle:c};"function"==typeof define&&define.amd?define(g):a.classie=g})(window),$(".color-tool li a").on("click",function(){var a=$(this).data("color");$("body").css("background",a)});function toCelsius(a){return 5/9*(a-32)}function toPercent(a){return(100*a).toFixed(0)+"%"}function toKPH(a){return(1.609344*a).toFixed(2)} |