-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
165 lines (142 loc) · 5.3 KB
/
script.js
File metadata and controls
165 lines (142 loc) · 5.3 KB
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
const navbarMenu = document.getElementById('menu');
const burgerMenu = document.getElementById('burger');
const headerMenu = document.getElementById('header');
// Open Close Navbar Menu on Click Burger
if (burgerMenu && navbarMenu) {
burgerMenu.addEventListener('click', () => {
burgerMenu.classList.toggle('is-active');
navbarMenu.classList.toggle('is-active');
});
}
// Close Navbar Menu on Click Menu Links
document.querySelectorAll('.menu-link').forEach((link) => {
link.addEventListener('click', () => {
burgerMenu.classList.remove('is-active');
navbarMenu.classList.remove('is-active');
});
});
// Change Header Background on Scrolling
window.addEventListener('scroll', () => {
if (window.scrollY >= 85) {
headerMenu.classList.add('on-scroll');
} else {
headerMenu.classList.remove('on-scroll');
}
});
// Fixed Navbar Menu on Window Resize
window.addEventListener('resize', () => {
if (window.innerWidth > 768) {
if (navbarMenu.classList.contains('is-active')) {
navbarMenu.classList.remove('is-active');
}
}
});
// MARKETPLACE DROPDOWN
// Select all dropdown buttons
const dropdownButtons = document.querySelectorAll('.dropdown-button');
// Handle filtering based on dropdown selection
dropdownButtons.forEach((button) => {
const dropdownContainer = button.closest('.dropdown-container');
const dropdownMenu = dropdownContainer.querySelector('.dropdown-menu');
// Toggle dropdown visibility for the clicked button
button.addEventListener('click', (event) => {
event.stopPropagation(); // Prevent click from propagating to the document
// Close all other dropdowns first
document.querySelectorAll('.dropdown-menu').forEach((menu) => {
if (menu !== dropdownMenu) {
menu.classList.remove('visible');
}
});
// Toggle visibility of the current dropdown
dropdownMenu.classList.toggle('visible');
});
// Handle item selection and update button text
const dropdownItems = dropdownMenu.querySelectorAll('.dropdown-item');
dropdownItems.forEach((item) => {
item.addEventListener('click', () => {
button.innerHTML = `${item.textContent} <span>▼</span>`;
dropdownMenu.classList.remove('visible'); // Close menu after selection
// Get the selected filter from the dropdown
const selectedFilter = item.textContent;
// Filter the marketplace items based on the selected option
filterMarketplaceItems(selectedFilter, button);
});
});
});
// Close all dropdowns when clicking outside
document.addEventListener('click', () => {
document.querySelectorAll('.dropdown-menu').forEach((menu) => {
menu.classList.remove('visible');
});
});
// Filter marketplace items based on the selected dropdown option
function filterMarketplaceItems(selectedFilter, button) {
const marketplaceItems = document.querySelectorAll('.marketplace-item');
const itemsArray = Array.from(marketplaceItems); // Convert NodeList to Array
// Handle rarity filtering
if (button.closest('.dropdown').id === 'rarityDropdown') {
// Check for the RARITY dropdown
const selectedRarity = selectedFilter.toLowerCase();
itemsArray.forEach((item) => {
const itemRarity = item.getAttribute('data-rarity').toLowerCase();
if (selectedRarity === 'all' || itemRarity === selectedRarity) {
item.style.display = 'block'; // Show item
} else {
item.style.display = 'none'; // Hide item
}
});
}
// Handle price sorting
if (button.closest('.dropdown').id === 'priceDropdown') {
// Check for the PRICE dropdown
if (selectedFilter === 'LOWEST TO HIGHEST') {
// Sort items by price ascending
itemsArray.sort(
(a, b) =>
parseFloat(a.getAttribute('data-price')) -
parseFloat(b.getAttribute('data-price')),
);
} else if (selectedFilter === 'HIGHEST TO LOWEST') {
// Sort items by price descending
itemsArray.sort(
(a, b) =>
parseFloat(b.getAttribute('data-price')) -
parseFloat(a.getAttribute('data-price')),
);
}
// Reorder the DOM based on the sorted items
const marketplaceGrid = document.querySelector('.marketplace-grid');
itemsArray.forEach((item) => {
marketplaceGrid.appendChild(item); // Append items in the new order
});
}
}
// MARKETPLACE CARD HOVER EFFECT
const cards = document.querySelectorAll('.marketplace-item'); // Select all cards
const popup = document.querySelector('.popup');
const closePopupBtn = document.querySelector('.popup-close');
const isMobile =
/iPhone|iPad|iPod|Android/i.test(navigator.userAgent) ||
window.innerWidth <= 768;
cards.forEach(($card) => {
$card.addEventListener('click', () => {
popup.classList.add('active'); // Show the popup
document.body.style.overflow = 'hidden';
});
});
// Close the popup when the close button is clicked
if (closePopupBtn) {
closePopupBtn.addEventListener('click', () => {
popup.classList.remove('active'); // Hide the popup
document.body.style.overflow = ''; // Reset to default
});
}
if (popup) {
// Close the popup when clicking on the background (but not on the popup content)
popup.addEventListener('click', (event) => {
if (event.target === popup) {
popup.classList.remove('active'); // Hide the popup
document.body.style.overflow = ''; // Reset to default
}
});
}