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
186 changes: 186 additions & 0 deletions css/style.css
Original file line number Diff line number Diff line change
@@ -1 +1,187 @@
/* Custom CSS goes here */

html {
display:table;
width:100%;
}

body {
text-align: center;
background-size: cover;
}

main {
display: block;
font-family: 'Raleway', sans-serif;
margin: 50px auto;
color: white;
line-height: 1.5;
font-size: 115%;
}

#btn {
background: #3B84F9;
color: white;
height: 30px;
width: 110px;
border: none;
font-weight: 700;
text-shadow: none;
font-size: 14px;
}

#btn:hover {
background: #5E9AFA;
}

.weather-city {
color: #939393;
}

h2 .results-city {
font-weight: 700 !important;
}

.temperature-container, .humidity-container {
visibility: hidden;
}

.row {
/*visibility: hidden;*/
margin-top: 30px;
}

footer {
position: fixed;
width: 100%;
background-color: rgba(0,0,0,.3);
padding: 10px 0;
}

footer, a {
color: white;
}

a {
font-weight: bold;
}

a:hover {
color: grey;
text-decoration: none;
}

/*it's icon time*/
.icon {
visibility: hidden;
position: relative;
display: inline-block;
width: 12em;
height: 10em;
font-size: .5em; /* control icon size here */
}

.sun {
position: absolute;
top: 50%;
left: 50%;
width: 2.5em;
height: 2.5em;
margin: -1.25em;
background: currentColor;
border-radius: 50%;
box-shadow: 0 0 0 0.375em #fff;
animation: spin 12s infinite linear;
}
.rays {
position: absolute;
top: -2em;
left: 50%;
display: block;
width: 0.375em;
height: 1.125em;
margin-left: -0.1875em;
background: #fff;
border-radius: 0.25em;
box-shadow: 0 5.375em #fff;
}
.rays:before,
.rays:after {
content: '';
position: absolute;
top: 0em;
left: 0em;
display: block;
width: 0.375em;
height: 1.125em;
transform: rotate(60deg);
transform-origin: 50% 3.25em;
background: #fff;
border-radius: 0.25em;
box-shadow: 0 5.375em #fff;
}
.rays:before {
transform: rotate(120deg);
}

/* Animations */

@keyframes spin {
100% { transform: rotate(360deg); }
}

@keyframes cloud {
0% { opacity: 0; }
50% { opacity: 0.3; }
100% {
opacity: 0;
transform: scale(0.5) translate(-200%, -3em);
}
}

@keyframes rain {
0% {
background: #0cf;
box-shadow:
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
-1.375em -0.125em 0 #0cf;
}
25% {
box-shadow:
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
-0.875em 1.125em 0 -0.125em #0cf,
-1.375em -0.125em 0 rgba(255,255,255,0.2);
}
50% {
background: rgba(255,255,255,0.3);
box-shadow:
0.625em 0.875em 0 -0.125em #0cf,
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
-1.375em -0.125em 0 rgba(255,255,255,0.2);
}
100% {
box-shadow:
0.625em 0.875em 0 -0.125em rgba(255,255,255,0.2),
-0.875em 1.125em 0 -0.125em rgba(255,255,255,0.2),
-1.375em -0.125em 0 #0cf;
}
}

@keyframes lightning {
45% {
color: #fff;
background: #fff;
opacity: 0.2;
}
50% {
color: #0cf;
background: #0cf;
opacity: 1;
}
55% {
color: #fff;
background: #fff;
opacity: 0.2;
}
}
26 changes: 21 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,21 @@
<head>
<meta charset="utf-8">
<title>Mini Weather App</title>
<link rel="stylesheet" href="css/style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/normalize/7.0.0/normalize.min.css" integrity="sha256-HxaKz5E/eBbvhGMNwhWRPrAR9i/lG1JeT4mD6hCQ7s4=" crossorigin="anonymous" />
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<link href="https://fonts.googleapis.com/css?family=Raleway:400,700" rel="stylesheet" type="text/css">
<link rel="stylesheet" href="css/style.css">
</head>
<body>
<body background="https://static.pexels.com/photos/125457/pexels-photo-125457.jpeg" id='backgroundChameleon'>

<main class="weather-app container">

