-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
40 lines (30 loc) Β· 977 Bytes
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
// Init Storage
const storage = new Storage();
//get stored location data
const weatherLocation = storage.getLocationData();
//Init weather object
const weather = new Weather(weatherLocation.city, weatherLocation.country);
//Init UI
const ui = new UI();
//get weather on DOM load
document.addEventListener('DOMContentLoaded', getWeather);
//change location event
document.getElementById('w-change-btn').addEventListener('click', e => {
const city = document.getElementById('city').value;
const country = document.getElementById('country').value;
//change location
weather.changeLocation(city, country);
//set location in local storage
storage.setLocationData(city, country);
//get and display weather
getWeather();
//close modal
$('#locModal').modal('hide');
});
function getWeather() {
weather.getWeather()
.then(results => {
ui.paint(results)
.catch(err => console.log(err))
});
}