-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
34 lines (31 loc) · 1.17 KB
/
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
//initialize storage class object
const storage = new Storage();
//get stored location, or application's default location
const storedLocation = storage.getLocation();
//initialize weather class object and pull param val from storage
const weather = new Weather(storedLocation.city, storedLocation.state);
//initialize ui class object, grab elements from page for populating later with weather data.
const ui = new UI();
//load weather when page loads
document.addEventListener('DOMContentLoaded', getWeather);
//change location event from modal
document.getElementById('w-change-btn').addEventListener('click', (e) => {
//get city and state values from modal
const city = document.getElementById('city').value;
const state = document.getElementById('state').value;
//change location
weather.changeLocation(city, state);
//get weather after location change
getWeather();
//store new location in local storage
storage.setLocation(city, state);
//close modal (uses jquery because of bootstrap)
$('#locationModal').modal('hide');
})
function getWeather() {
weather.getWeather()
.then(results => {
ui.populate(results)
})
.catch(error => console.log(error));
}