-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.js
219 lines (188 loc) · 6.13 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
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
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
var firebaseConfig = {
apiKey: "AIzaSyDvi6sKh_qzltWQijYoIlupmikcrvhhwSw",
authDomain: "uniproject-be097.firebaseapp.com",
databaseURL: "https://uniproject-be097.firebaseio.com",
projectId: "uniproject-be097",
storageBucket: "uniproject-be097.appspot.com",
messagingSenderId: "1050631639916",
appId: "1:1050631639916:web:af5059742a70bcc1505949",
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
var db = firebase.firestore();
const hamburger = document.querySelector(".fas.fa-bars");
const ul = document.querySelector("ul");
const logOutBtn = document.querySelector(".logOut");
const infoIcon = document.querySelector(".fas.fa-info-circle");
const infoAboutObject = document.querySelector(".info");
const closeInfo = document.querySelector(".fas.fa-times");
const mainDiv = document.querySelector("main");
const renderTest = document.querySelector(".renderTest");
const searchBar = document.querySelector(".searchBar");
const popUpFinder = document.querySelector('.modal-iframe');
const mapFrame = document.querySelector('.mapFrame');
// Hamburger
function expand() {
ul.classList.toggle("active");
}
hamburger.addEventListener("click", expand);
function logOut() {
console.log("dziala");
firebase
.auth()
.signOut()
.then(() => {
window.location.href = "index.html";
})
.catch((e) => {
console.error("Sign Out Error", e);
});
}
logOutBtn.addEventListener("click", logOut);
// Expand info div
function moreInfo(clickedElement, openInfo) {
clickedElement.addEventListener("click", () => {
openInfo.classList.add("active");
});
}
//Close info div
function lessInfo(closeIcon, closeInfo) {
closeIcon.addEventListener("click", () =>
closeInfo.classList.remove("active")
);
}
//Render cards
function renderCards(doc) {
const card = document.createElement("div");
card.className = "card";
mainDiv.appendChild(card);
const cardImage = document.createElement("div");
cardImage.className = "cardImage";
card.appendChild(cardImage);
const image = document.createElement("img");
image.setAttribute("src", doc.data().img);
cardImage.appendChild(image);
const cardTitle = document.createElement("div");
cardTitle.className = "cardTitle";
card.appendChild(cardTitle);
const h2 = document.createElement("h2");
h2.textContent = doc.data().name;
cardTitle.appendChild(h2);
const textAndIcons = document.createElement("div");
textAndIcons.className = "textAndIcons";
cardTitle.appendChild(textAndIcons);
const firstIcon = document.createElement("i");
firstIcon.className = "fas fa-map-marker-alt";
textAndIcons.appendChild(firstIcon);
firstIcon.addEventListener('click',()=> {
console.log('dziala');
const close = document.querySelector('.closeMap');
console.log(close);
popUpFinder.classList.add('active');
mapFrame.setAttribute("src",doc.data().map);
close.addEventListener('click',()=>{
popUpFinder.classList.remove('active');
})
console.log(doc.data().map);
})
const secondIcon = document.createElement("i");
secondIcon.className = "fas fa-info-circle";
textAndIcons.appendChild(secondIcon);
const info = document.createElement("div");
info.className = "info";
card.appendChild(info);
moreInfo(secondIcon, info);
const firstP = document.createElement("p");
firstP.textContent = `City: ${doc.data().city}`;
info.appendChild(firstP);
const secondP = document.createElement("p");
secondP.textContent = `Region: ${doc.data().region}`;
info.appendChild(secondP);
const thirdP = document.createElement("p");
thirdP.textContent = `Code: ${doc.data().postalcode}`;
info.appendChild(thirdP);
const fourthP = document.createElement("p");
fourthP.textContent = `Address: ${doc.data().address}`;
info.appendChild(fourthP);
const lastIcon = document.createElement("i");
lastIcon.className = "fas fa-times";
info.appendChild(lastIcon);
lessInfo(lastIcon, info);
}
// Function filter
function findAndFilter(e) {
let inputValue = e.target.value.toLowerCase();
if (
inputValue === "odessa" ||
inputValue === "kharkiv" ||
inputValue === "chernivtsi" ||
inputValue === "kiev" ||
inputValue === "lviv"
) {
findCity(
"Ukraine",
inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase()
);
} else if (inputValue === "") mainDiv.innerHTML = "";
if (inputValue === "warsaw" || inputValue === "krakow") {
findCity(
"Poland",
inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase()
);
} else if (inputValue === "") mainDiv.innerHTML = "";
if (inputValue === "moscov" || inputValue === "saint petersburg") {
findCity(
"Russia",
inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase()
);
} else if (inputValue === "") mainDiv.innerHTML = "";
if (
inputValue === "dresden" ||
inputValue === "berlin" ||
inputValue === "munich"
) {
findCity(
"Deutschland",
inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase()
);
} else if (inputValue === "") mainDiv.innerHTML = "";
if (inputValue === "barcelona" || inputValue === "granada") {
findCity(
"Spain",
inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase()
);
} else if (inputValue === "") mainDiv.innerHTML = "";
if (
inputValue === "ukraine" ||
inputValue === "poland" ||
inputValue === "russia" ||
inputValue === "spain"
) {
showCounty(inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase());
}
if (inputValue === "germany") {
inputValue = "deutschland";
showCounty(inputValue[0].toUpperCase() + inputValue.slice(1).toLowerCase());
}
}
searchBar.addEventListener("input", findAndFilter);
//Order by city name
function findCity(country, city) {
console.log(`${country} i ${city}`);
var order = db.collection(country).where("city", "==", city);
order.get().then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
renderCards(doc);
});
});
}
//Order by country name
function showCounty(country) {
db.collection(country)
.get()
.then(function (querySnapshot) {
querySnapshot.forEach(function (doc) {
renderCards(doc);
});
});
}