-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
321 lines (296 loc) · 10.4 KB
/
script.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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
$("a[href^='#']").click(function (e) {
e.preventDefault();
$("body, html").animate(
{
scrollTop: $($(this).attr("href")).offset().top - 50,
},
750
);
});
const flipClick = (e) => {
let FlipCard = $(".flip-card");
if ($(e).hasClass("flip-active")) {
$(e).removeClass("flip-active");
} else {
FlipCard.removeClass("flip-active");
$(e).addClass("flip-active");
}
};
const navspy = () => {
var navs = $("nav ul li a");
var sec = $(".sec");
var navh = $("nav").height();
var docel = $(document);
docel.on("scroll", function () {
var scrollpos = docel.scrollTop();
sec.each(function () {
var self = $(this);
if (
self.offset().top < scrollpos + navh &&
scrollpos + navh < self.offset().top + self.outerHeight()
) {
var currClass = "." + self.attr("id") + "-mark";
navs.removeClass("active");
$(currClass).addClass("active");
}
});
});
};
const carousel = () => {
var carSlide = $(".carousel-slide");
var carImg = $(".carousel-slide img");
var next = $("#next");
var prev = $("#prev");
let count = 1;
var size = carImg.width();
carSlide.css("transform", "translateX(" + -size * count + "px)");
next.click(() => {
if (count >= carImg.length - 1) return;
console.log("next");
carSlide.css("transition", "transform 0.4s ease-in-out");
count++;
carSlide.css("transform", "translateX(" + -size * count + "px)");
});
prev.click(() => {
if (count <= 0) return;
console.log("prev");
carSlide.css("transition", "transform 0.4s ease-in-out");
count--;
carSlide.css("transform", "translateX(" + -size * count + "px)");
});
carSlide.on("transitionend", () => {
if (carImg[count].id == "lastc") {
carSlide.css("transition", "none");
count = carImg.length - 2;
carSlide.css("transform", "translateX(" + -size * count + "px)");
} else if (carImg[count].id == "firstc") {
carSlide.css("transition", "none");
count = carImg.length - count;
carSlide.css("transform", "translateX(" + -size * count + "px)");
}
});
var dropbool = false;
setInterval(() => {
if (dropbool == false) {
$(".scrollD").css("transition", "transform 0.8s ease-in-out");
$(".scrollD").css("transform", "translateY(10px)");
} else {
$(".scrollD").css("transition", "transform 0.8s ease-in-out");
$(".scrollD").css("transform", "translateY(-10px)");
}
dropbool = !dropbool;
}, 1000);
};
const navSlide = () => {
const burger = $(".burger");
const nav = $("nav ul");
const navLink = document.querySelectorAll("nav ul li");
burger.click(() => {
nav.toggleClass("nav-active");
navLink.forEach((link, index) => {
if (link.style.animation) {
link.style.animation = "";
} else {
link.style.animation = `navFade 0.5s ease forwards ${index / 7 + 0.5}s`;
}
});
});
for (var i = 0; i < navLink.length; i++) {
navLink[i].addEventListener("click", function () {
nav.toggleClass("nav-active");
navLink.forEach((link) => {
link.style.animation = "";
});
});
}
};
navspy();
carousel();
navSlide();
var countryContent = $(".country-content");
var acc = document.getElementsByClassName("country-headder");
var i;
for (i = 0; i < acc.length; i++) {
acc[i].addEventListener("click", function () {
var panel = this.nextElementSibling;
if (panel.style.maxHeight) {
panel.style.maxHeight = null;
this.children[1].style.transform = "rotate(0deg)";
} else {
for (var j = 0; j < acc.length; j++) {
if (i != j) {
acc[j].nextElementSibling.style.maxHeight = null;
acc[j].children[1].style.transform = "rotate(0deg)";
}
panel.style.maxHeight = panel.scrollHeight + "px";
this.children[1].style.transform = "rotate(90deg)";
}
}
});
}
httpRequest = new XMLHttpRequest();
httpRequest.open("GET", "https://chirayurathi.github.io/spotramenJson/db.json");
var jsonData = [];
var hotContainer = document.querySelector(".hotspots-container");
httpRequest.onload = () => {
jsonData = JSON.parse(httpRequest.responseText);
loadCards("Brand");
countryMaker();
yearsFunction();
};
httpRequest.send();
const loadCards = (para) => {
jsonData = JSON.parse(httpRequest.responseText);
sortAlg(jsonData, 0, jsonData.length - 1, para);
hotContainer.innerHTML = "";
for (var i = 0; i < jsonData.length; i++) makeCard(jsonData[i]);
};
const makeCard = (jsonEle) => {
htmlString =
"<div class='flip-container'><div class='flip-card' onclick='flipClick(this)'><div class='flip-front'><p>" +
jsonEle["Brand"] +
"</p></div><div class='flip-back'><div class='star'><a>" +
jsonEle["Stars"] +
"</a><i class='fas fa-star'></i></div><p class='sub-head'>variety</p><p class='variety'>" +
jsonEle["Variety"] +
"</p><p class='sub-head'>style</p><p>" +
jsonEle["Style"] +
"</p><p class='sub-head'>location</p><p>" +
jsonEle["Country"] +
"</p><p class='rank'>Ranked " +
jsonEle["TopTen"] +
"</p></div></div></div>";
hotContainer.insertAdjacentHTML("beforeend", htmlString);
};
const sortAlg = (data, low, high, parameter) => {
// ISSUE#1
// implement quicksort to sort the restaurants accoring to the parameter selected by the user (ex: brand, country, stars)
// quick sort reference - https://www.geeksforgeeks.org/quick-sort/
// data contains the JSON data which has to be sorted. (structure of the data can be viewed at https://github.com/chirayurathi/spotramenJson/blob/master/db.json)
};
var dropbtnbool = false;
$(".drop button").click(() => {
if (dropbtnbool === false) $(".drop ul").attr("id", "drop-active");
else $(".drop ul").attr("id", "");
dropbtnbool = !dropbtnbool;
});
var droplist = document.querySelectorAll(".drop ul li");
droplist[0].addEventListener("click", () => {
loadCards("Brand");
});
droplist[1].addEventListener("click", () => {
loadCards("Country");
});
droplist[2].addEventListener("click", () => {
loadCards("Stars");
});
var inputVal = $('input[type="text"]');
const searchlist = function () {
for (var i = 0; i < jsonData.length; i++) {
if (
jsonData[i]["Brand"].toLowerCase().indexOf(inputVal.val().toLowerCase()) >
-1
) {
$(".hotspots-container > .flip-container")
.eq(i)
.css("display", "inline-block");
} else {
$(".hotspots-container > .flip-container").eq(i).css("display", "none");
}
}
};
const countryMaker = function () {
var countryHeadder = $(".country-headder");
countryHeadder.each(function () {
countryFilter($(this).text(), countryHeadder.index(this));
});
};
const countryFilter = (countryName, index) => {
// ISSUE#2
// complete this function to filter the restaurants of the country countryName
// countrylist is stored in variable -> jsonData ( checkout the data structure at https://github.com/chirayurathi/spotramenJson/blob/master/db.json).
// use the appendCountryCard() function to append the filtered countries.
};
const appendCountryCard = (data,index)=>{
htmlString =
"<div class='flip-container'><div class='flip-card' onclick='flipClick(this)'><div class='flip-front'><p>" +
data["Brand"] +
"</p></div><div class='flip-back'><div class='star'><a>" +
data["Stars"] +
"</a><i class='fas fa-star'></i></div><p class='sub-head'>variety</p><p class='variety'>" +
data["Variety"] +
"</p><p class='sub-head'>style</p><p>" +
data["Style"] +
"</p><p class='sub-head'>location</p><p>" +
data["Country"] +
"</p><p class='rank'>Ranked " +
data["TopTen"] +
"</p></div></div></div>";
countryContent.eq(index).append(htmlString);
}
var years = $(".yeartag");
var yearsSubList = [Array(10), Array(10), Array(10), Array(10), Array(10)];
const yearsFunction = function () {
years.each(function () {
console.log(jsonData.length);
for (var i = 0; i < jsonData.length; i++) {
if (jsonData[i]["TopTen"].indexOf("2012") > -1)
yearsSubList[0][Number(jsonData[i]["TopTen"].slice(6))] = jsonData[i];
else if (jsonData[i]["TopTen"].indexOf("2013") > -1)
yearsSubList[1][Number(jsonData[i]["TopTen"].slice(6))] = jsonData[i];
else if (jsonData[i]["TopTen"].indexOf("2014") > -1)
yearsSubList[2][Number(jsonData[i]["TopTen"].slice(6))] = jsonData[i];
else if (jsonData[i]["TopTen"].indexOf("2015") > -1)
yearsSubList[3][Number(jsonData[i]["TopTen"].slice(6))] = jsonData[i];
else if (jsonData[i]["TopTen"].indexOf("2016") > -1)
yearsSubList[4][Number(jsonData[i]["TopTen"].slice(6))] = jsonData[i];
}
});
var yearActList = yearsSubList[0];
for (var i = 0; i < 10; i++) {
if (yearActList[i]) {
console.log("check");
htmlString =
"<div class='flip-container'><div class='flip-card' onclick='flipClick(this)'><div class='flip-front'><p>" +
yearActList[i]["Brand"] +
"</p></div><div class='flip-back'><div class='star'><a>" +
yearActList[i]["Stars"] +
"</a><i class='fas fa-star'></i></div><p class='sub-head'>variety</p><p class='variety'>" +
yearActList[i]["Variety"] +
"</p><p class='sub-head'>style</p><p>" +
yearActList[i]["Style"] +
"</p><p class='sub-head'>location</p><p>" +
yearActList[i]["Country"] +
"</p><p class='rank'>Ranked " +
yearActList[i]["TopTen"] +
"</p></div></div></div>";
$(".tencontainer").append(htmlString);
}
}
};
years.click(function () {
years.removeClass("yeartag-active");
$(this).addClass("yeartag-active");
var yearActList = yearsSubList[Number($(this).text()) % 2012];
$(".tencontainer").empty();
for (var i = 0; i < 10; i++) {
if (!(yearActList[i] === undefined)) {
console.log("check");
htmlString =
"<div class='flip-container'><div class='flip-card' onclick='flipClick(this)'><div class='flip-front'><p>" +
yearActList[i]["Brand"] +
"</p></div><div class='flip-back'><div class='star'><a>" +
yearActList[i]["Stars"] +
"</a><i class='fas fa-star'></i></div><p class='sub-head'>variety</p><p class='variety'>" +
yearActList[i]["Variety"] +
"</p><p class='sub-head'>style</p><p>" +
yearActList[i]["Style"] +
"</p><p class='sub-head'>location</p><p>" +
yearActList[i]["Country"] +
"</p><p class='rank'>Ranked " +
yearActList[i]["TopTen"] +
"</p></div></div></div>";
$(".tencontainer").append(htmlString);
}
}
});