-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Header created. Event listenter added to search button. API call created
- Loading branch information
Alejandro Gonzalvez
authored and
Alejandro Gonzalvez
committed
Jun 5, 2021
1 parent
878745c
commit d864a3b
Showing
3 changed files
with
144 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
let lat; | ||
let lon; | ||
let searchButton = document.querySelector('#searchBtn'); | ||
let searchInput; | ||
|
||
|
||
// Search bar function | ||
function handleSearchFormSubmit(event) { | ||
event.preventDefault(); | ||
searchInput = document.querySelector('.form-control').value; | ||
console.log(searchInput) | ||
|
||
if (!searchInput) { | ||
console.error('You need to enter a city!'); | ||
return; | ||
} | ||
|
||
getWeather(); | ||
} | ||
|
||
//Search button event listener | ||
searchButton.addEventListener('click', handleSearchFormSubmit); | ||
|
||
|
||
//Geolocation | ||
|
||
// function getLocation() { | ||
// if (navigator.geolocation) { | ||
// navigator.geolocation.getCurrentPosition(showPosition); | ||
// } else { | ||
// console.log("cant get coordinates") | ||
// } | ||
// } | ||
// function showPosition(position) { | ||
// lat = position.coords.latitude; | ||
// lon = position.coords.longitude; | ||
// console.log(lat, lon) | ||
|
||
// } | ||
// getLocation(); | ||
|
||
// One Call API Call | ||
|
||
function getWeather() { | ||
let openWeather = 'api.openweathermap.org/data/2.5/weather?q={city name}&appid={7a9e308d5f5da317f65c95353cf68b30}' + searchInput; | ||
console.log(openWeather) | ||
$.ajax({ | ||
'url': openWeather, | ||
'method': 'GET', | ||
'timeout': 0, | ||
'headers': { | ||
'Content-Type': 'application/json', | ||
} | ||
}) | ||
}; | ||
|
||
|
||
// + '&latitude=' + lat + '&longitude=' + lon |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
.b-example-divider { | ||
height: 3rem; | ||
background-color: rgba(0, 0, 0, .1); | ||
border: solid rgba(0, 0, 0, .15); | ||
border-width: 1px 0; | ||
box-shadow: inset 0 .5em 1.5em rgba(0, 0, 0, .1), inset 0 .125em .5em rgba(0, 0, 0, .15); | ||
} | ||
|
||
.form-control-dark { | ||
color: #fff; | ||
background-color: var(--bs-dark); | ||
border-color: var(--bs-gray); | ||
} | ||
.form-control-dark:focus { | ||
color: #fff; | ||
background-color: var(--bs-dark); | ||
border-color: #fff; | ||
box-shadow: 0 0 0 .25rem rgba(255, 255, 255, .25); | ||
} | ||
|
||
.bi { | ||
vertical-align: -.125em; | ||
fill: currentColor; | ||
} | ||
|
||
.text-small { | ||
font-size: 85%; | ||
} | ||
|
||
.dropdown-toggle { | ||
outline: 0; | ||
} | ||
|