forked from ML-Fusion-Lab/ML-Fusion-Lab-Website
-
Notifications
You must be signed in to change notification settings - Fork 0
/
courses.js
185 lines (171 loc) · 5.16 KB
/
courses.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
// Array of courses to dynamically render on the page
const courses = [
{
id: "course_1",
img: "Course Assets/1.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "Google AI Essentials",
desc: "Beginner · Course",
skills: "",
},
{
id: "course_2",
img: "Course Assets/2.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "Python for Everybody",
desc: "Beginner · Specialization",
skills: "",
},
{
id: "course_3",
img: "Course Assets/3.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "Prompt Engineering",
desc: "Beginner · Specialization",
skills: "",
},
{
id: "course_4",
img: "Course Assets/4.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_5",
img: "Course Assets/5.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_6",
img: "Course Assets/6.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_7",
img: "Course Assets/7.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_8",
img: "Course Assets/8.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_9",
img: "Course Assets/9.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_10",
img: "Course Assets/10.png",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_11",
img: "Course Assets/11.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
{
id: "course_12",
img: "Course Assets/12.jpg",
logo: "https://upload.wikimedia.org/wikipedia/commons/5/51/IBM_logo.svg",
logoName: "IBM",
title: "IBM Data Science",
desc: "Beginner · Professional Certificate",
skills: "AI skills",
},
];
// Select card container
const cardContainer = document.querySelector(".cards-container");
const loadMoreButton = document.querySelector(".load-more-button");
// Render courses
cardPerPage = 5;
currentIndex = 0;
const loadMore = () => {
for (
let i = currentIndex;
i < currentIndex + cardPerPage && i < courses.length;
i++
) {
// Create card element
const card = document.createElement("div");
const cardImg = document.createElement("img");
const cardContent = document.createElement("div");
const logoDiv = document.createElement("div");
const logo = document.createElement("img");
const title = document.createElement("h3");
const desc = document.createElement("p");
const skills = document.createElement("span");
const logoName = document.createElement("span");
// Set attributes
card.className = "card";
cardImg.setAttribute("src", courses[i].img);
cardImg.setAttribute("alt", courses[i].title);
cardContent.className = "card-content";
logoDiv.className = "logo";
logoName.innerHTML = courses[i].logoName;
logoName.className = "logoName";
logo.setAttribute("src", courses[i].logo);
title.innerHTML = courses[i].title;
desc.innerHTML = courses[i].desc;
skills.className = "tag";
skills.innerHTML = courses[i].skills;
// Append the elements
card.appendChild(cardImg);
card.appendChild(cardContent);
cardContent.appendChild(logoDiv);
cardContent.appendChild(title);
cardContent.appendChild(desc);
// If skill is not present then do not append
if (courses[i].skills) {
cardContent.appendChild(skills);
}
logoDiv.appendChild(logo);
logoDiv.appendChild(logoName);
cardContainer.appendChild(card);
}
currentIndex += cardPerPage;
if (currentIndex > courses.length){
loadMoreButton.classList.add("hide-btn")
}
};
// Load cards on click event
loadMoreButton.addEventListener("click", () => {
loadMore();
});
// Function is called once statically to load initial cards.
loadMore();