@@ -51,12 +51,15 @@ function displayFamilies(familyCounts) {
51
51
familiesContainer . innerHTML = "" ;
52
52
53
53
const sortedFamilies = Object . keys ( familyCounts ) . sort ( ) ;
54
+ const maxVisible = 5 ; // Show only first 5 initially
55
+ let showMoreClicked = false ;
54
56
55
- sortedFamilies . forEach ( ( family ) => {
57
+ sortedFamilies . forEach ( ( family , index ) => {
56
58
const familyCount = familyCounts [ family ] ;
57
59
58
60
const familyRow = document . createElement ( "div" ) ;
59
61
familyRow . className = "family-row" ;
62
+ if ( index >= maxVisible ) familyRow . style . display = "none" ; // Hide extra items initially
60
63
61
64
const checkbox = document . createElement ( "input" ) ;
62
65
checkbox . type = "checkbox" ;
@@ -67,29 +70,53 @@ function displayFamilies(familyCounts) {
67
70
familyName . className = "family-name" ;
68
71
familyName . textContent = family ;
69
72
70
- const familyCountElem = document . createElement ( "span" ) ;
71
- familyCountElem . className = "family-count" ;
72
- familyCountElem . textContent = `( ${ familyCount } ) ` ;
73
+ const familyCountElement = document . createElement ( "span" ) ;
74
+ familyCountElement . className = "family-count" ;
75
+ familyCountElement . textContent = `${ familyCount } ` ;
73
76
74
77
familyRow . appendChild ( checkbox ) ;
75
78
familyRow . appendChild ( familyName ) ;
76
- // familyRow.appendChild(familyCountElem );
79
+ familyRow . appendChild ( familyCountElement ) ;
77
80
78
81
familiesContainer . appendChild ( familyRow ) ;
79
82
} ) ;
83
+
84
+ // Handle "Show more" click
85
+ const showMoreButton = document . querySelector ( ".product-families .show-more" ) ;
86
+ const FamilyRows = document . querySelectorAll ( ".family-row" ) ;
87
+ showMoreButton . addEventListener ( "click" , ( ) => {
88
+ if ( showMoreClicked ) {
89
+ FamilyRows . forEach ( ( row , index ) => {
90
+ if ( index >= maxVisible ) {
91
+ row . style . display = "none" ;
92
+ }
93
+ } ) ;
94
+ showMoreButton . textContent = "Show more" ;
95
+ showMoreClicked = false ;
96
+ } else {
97
+ FamilyRows . forEach ( ( row ) => {
98
+ row . style . display = "flex" ;
99
+ } ) ;
100
+ showMoreButton . textContent = "Show less" ;
101
+ showMoreClicked = true ;
102
+ }
103
+ } ) ;
80
104
}
81
105
82
106
function displayTags ( tagCounts ) {
83
107
const tagsContainer = document . getElementById ( "product-tags-list" ) ;
84
108
tagsContainer . innerHTML = "" ;
85
109
86
110
const sortedTags = Object . keys ( tagCounts ) . sort ( ) ;
111
+ const maxVisible = 5 ; // Show only first 5 initially
112
+ let showMoreClicked = false ;
87
113
88
- sortedTags . forEach ( ( tag ) => {
114
+ sortedTags . forEach ( ( tag , index ) => {
89
115
const tagCount = tagCounts [ tag ] ;
90
116
91
117
const tagRow = document . createElement ( "div" ) ;
92
118
tagRow . className = "tag-row" ;
119
+ if ( index >= maxVisible ) tagRow . style . display = "none" ; // Hide extra items initially
93
120
94
121
const checkbox = document . createElement ( "input" ) ;
95
122
checkbox . type = "checkbox" ;
@@ -100,19 +127,56 @@ function displayTags(tagCounts) {
100
127
tagName . className = "tag-name" ;
101
128
tagName . textContent = tag ;
102
129
103
- const tagCountElem = document . createElement ( "span" ) ;
104
- tagCountElem . className = "tag-count" ;
105
- tagCountElem . textContent = `( ${ tagCount } ) ` ;
130
+ const tagCountElement = document . createElement ( "span" ) ;
131
+ tagCountElement . className = "tag-count" ;
132
+ tagCountElement . textContent = `${ tagCount } ` ;
106
133
107
134
tagRow . appendChild ( checkbox ) ;
108
135
tagRow . appendChild ( tagName ) ;
109
- // tagRow.appendChild(tagCountElem );
136
+ tagRow . appendChild ( tagCountElement ) ;
110
137
111
138
tagsContainer . appendChild ( tagRow ) ;
112
139
} ) ;
140
+
141
+ // Handle "Show more" click
142
+ const showMoreButton = document . querySelector ( ".product-tags .show-more" ) ;
143
+ const TagRows = document . querySelectorAll ( ".tag-row" ) ;
144
+ showMoreButton . addEventListener ( "click" , ( ) => {
145
+ if ( showMoreClicked ) {
146
+ TagRows . forEach ( ( row , index ) => {
147
+ if ( index >= maxVisible ) {
148
+ row . style . display = "none" ;
149
+ }
150
+ } ) ;
151
+ showMoreButton . textContent = "Show more" ;
152
+ showMoreClicked = false ;
153
+ } else {
154
+ TagRows . forEach ( ( row ) => {
155
+ row . style . display = "flex" ;
156
+ } ) ;
157
+ showMoreButton . textContent = "Show less" ;
158
+ showMoreClicked = true ;
159
+ }
160
+ } ) ;
113
161
}
114
162
115
163
function handleFamilySelection ( ) {
164
+ applyFilters ( ) ;
165
+ }
166
+
167
+ function handleTagSelection ( ) {
168
+ applyFilters ( ) ;
169
+ }
170
+
171
+ function applyFilters ( ) {
172
+ const SelectedTagsContainer = document . getElementById (
173
+ "selected-product-tags-list" ,
174
+ ) ;
175
+ const SelectedFamiliesContainer = document . getElementById (
176
+ "selected-product-families-list" ,
177
+ ) ;
178
+ SelectedTagsContainer . innerHTML = "" ;
179
+ SelectedFamiliesContainer . innerHTML = "" ;
116
180
const selectedFamilies = Array . from (
117
181
document . querySelectorAll (
118
182
'#product-families-list input[type="checkbox"]:checked' ,
@@ -121,58 +185,58 @@ function handleFamilySelection() {
121
185
checkbox . id . replace ( "family-" , "" ) . replace ( "\\ " , "-" ) . toLowerCase ( ) ,
122
186
) ;
123
187
124
- console . log ( "Selected families:" , selectedFamilies ) ;
125
-
126
- const projectCards = document . querySelectorAll ( ".project-card" ) ;
127
-
128
- projectCards . forEach ( ( card ) => {
129
- const family = card . getAttribute ( "data-family" ) . toLowerCase ( ) ;
130
- console . log ( "Family:" , family ) ;
131
- card . style . display =
132
- selectedFamilies . length === 0 || selectedFamilies . includes ( family )
133
- ? "flex"
134
- : "none" ;
135
- } ) ;
136
- }
137
-
138
- function handleTagSelection ( ) {
139
188
const selectedTags = Array . from (
140
189
document . querySelectorAll (
141
190
'#product-tags-list input[type="checkbox"]:checked' ,
142
191
) ,
143
192
) . map ( ( checkbox ) =>
144
193
checkbox . id . replace ( "tag-" , "" ) . replace ( "\\ " , "-" ) . toLowerCase ( ) ,
145
194
) ;
195
+ for ( const tag of selectedTags ) {
196
+ const selectedTag = document . createElement ( "span" ) ;
197
+ selectedTag . className = "selected-tag" ;
198
+ selectedTag . textContent = tag ;
199
+ SelectedTagsContainer . appendChild ( selectedTag ) ;
200
+ }
201
+
202
+ for ( const family of selectedFamilies ) {
203
+ const selectedFamily = document . createElement ( "span" ) ;
204
+ selectedFamily . className = "selected-family" ;
205
+ selectedFamily . textContent = family ;
206
+ SelectedFamiliesContainer . appendChild ( selectedFamily ) ;
207
+ }
146
208
209
+ console . log ( "Selected families:" , selectedFamilies ) ;
147
210
console . log ( "Selected tags:" , selectedTags ) ;
148
211
149
212
const projectCards = document . querySelectorAll ( ".project-card" ) ;
150
213
151
214
projectCards . forEach ( ( card ) => {
215
+ const family = card . getAttribute ( "data-family" ) . toLowerCase ( ) ;
152
216
const rawTags = card . getAttribute ( "data-tags" ) ;
153
217
154
- if ( ! rawTags ) {
155
- card . style . display = "none" ;
156
- return ;
157
- }
158
-
159
- // Parse the data-tags string
160
218
let cardTags = [ ] ;
161
- try {
162
- cardTags = JSON . parse ( rawTags . replace ( / ' / g, '"' ) ) ;
163
- } catch ( error ) {
164
- console . error ( "Error parsing data-tags:" , rawTags , error ) ;
165
- card . style . display = "none" ;
166
- return ;
219
+ if ( rawTags ) {
220
+ try {
221
+ cardTags = JSON . parse ( rawTags . replace ( / ' / g, '"' ) ) . map ( ( tag ) =>
222
+ tag . toLowerCase ( ) ,
223
+ ) ;
224
+ } catch ( error ) {
225
+ console . error ( "Error parsing data-tags:" , rawTags , error ) ;
226
+ }
167
227
}
168
228
169
- const cardTagsLower = cardTags . map ( ( tag ) => tag . toLowerCase ( ) ) ;
170
- const hasMatchingTag = selectedTags . some ( ( tag ) =>
171
- cardTagsLower . includes ( tag ) ,
172
- ) ;
229
+ // Check if the card matches the selected families
230
+ const matchesAllFamilies =
231
+ selectedFamilies . length === 0 || selectedFamilies . includes ( family ) ;
232
+
233
+ // Check if the card matches the selected tags
234
+ const matchesAllTags =
235
+ selectedTags . length === 0 ||
236
+ selectedTags . every ( ( tag ) => cardTags . includes ( tag ) ) ;
173
237
174
- card . style . display =
175
- selectedTags . length === 0 || hasMatchingTag ? "flex" : "none" ;
238
+ // Show only if both family & tag filters match (or if no filter is applied)
239
+ card . style . display = matchesAllFamilies && matchesAllTags ? "flex" : "none" ;
176
240
} ) ;
177
241
}
178
242
0 commit comments