-
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.
Has basic features of denoting weather via image, temperature and depicts the location using navigator.
- Loading branch information
1 parent
6af7a28
commit 119b659
Showing
22 changed files
with
216 additions
and
0 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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,37 @@ | ||
<!DOCTYPE html> | ||
<!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]--> | ||
<!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]--> | ||
<!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]--> | ||
<!--[if gt IE 8]> <html class="no-js"> <!--<![endif]--> | ||
<html> | ||
<head> | ||
<meta charset="utf-8"> | ||
<title>Weather App</title> | ||
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Domine&display=swap"> | ||
<link rel="stylesheet" href="styling/style.css" > | ||
</head> | ||
<body> | ||
<div class="container"> | ||
<div class="app-title"> | ||
<p>Weather</p> | ||
</div> | ||
<div class="notification"></div> | ||
<div class="weather-container"> | ||
<div class="weather-icon"> | ||
<img src="icons/unknown.png" alt=""> | ||
</div> | ||
<div class="temperature-value"> | ||
<p>- *<span>C</span></p> | ||
</div> | ||
<div class="temperature-description"> | ||
<p>-</p> | ||
</div> | ||
<div class="location"> | ||
<p>-</p> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<script src="script.js"></script> | ||
</body> | ||
</html> |
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,71 @@ | ||
//select elements | ||
|
||
const iconElement = document.querySelector(".weather-icon"); | ||
const tempElement = document.querySelector(".temperature-value p"); | ||
const descElement = document.querySelector(".temperature-description p"); | ||
const locationElement = document.querySelector(".location p"); | ||
const notificationElement = document.querySelector(".notification"); | ||
|
||
//App data | ||
const weather = {}; | ||
|
||
weather.temperature = { | ||
unit : "celsius" | ||
} | ||
|
||
//app consts and vars | ||
const KELVIN = 273; | ||
//API KEY | ||
const key = "5a8832e4b680a91e82968e34fedc063a"; | ||
|
||
//check if browser supports geo-location | ||
if('geolocation' in navigator){ | ||
navigator.geolocation.getCurrentPosition(setPosition, showError); | ||
} | ||
else{ | ||
notificationElement.style.display = "block"; | ||
notificationElement.innerHTML = "<p> Browser does not support geolocation</p>"; | ||
} | ||
|
||
//set user's position | ||
function setPosition(position){ | ||
let latitude = position.coords.latitude; | ||
let longitude = position.coords.longitude; | ||
|
||
getWeather(latitude, longitude); | ||
} | ||
|
||
// show error when there is any issue with geolocation service | ||
function showError(error){ | ||
notificationElement.style.display = "block"; | ||
notificationElement.innerHTML = `<p> ${error.message} </p>` | ||
} | ||
|
||
//Get weather from API provider | ||
function getWeather(latitude, longitude){ | ||
let api=`https://api.openweathermap.org/data/2.5/weather?lat=${latitude}&lon=${longitude}&appid=${key}`; | ||
|
||
fetch(api) | ||
.then(function(response){ | ||
let data = response.json(); | ||
return data; | ||
}) | ||
.then(function(data){ | ||
weather.temperature.value = Math.floor(data.main.temp - KELVIN); | ||
weather.description = data.weather[0].icon; | ||
weather.iconId = data.weather[0].icon; | ||
weather.city = data.name; | ||
weather.country = data.sys.country; | ||
}) | ||
.then(function(){ | ||
displayWeather(); | ||
}); | ||
} | ||
|
||
//Display weather to UI | ||
function displayWeather(){ | ||
iconElement.innerHTML = `<img src="icons/${weather.iconId}.png">`; | ||
tempElement.innerHTML = `${weather.temperature.value}*<span>C</span>`; | ||
descElement.innerHTML = weather.description; | ||
locationElement.innerHTML = `${weather.city}, ${weather.country}`; | ||
} |
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,108 @@ | ||
*{ | ||
font-family: 'Domine', serif; | ||
} | ||
|
||
body{ | ||
background-color: #293251; | ||
} | ||
|
||
.container{ | ||
width: 300px; | ||
background-color: #FFF; | ||
|
||
display: block; | ||
margin: 0 auto; | ||
|
||
border-radius: 10px; | ||
padding-bottom : 50px; | ||
} | ||
|
||
.app-title{ | ||
width: 300px; | ||
height: 50px; | ||
border-radius: 10px 10px 0 0; | ||
} | ||
|
||
.app-title p{ | ||
text-align: center; | ||
padding: 15px; | ||
margin: 0 auto; | ||
font-size: 1.2em; | ||
color: #293251; | ||
} | ||
|
||
.notification{ | ||
background-color: #f8d7da; | ||
display: none; | ||
} | ||
|
||
.notification p{ | ||
color: #721c24; | ||
font-size: 1.2em; | ||
margin: 0; | ||
text-align: center; | ||
padding: 10px 0; | ||
} | ||
|
||
.weather-container{ | ||
width: 300px; | ||
height: 260px; | ||
background-color: #F4F9FF; | ||
} | ||
|
||
.weather-icon{ | ||
width: 300px; | ||
height: 128px; | ||
} | ||
|
||
.weather-icon img{ | ||
display: block; | ||
margin: 0 auto; | ||
} | ||
|
||
.temperature-value{ | ||
width: 300px; | ||
height:60px; | ||
} | ||
|
||
.temperature-value p{ | ||
padding: 0; | ||
margin: 0; | ||
color: #293251; | ||
font-size: 4em; | ||
text-align: center; | ||
cursor: pointer; | ||
} | ||
|
||
.temperature-value p:hover{ | ||
|
||
} | ||
|
||
.temperature-value span{ | ||
color: #293251; | ||
font-size: 0.5em; | ||
} | ||
|
||
.temperature-description{ | ||
|
||
} | ||
|
||
.temperature-description p{ | ||
padding: 8px; | ||
margin: 0; | ||
color: #293251; | ||
text-align: center; | ||
font-size: 1.2em; | ||
} | ||
|
||
.location{ | ||
|
||
} | ||
|
||
.location p{ | ||
margin: 0; | ||
padding: 0; | ||
color: #293251; | ||
text-align: center; | ||
font-size: 0.8em; | ||
} |