Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 55 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,56 @@
/* Custom CSS goes here */
body {
text-align: center;
}

h1, h2 {
font-family: 'Montserrat', sans-serif;
letter-spacing: 3px;
}

h1 {
padding: 15px;
font-size: 200px;
}

h2 {
font-size: 50px;;
}

form {
padding: 15px;
}

span {
font-family: 'Open Sans', sans-serif;
}

.container {
border: 3px solid #76A0E6;
box-shadow: 2px 2px 7px black;
width: 80%;
padding-bottom: 50px;
border-radius: 5px;
}

.weather-city {
width: 200px;
height: 40px;
border-radius: 5px;
font-family: 'Open Sans', sans-serif;
}

.submit-button {
font-family: 'Open Sans', sans-serif;
border: none;
background-color: #FFA8A8;
width: 100px;
height: 35px;
border-radius: 5px;
}

.submit-button:hover {
background-color: #FF7474;
}


12 changes: 8 additions & 4 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
<head>
<meta charset="utf-8">
<title>Mini Weather App</title>
<link href="https://fonts.googleapis.com/css?family=Montserrat|Open+Sans" rel="stylesheet">
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
</head>
Expand All @@ -11,10 +12,11 @@

<div class="row form-row">
<div class="col-md-4 col-md-offset-4">
<h1 class="title">Weather App</h1>
<h1 class="title">WEATHER TRACKER</h1>
<form class="getWeatherData">
<input type="text" class="weather-city" placeholder="Enter a city.."/>
<input type="submit" value="Get Weather">
<input type="text" class="weather-city" name="q" placeholder="Enter a city.."/>
<input type="hidden" name="appid" value="f44e9d4e81fbd380f38ccb737f016c30">
<input type="submit" value="Get Weather" class="submit-button">
<p class="city-error" style="display:none;">Whoops! Looks like that city doesn't exist, try another one.</p>
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of setting this as an inline style, simply add a "hidden" class and then toggle the class instead of the style with js when you need it to show.

</form>
</div>
Expand All @@ -23,9 +25,11 @@ <h1 class="title">Weather App</h1>
<div class="row">
<div class="col-md-4 col-md-offset-4 results">

<h2 class="results-city"></h2>
<div class="flag-container"></div>

<h2 class="results-city"></h2>

<div class="icon-container"></div>
<div class="temperature-container">
<span class="temperature-label"><strong>Temperature: </strong></span>
<span class="temperature"></span>
Expand Down
39 changes: 39 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,40 @@
/* Javascript goes here! */
$(document).ready(function () {

$('.getWeatherData').on('submit', e => {

e.preventDefault();


$.ajax({

method: 'GET',
url: 'http://api.openweathermap.org/data/2.5/weather',
data: $('form').serialize() + ('&units=imperial'),
dataType: 'json',
success: onSuccess,
error: onError

})
});

});


function onSuccess(returnData) {

$('.city-error').css('display', 'none');
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be where you toggle the class instead of adjusting the CSS.

var imgSource = `http://openweathermap.org/img/w/${returnData.weather[0].icon}.png`;
var country = returnData.sys.country.toLowerCase();

$('.results-city').html(returnData.name);
$('.temperature').html(returnData.main.temp);
$('.humidity').html(returnData.main.pressure);
$('.description').html(returnData.weather[0].description);
$('.icon-container').html(`<img src=${imgSource}>`);
$('.flag-container').html(`<span class="flag-icon flag-icon-${country}"></span>`);
}

function onError() {
$('.city-error').css('display', 'block');
}
Loading