-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
39 lines (29 loc) · 860 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
// Init storage
const storage = new Storage();
// Get stored location data
const weatherLocation = storage.getLocationData();
// Init weather object
const weather = new Weather(weatherLocation.city);
// Init UI object
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;
// Change location
weather.changeLocation(city);
// Set location in local storage
storage.setLocationData(city);
// Get and display weather
getWeather();
// Close modal using jQuery
$('#locModal').modal('hide');
})
function getWeather() {
weather.getWeather()
.then(results => {
ui.paint(results);
})
.catch(err => console.log(err));
}