-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
202 lines (174 loc) · 7.47 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
// define object items
const featuredTeams = [
{
image: 'Assets/teams/nrg.png',
name: 'NRG Esports',
region: '(North America)',
description: 'NRG Esports is a top-performing North American team that has won several major Rocket League tournaments. The team consists of players GarrettG, jstn, and SquishyMuffinz.',
},
{
image: 'Assets/teams/vitality.jpg',
name: 'Team Vitality',
region: '(Europe)',
description: 'Team Vitality is a dominant European team with a consistent track record of success. The team features players such as Fairy Peak!, Alpha54, and Kaydop.',
},
{
image: 'Assets/teams/spacestation.jpg',
name: 'Spacestation Gaming',
region: '(North America)',
description: 'Spacestation Gaming is a North American team that has been consistently performing well in recent seasons of RLCS. The team is composed of players Sypical, Arsenal, and retals.',
},
{
image: 'Assets/teams/bds.jpg',
name: 'BDS Esports',
region: '(Europe)',
description: "BDS Esport is a European team that has been a rising star in the competitive Rocket League scene. The team's roster includes players such as Monkey Moon, Extra, and Marc_By_8.",
},
{
image: 'Assets/teams/g2.png',
name: 'G2 Esports',
region: '(North America)',
description: 'G2 Esports is a North American team with a long history of success in competitive Rocket League. The team consists of players JKnaps, Rizzo, and Chicago.',
},
{
image: 'Assets/teams/envy.jpg',
name: 'Team Envy',
region: '(North America)',
description: 'Team Envy is a North American team that has had success in both RLCS and other Rocket League tournaments. The team features players such as Atomic, Mist, and Turinturo.',
},
];
// Define featured cards and see more button
const featuredCards = document.querySelector('.featured-cards');
const button = document.querySelector('.see-more');
// Get the media query
const mediaQuery = window.matchMedia('(min-width: 768px)');
// Check if the media query matches
if (mediaQuery.matches) {
// add hide class to the see-more button
button.classList.add('hide');
// Execute the forEach loop for all items
featuredTeams.forEach((team) => {
// create article element
const container = document.createElement('article');
container.classList.add('card', 'd-flex', 'flex-row', 'justify-content-end', 'p-2', 'my-2');
// create image div
const imageHolder = document.createElement('div');
imageHolder.classList.add('featured-image-holder', 'd-flex', 'justify-content-end', 'align-items-end');
container.appendChild(imageHolder);
// create image element
const image = document.createElement('img');
image.src = team.image;
image.alt = team.name;
imageHolder.appendChild(image);
// create team details div
const teamDetails = document.createElement('div');
teamDetails.classList.add('team', 'd-flex', 'flex-column', 'ps-2');
container.appendChild(teamDetails);
// create team name
const teamName = document.createElement('h5');
teamName.className = 'card-title';
teamName.innerHTML = team.name;
teamDetails.appendChild(teamName);
// create team region element
const teamRegion = document.createElement('span');
teamRegion.className = 'card-text';
teamRegion.innerHTML = team.region;
teamDetails.appendChild(teamRegion);
// create underline element
const underline = document.createElement('div');
underline.className = 'underline my-1';
teamDetails.appendChild(underline);
// create description element
const teamDescription = document.createElement('p');
teamDescription.className = 'card-text';
teamDescription.innerHTML = team.description;
teamDetails.appendChild(teamDescription);
// append team card to html
featuredCards.appendChild(container);
});
} else {
// Execute the forEach loop for only the first two items
featuredTeams.slice(0, 2).forEach((team) => {
// create article element
const container = document.createElement('article');
container.classList.add('card', 'd-flex', 'flex-row', 'justify-content-end', 'p-2', 'my-2');
// create image div
const imageHolder = document.createElement('div');
imageHolder.classList.add('featured-image-holder', 'd-flex', 'justify-content-end', 'align-items-end');
container.appendChild(imageHolder);
// create image element
const image = document.createElement('img');
image.src = team.image;
image.alt = team.name;
imageHolder.appendChild(image);
// create team details div
const teamDetails = document.createElement('div');
teamDetails.classList.add('team', 'd-flex', 'flex-column', 'ps-2');
container.appendChild(teamDetails);
// create team name
const teamName = document.createElement('h5');
teamName.className = 'card-title';
teamName.innerHTML = team.name;
teamDetails.appendChild(teamName);
// create team region element
const teamRegion = document.createElement('span');
teamRegion.className = 'card-text';
teamRegion.innerHTML = team.region;
teamDetails.appendChild(teamRegion);
// create underline element
const underline = document.createElement('div');
underline.className = 'underline my-1';
teamDetails.appendChild(underline);
// create description element
const teamDescription = document.createElement('p');
teamDescription.className = 'card-text';
teamDescription.innerHTML = team.description;
teamDetails.appendChild(teamDescription);
// append team card to html
featuredCards.appendChild(container);
});
// Wait for a click event on a button to execute the rest
button.addEventListener('click', () => {
// hide the see more button
button.classList.add('hide');
featuredTeams.slice(2).forEach((team) => {
// create article element
const container = document.createElement('article');
container.classList.add('card', 'd-flex', 'flex-row', 'justify-content-end', 'p-2', 'my-2');
// create image div
const imageHolder = document.createElement('div');
imageHolder.classList.add('featured-image-holder', 'd-flex', 'justify-content-end', 'align-items-end');
container.appendChild(imageHolder);
// create image element
const image = document.createElement('img');
image.src = team.image;
image.alt = team.name;
imageHolder.appendChild(image);
// create team details div
const teamDetails = document.createElement('div');
teamDetails.classList.add('team', 'd-flex', 'flex-column', 'ps-2');
container.appendChild(teamDetails);
// create team name
const teamName = document.createElement('h5');
teamName.className = 'card-title';
teamName.innerHTML = team.name;
teamDetails.appendChild(teamName);
// create team region element
const teamRegion = document.createElement('span');
teamRegion.className = 'card-text';
teamRegion.innerHTML = team.region;
teamDetails.appendChild(teamRegion);
// create underline element
const underline = document.createElement('div');
underline.className = 'underline my-1';
teamDetails.appendChild(underline);
// create description element
const teamDescription = document.createElement('p');
teamDescription.className = 'card-text';
teamDescription.innerHTML = team.description;
teamDetails.appendChild(teamDescription);
// append team card to html
featuredCards.appendChild(container);
});
});
}