diff --git a/css/style.css b/css/style.css index 96445a6..42ec2d5 100644 --- a/css/style.css +++ b/css/style.css @@ -1 +1,21 @@ /* Custom CSS goes here */ +body{ + height: 100vh; +} + +.col-md-offset-4{ + text-align: center; +} + +h1{ + margin: 35px auto; + font-size: 45px; +} + +.row, p{ + padding: 10px; +}; + +main{ + color: red; +} diff --git a/index.html b/index.html index 33c1580..5e982ce 100644 --- a/index.html +++ b/index.html @@ -3,8 +3,8 @@ Mini Weather App - +
@@ -14,7 +14,7 @@

Weather App

- +
@@ -23,6 +23,7 @@

Weather App

+

diff --git a/js/main.js b/js/main.js index da8a934..c781851 100644 --- a/js/main.js +++ b/js/main.js @@ -1 +1,84 @@ /* Javascript goes here! */ +console.log('Sanity Check'); + +var mapURL; +var toF; +var thisMap; + +$('.weather-app').css('background-color', 'rgba(255,255,255,.5)'); + +$(document).ready(function(){ + //Initialized description + $('.description').append("Condition Outside: "); + + $('.submission').click(function(event){ + event.preventDefault(); + }); + + $('.submission').on('click', function(){ + var userInput = $('.weather-city').val(); + requestWeatherData(userInput); + console.log(userInput); + }); +}); + +function requestWeatherData(cityName){ + //AJAX request based on user input + $.ajax({ + method: 'GET', + url: 'https://api.openweathermap.org/data/2.5/weather', + dataType:'json' , + data: 'q=' + cityName + '&APPID=461bf158b2034c572293a7dfe13219a2', + success: onSuccess, + error: onError + }); +}; + +function onSuccess(weatherData){ + $('.results').css('display', 'block'); + $('.results-city').empty(); + $('.temperature').empty(); + $('.humidity').empty(); + $('.description').empty(); + $('.flag-icon').empty(); + $('.city-error').css('display', 'none'); + + var toF = parseInt(((((weatherData.main.temp)-273.15)*1.8)+32)); + console.dir(toF); + $('.results-city').append(weatherData.name + ", " + weatherData.sys.country); + $('.temperature').append(toF + '°'); + $('.humidity').append(weatherData.main.humidity); + $('.description').append("Condition Outside: " + weatherData.weather[0].main); + $('.flag-icon').append(''); + // mapURL = getWeatherMap(weatherData.coord.lon, weatherData.coord.lat) + // console.log(mapURL); + // $('body').css("backgroundImage", mapURL); +}; + +function onError(){ + $('.results').css('display', 'none'); + + $('.city-error').css('display', 'inline-block'); + $('.city-error').css('color', 'red'); + console.log('dangit'); +}; + +function getWeatherMap(x, y){ + // thisMap = 'http://tile.openweathermap.org/map/clouds_new/' + '6' + '/' + x + '/' + y + '.png?appid=' + '461bf158b2034c572293a7dfe13219a2'; + thisMap = 'http://tile.openweathermap.org/map/clouds_new/6/-97.74/30.37.png?appid=461bf158b2034c572293a7dfe13219a2' + console.log(thisMap) + $.ajax({ + method: 'GET', + url: thisMap, + dataType:'json' , + // data: 'q=' + cityName + '&APPID=461bf158b2034c572293a7dfe13219a2', + success: mapSuccess, + // error: onError + }); + function mapSuccess(mapData){ + console.log(mapData); + console.log("here"); + }; +}; + +getWeatherMap('-97.74', '30.37');