Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Jose & Alex #4

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
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
68 changes: 68 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//const weatherReqkey= 'http://api.openweathermap.org/data/2.5/weather?q=london&APPID=b7aecc81c3f01e1eadcb367a666606c4';
//const imagesReqKey='https://api.unsplash.com/search/photos?query=snow&client_id=217d39354a152114b5bb4e0f77e4ca3c7ecdbe155bb9d43580e11138def7915a';


//const goButton = document.querySelector('.btn');
const search = document.querySelector('#search');
const foreCast = document.querySelector('#conditions');
const smallPictures = document.querySelector('.thumbs');
const largeImage = document.querySelector('.photo');

//////get weather info//////////////////////////////////
function getWeather(city){
fetch(`http://api.openweathermap.org/data/2.5/weather?q=${city}&APPID=b7aecc81c3f01e1eadcb367a666606c4`)
.then(function(response){
return response.json();
})
.then(function(data){
//console.log(data);
const weatherDesc = data.weather[0].description;
const temperature = data.main.temp;
foreCast.textContent= `${weatherDesc} ${temperature} `;
getImage(weatherDesc);

})
.catch(function(error){
console.log(error);
});
};

////////second function get images////////////////////////
function getImage(weatherCondition){

fetch(`https://api.unsplash.com/search/photos?query=${weatherCondition}&client_id=217d39354a152114b5bb4e0f77e4ca3c7ecdbe155bb9d43580e11138def7915a`)
.then(function(response){
return response.json();
})
.then(function(data){
//console.log(data);
const ourImagesData = data.results;
//console.log(ourImagesData);
smallPictures.innerHTML= ourImagesData.map(function(element){
return `<a href=${element.urls.regular} class='thumbs__link'><img src=${element.urls.thumb} class='thumbs__link__img'/></a>`

})

})
.catch(function(error){
console.log(error);
});

};
////event listener/////////////////////////////////
search.addEventListener('submit', function(event) {
event.preventDefault();
//console.log(event.target.city.value);
getWeather(event.target.city.value);
});

//////event get the picture from thumb and add to photo section /////////
smallPictures.addEventListener('click',function(event){
if(event.target.className !== 'thumbs__link') //prevent to click on different area
return
const test=event.target.getAttribute('href');
event.preventDefault();
//console.log(event.target.className);
largeImage.innerHTML=`<img src=${test}/>`

})
89 changes: 46 additions & 43 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,49 +1,52 @@
<!DOCTYPE html>
<html lang="en">

<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Meteoropolis</title>
<link rel="stylesheet" href="assets/globals.css">
<link rel="stylesheet" href="assets/styles.css">
</head>

<body>
<!-- Structure -->
<main class="content">
<header class="header">
<h1 class="title">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Meteoropolis</title>
<link rel="stylesheet" href="assets/globals.css">
<link rel="stylesheet" href="assets/styles.css">
</head>

<body>
<!-- Structure -->
<main class="content">
<header class="header">
<h1 class="title">
<i>Meteor</i>
<i>opolis</i>
</h1>
</header>

<figure class="photo" id="photo"></figure>

<div class="info">
<p class="info__item info__item--conditions" id="conditions"></p>
<p class="info__item info__item--credits">
<a href="#" id="credit-user"></a>
<span>on</span>
<a href="#" id="credit-platform">Unsplash</a>
</p>
</div>

<div class="thumbs" id="thumbs"></div>

<div class="controls">
<form class="search" id="search">
<label class="search__label" for="search-tf">City</label>
<input class="search__input" id="search-tf" name="city" placeholder="Enter city name" autocomplete="city" />
<button class="btn search__btn">Go</button>
</form>
</div>
</main>

<!-- JS goes here -->
</body>

</html>
</header>

<figure class="photo" id="photo"></figure>

<div class="info">
<p class="info__item info__item--conditions" id="conditions"></p>
<p class="info__item info__item--credits">
<a href="#" id="credit-user"></a>
<span>on</span>
<a href="#" id="credit-platform">Unsplash</a>
</p>
</div>

<div class="thumbs" id="thumbs"></div>

<div class="controls">
<form class="search" id="search">
<label class="search__label" for="search-tf">City</label>
<input class="search__input" id="search-tf" name="city" placeholder="Enter city name" autocomplete="city" />
<button class="btn search__btn">Go</button>
</form>
</div>
</main>

<!-- JS goes here -->
<script src='app.js'> </script>
</body>



</html>