-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
130 lines (116 loc) · 3.75 KB
/
app.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
let body = document.querySelector("body");
let cardContainer = document.querySelector(".container");
let selectList = document.getElementById("select_list");
let loader = document.getElementById("loader");
let footer = document.querySelector(".footer");
let apiLink = "https://api.theindex.tech/";
function createNode(element) {
return document.createElement(element);
}
function loadData(indexs = 0) {
loader.removeAttribute("hidden");
footer.style.display = "none";
fetch(apiLink)
.then((response) => {
if (response.ok) {
return response.json();
} else {
throw new Error("Something went wrong");
}
})
.then((resData) => {
loader.setAttribute("hidden", "");
footer.style.display = "block";
data = resData.websites[`${indexs}`];
// for each start
data.forEach((element) => {
// card
const card = createNode("div");
card.setAttribute("class", "card");
// card title
const cardTitle = createNode("div");
cardTitle.setAttribute("class", "card_title");
const a = createNode("a");
a.href = element.link;
a.setAttribute("target", "_blank");
a.textContent = element.title;
// card discription
const cardDiscription = createNode("div");
cardDiscription.setAttribute("class", "card_discription");
const p = createNode("p");
element.description = element.description.substring(0, 70);
p.textContent = element.description + "...";
// card logo
const cardLogo = createNode("div");
cardLogo.setAttribute("class", "card_logo");
const img = createNode("img");
img.src = element.logo || "aseets/404.png";
img.onerror = function () {
// error handling if image not found
this.onerror = null;
this.src = "aseets/404.png";
};
// resouce link
const resouceLink = createNode("div");
resouceLink.setAttribute("class", "resouce_link");
const card_link = createNode("a");
card_link.href = element.link;
card_link.setAttribute("target", "_blank");
const i = createNode("i");
i.setAttribute("class", "fa fa-external-link");
//append
cardContainer.appendChild(card);
card.appendChild(cardTitle);
cardTitle.appendChild(a);
card.appendChild(cardDiscription);
cardDiscription.appendChild(p);
card.appendChild(cardLogo);
cardLogo.appendChild(img);
card.appendChild(resouceLink);
resouceLink.appendChild(card_link);
card_link.appendChild(i);
});
// for each end
// Reveal Animation
(function scrollReveal() {
window.sr = ScrollReveal();
sr.reveal(
".card",
{
duration: 800,
distance: "40px",
easing: "ease-out",
origin: "bottom",
reset: true,
scale: 1,
viewFactor: 0,
},
150
);
})();
// Reveal Animation End
});
}
selectList.addEventListener("change", function () {
cardContainer.innerHTML = "";
selectedItem = selectList.selectedIndex;
loadData(selectedItem);
});
window.onscroll = function () {
scrollFunction();
};
function scrollFunction() {
if (
document.body.scrollTop > 150 ||
document.documentElement.scrollTop > 150
) {
document.querySelector(".category").style.backgroundColor = "white";
document.querySelector(".drop_down").style.backgroundColor = "black";
} else {
document.querySelector(".category").style.backgroundColor =
"rgba(255, 255, 255, 0.2)";
document.querySelector(".drop_down").style.backgroundColor =
"rgba(255, 255, 255, 0.2)";
}
}
loadData();