-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
108 lines (103 loc) · 3.86 KB
/
main.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
const maltaTime = document.getElementById('mt-hr');
const swissTime = document.getElementById('ch-hr');
const belgianTime = document.getElementById('be-hr');
const brazilTime = document.getElementById('br-hr');
const italyTime = document.getElementById('it-hr');
function calcTime(offset){
// called as a constructor, it returns a new Date object (acc to local machine)
let d = new Date();
console.log(d);
// getTime() method returns the number of ms since the Unix epoch (e.g. 1625583448306)
// getTimezoneOffset() method returns the difference between a date evaluated in the UTC time zone and the same date as evaluated in the local time zone.
let utc = d.getTime() + (d.getTimezoneOffset() * 1000);
console.log(utc);
let nd= new Date(utc + (3600000*offset));
let hours = nd.getHours();
let minutes = nd.getMinutes();
return `${hours} : ${minutes}`;
}
maltaTime.textContent = `${calcTime('+5')}`;
swissTime.textContent = `${calcTime('+5')}`;
belgianTime.textContent = `${calcTime('+5')}`;
italyTime.textContent = `${calcTime('+5')}`;
brazilTime.textContent = `${calcTime('0')}`;
function allowDrop(event){
console.log('allowdrop');
event.preventDefault();
}
function drag(event){
console.log('drag');
const boxGrid = document.querySelector('.boxes');
event.currentTarget.style.border = '4px yellow solid';
boxGrid.style.border = '4px black dashed';
event.dataTransfer.setData('text', event.target.id);
}
function drop(event){
event.preventDefault();
var data = event.dataTransfer.getData('text');
thisdiv = event.target;
$(document.getElementById(data)).insertBefore(thisdiv);
console.log('dropped');
}
window.onload = function(){
const maltaWeather = document.querySelector('.mt-weather');
const swissWeather = document.querySelector('.ch-weather');
const belgianWeather = document.querySelector('.be-weather');
const brazilianWeather = document.querySelector('.br-weather');
const italyWeather = document.querySelector('.it-weather');
const maltaDataPromise = fetch('https://goweather.herokuapp.com/weather/Sliema');
const swissDataPromise = fetch('https://goweather.herokuapp.com/weather/Zurich');
const belgianDataPromise = fetch('https://goweather.herokuapp.com/weather/Leuven');
const brazilianDataPromise = fetch('https://goweather.herokuapp.com/weather/Rio_de_janeiro');
const italianDataPromise = fetch('https://goweather.herokuapp.com/weather/Perugia');
maltaDataPromise
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data.temperature);
maltaWeather.innerText = `${data.temperature}`;
})
.catch(handleError);
swissDataPromise
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data.temperature);
swissWeather.innerText = `${data.temperature}`;
})
.catch(handleError);
belgianDataPromise
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data.temperature);
belgianWeather.innerText = `${data.temperature}`;
})
.catch(handleError);
brazilianDataPromise
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data.temperature);
brazilianWeather.innerText = `${data.temperature}`;
})
.catch(handleError);
italianDataPromise
.then((response) => {
return response.json();
})
.then((data) => {
console.log(data.temperature);
italyWeather.innerText = `${data.temperature}`;
})
.catch(handleError);
}
// Error handler
function handleError(err){
console.log("Error");
console.log(err);
}