-
Notifications
You must be signed in to change notification settings - Fork 1
/
ui.js
59 lines (52 loc) · 2.11 KB
/
ui.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
const dayName = document.querySelector('.date-dayname');
const currentDate = document.querySelector('.date-day');
const today = new Date();
let myDay = today.getDay();
let weekday = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
dayName.innerText = weekday[myDay];
var dd = String(today.getDate()).padStart(2, '0');
var yyyy = today.getFullYear();
let monthName = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
var mm = monthName[today.getMonth()];
currentDate.innerText = `${dd} ${mm} ${yyyy}`;
// Modal
const modal = document.querySelector('#myModal');
const modalBtn = document.querySelector('#locationBtn');
const closeBtn = document.querySelector('#close');
modalBtn.onclick = function () {
modal.style.display = "block";
}
closeBtn.onclick = function () {
modal.style.display = "none";
}
window.onclick = function (e) {
if (e.target == modal) {
modal.style.display = "none";
}
}
class UI {
constructor() {
this.location = document.getElementById('w-location');
this.desc = document.getElementById('w-desc');
this.string = document.getElementById('w-temp');
// this.details = document.getElementById('w-location');
this.icon = document.getElementById('w-icon');
this.humidity = document.getElementById('w-humidity');
this.feelsLike = document.getElementById('w-feels-like');
this.dewpoint = document.getElementById('w-dewpoint');
this.wind = document.getElementById('w-wind');
}
paint(weather) {
this.location.textContent = weather.name;
this.desc.textContent = weather.weather[0].description;
this.string.textContent = weather.main.temp + '°C';
this.icon.setAttribute(
'src',
`http://openweathermap.org/img/wn/${weather.weather[0].icon}@2x.png`
);
this.humidity.textContent = weather.main.humidity;
this.dewpoint.textContent = weather.visibility;
this.wind.textContent = `${weather.wind.speed} m/s`;
this.feelsLike.textContent = weather.main.feels_like;
}
}