-
Notifications
You must be signed in to change notification settings - Fork 0
/
piz.js
176 lines (105 loc) · 4.11 KB
/
piz.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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
var weatherContainer = document.getElementById('weather');
var homeButton = document.getElementById('homeBtn');
// time:
const format2 = "YYYY-MM-DD"
var date2 = new Date();
dateTime2 = moment(date2).format(format2);
document.getElementById("demo2").innerHTML = "As of :"+"" +dateTime2;
homeButton.addEventListener('click', function(e){
console.log("test")
window.location = "index.html";
});
var menuButton = document.getElementById('menuBtn');
menuButton.addEventListener('click', function(e){
console.log("test")
window.location ="menu.html";
});
// get checked value from checkbox:
var addBtn = document.getElementById('add')
var textEl =document.getElementById('text1')
addBtn.addEventListener('click', printChecked)
function printChecked() {
var items = document.getElementsByName("acs");
var selectedItems = " ";
for (var i = 0; i < items.length; i++) {
if (items[i].type == "checkbox" && items[i].checked == true) selectedItems += items[i].value + "\n";
}
localStorage.setItem('selected',JSON.stringify(selectedItems) );
}
// weather
function getApiW(){
fetch('https://api.openweathermap.org/data/2.5/weather?lat=40&lon=-75&appid=6939a1ebe83748be1cc4bbe471aef1a9&units=imperial')
.then(function(response){
return response.json();
})
.then(function(data){
console.log(data);
var wthEl = document.createElement('h2');
wthEl.setAttribute('style', ' display: block;font-size: 3.5rem;line-height: .96em;font-weight: 500;');
wthEl.textContent =data.main.temp+"°";
weatherContainer.append(wthEl);
})
}
getApiW();
// Geolocation:
var locationEl = document.getElementById('submitOrder')
var newDiv = document.getElementById('myLocation')
function getApiGeo(){
locationEl.addEventListener('click', ()=>{
navigator.geolocation.getCurrentPosition(data =>{
console.log(data);
},(error)=>console.log(error))
});
function success(data){
var api_key = '8cf6f7e105304f8c975adee408dc60d8';
var latitude = data.coords.latitude;
var longitude = data.coords.longitude;
var api_url = 'https://api.opencagedata.com/geocode/v1/json'
var request_url = api_url
+ '?'
+ 'key=' + api_key
+ '&q=' + encodeURIComponent(latitude + ',' + longitude)
+ '&pretty=1'
+ '&no_annotations=1';
// see full list of required and optional parameters:
// https://opencagedata.com/api#forward
var request = new XMLHttpRequest();
request.open('GET', request_url, true);
request.onload = function() {
// https://opencagedata.com/api#codes
if (request.status === 200){
// Success!
var data = JSON.parse(request.responseText);
// replace alert by an Element tag
// lets store the address and use it for confirmation.
var address =data.results[0].formatted;
localStorage.setItem('Address',JSON.stringify(address));
} else if (request.status <= 500){
console.log("unable to geocode! Response code: " + request.status);
var data = JSON.parse(request.responseText);
console.log('error msg: ' + data.status.message);
} else {
console.log("server error");
}
};
request.onerror = function() {
// There was a connection error of some sort
console.log("unable to connect to server");
};
request.send(); // make the request
}
navigator.geolocation.getCurrentPosition(success, console.error);
}
getApiGeo();
// get User location
var enterLocation = document.getElementById('submitOrder');
enterLocation.addEventListener('click',getloc);
function getloc(){
var addresEl = document.getElementById('adress')
addresEl.innerHTML = "Delivered To :"+ ''+ JSON.parse(localStorage.getItem('Address'));
textEl.innerHTML =JSON.parse(localStorage.getItem('selected'))
var customer =document.getElementById('customerName')
customer.innerHTML =JSON.parse(localStorage.getItem('name'))
var customerPhone = document.getElementById('customerPhone');
customerPhone.innerHTML = JSON.parse(localStorage.getItem('phone'));
}