@@ -147,6 +147,7 @@ function updateUI() {
147
147
let resourceBox = $ ( this ) ;
148
148
149
149
// Validate the filters
150
+
150
151
$ . each ( activeFilters , function ( filterType , filters ) {
151
152
// If the filter list is empty, this passes validation.
152
153
if ( filters . length === 0 ) {
@@ -171,6 +172,7 @@ function updateUI() {
171
172
}
172
173
} ) . show ( ) ;
173
174
175
+
174
176
// If there are no matches, show the no matches message
175
177
if ( ! hasMatches ) {
176
178
$ ( ".no-resources-found" ) . show ( ) ;
@@ -219,14 +221,18 @@ document.addEventListener("DOMContentLoaded", function () {
219
221
}
220
222
221
223
// If you click on the div surrounding the filter checkbox, it clicks the corresponding checkbox.
222
- $ ( '.filter-panel' ) . click ( function ( ) {
223
- let checkbox = $ ( this ) . find ( ".filter-checkbox" ) ;
224
- checkbox . prop ( "checked" , ! checkbox . prop ( "checked" ) ) ;
225
- checkbox . change ( ) ;
224
+ $ ( '.filter-panel' ) . on ( "click" , function ( event ) {
225
+ let hitsCheckbox = Boolean ( String ( event . target ) ) ;
226
+
227
+ if ( ! hitsCheckbox ) {
228
+ let checkbox = $ ( this ) . find ( ".filter-checkbox" ) ;
229
+ checkbox . prop ( "checked" , ! checkbox . prop ( "checked" ) ) ;
230
+ checkbox . trigger ( "change" ) ;
231
+ }
226
232
} ) ;
227
233
228
234
// If you click on one of the tags in the filter box, it unchecks the corresponding checkbox.
229
- $ ( '.filter-box-tag' ) . click ( function ( ) {
235
+ $ ( '.filter-box-tag' ) . on ( "click" , function ( ) {
230
236
let filterItem = this . dataset . filterItem ;
231
237
let filterName = this . dataset . filterName ;
232
238
let checkbox = $ ( `.filter-checkbox[data-filter-name='${ filterName } '][data-filter-item='${ filterItem } ']` ) ;
@@ -236,7 +242,7 @@ document.addEventListener("DOMContentLoaded", function () {
236
242
} ) ;
237
243
238
244
// If you click on one of the tags in the resource cards, it clicks the corresponding checkbox.
239
- $ ( '.resource-tag' ) . click ( function ( ) {
245
+ $ ( '.resource-tag' ) . on ( "click" , function ( ) {
240
246
let filterItem = this . dataset . filterItem ;
241
247
let filterName = this . dataset . filterName ;
242
248
let checkbox = $ ( `.filter-checkbox[data-filter-name='${ filterName } '][data-filter-item='${ filterItem } ']` ) ;
@@ -251,13 +257,13 @@ document.addEventListener("DOMContentLoaded", function () {
251
257
} ) ;
252
258
253
259
// When checkboxes are toggled, trigger a filter update.
254
- $ ( '.filter-checkbox' ) . change ( function ( ) {
260
+ $ ( '.filter-checkbox' ) . on ( "change" , function ( event ) {
255
261
let filterItem = this . dataset . filterItem ;
256
262
let filterName = this . dataset . filterName ;
257
263
258
- if ( this . checked ) {
264
+ if ( this . checked && ! activeFilters [ filterName ] . includes ( filterItem ) ) {
259
265
addFilter ( filterName , filterItem ) ;
260
- } else {
266
+ } else if ( ! this . checked && activeFilters [ filterName ] . includes ( filterItem ) ) {
261
267
removeFilter ( filterName , filterItem ) ;
262
268
}
263
269
} ) ;
0 commit comments