<div class="row form-row">
<div class="col-md-4 col-md-offset-4">
<h1 class="title">Weather App</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="submit" value="Get Weather" id="btn">
<p class="city-error" style="display:none;">Whoops! Looks like that city doesn't exist, try another one.</p>
</form>
</div>
Expand All @@ -25,6 +28,13 @@ <h1 class="title">Weather App</h1>

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

<!-- just placeholder for now, eventually want to
add icons that match weather description -->
<div class="icon sunny">
<div class="sun">
<div class="rays"></div>
</div>
</div>

<div class="temperature-container">
<span class="temperature-label"><strong>Temperature: </strong></span>
Expand All @@ -43,8 +53,14 @@ <h2 class="results-city"></h2>

</div>
</div>

</main>
<footer>
created by: karl meowski.
<br>
find me on <a href="#">linkedin</a>, <a href="#">github</a>, or <a href="https://twitter.com/diskokarl">twitter</a>.
<br>
<a href="https://codepen.io/joshbader/pen/EjXgqr">shout out to josh bader for weather icons</a>
</footer>
<script src="js/jquery.min.js"></script>
<script src="js/main.js"></script>
</body>
Expand Down
88 changes: 88 additions & 0 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1 +1,89 @@
/* Javascript goes here! */
console.log('is your script running? better go catch it!');

$(document).ready(function(){
console.log('ready');

//I DONT KNOW WHAT TO DO TO MAKE MY WEBSITE DELETE OLD STUFF ON ENTRY!!!

Choose a reason for hiding this comment

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

You can try to just clear out the text in those inputs by setting it to an empty string $(input).text('').

Copy link
Author

@karla-moreno karla-moreno Sep 29, 2017

Choose a reason for hiding this comment

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

that worked; thank you. i tried my .remove() functions again, and apparently they work now 😄

edit: i lied, something is wrong with them.. i'll try both in the future.

$('form').submit(function(event) {
event.preventDefault();
$('.results-city').text('');
$('.temperature').text('');
$('.humidity').text('');
$('.description').text('');

// NOTE: tried using $('.class-name').remove(); to achieve
// the same result, but they weren't working properly
// need to dig in more

requestWeatherData();
});
});

function requestWeatherData(){
console.log('requesting data...');
$.ajax({
method: 'GET',
url: 'http://api.openweathermap.org/data/2.5/weather',
data: $('form').serialize() + '&units=imperial&appid=a77765c844f61df44fe43412c991b9cf',

Choose a reason for hiding this comment

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

Since you are serializing the form, you can also add two hidden inputs for appid and units to the form to be included instead of writing them out by hand here.

dataType: 'json',
success: onSuccess,
error: onError
})
}

function onSuccess(data) {
console.log('success. proceed.');
$('.city-error').css('display', 'none');
displayCityAndIcon(data);
displayTemp(data);
displayHumid(data);
displayDescription(data);
}

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

function ifInvalidEntry(data){

}


// error 403 forbidden for img :'(
function displayCityAndIcon(data){
var cityName = String(data.name);

Choose a reason for hiding this comment

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

This works, but it's unnecessary since the data.name returned is already a string.

// var iconID = String(data.weather[0].icon);
// var img = '<img src="http://openweathermap.org/img/w/" + iconID +".png">';
// console.log(iconID);
// console.log(img);
// $('.icon').append(img);
$('.icon').css('visibility', 'visible');
$('.results-city').append(cityName);
}

function displayTemp(data){
var temp = parseFloat(data.main.temp);
console.log(temp);
$('.temperature-container').css('visibility', 'visible');
$('.temperature').append(temp + String.fromCharCode(176) + "F");

Choose a reason for hiding this comment

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

Nice find!! This would be a good spot to have a comment to let others know what the code is for.

Copy link
Author

Choose a reason for hiding this comment

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

for the styling, temperature format when append'ed to html, or both?

}

function displayHumid(data){
var humidity = parseFloat(data.main.humidity);
console.log(humidity);
$('.humidity-container').css('visibility', 'visible');
$('.humidity').append(humidity + '%');
}

function displayDescription(data){
var description = String(data.weather[0].description);
$('.description').append('The weather is currently: ' + description + '.');
}


//NOTE: (WIP) this function will eventually change based on the description of the city's weather
// function changeBackground(){
//
// }