Skip to content

Commit a825d75

Browse files
committed
tweak list filter module so that list elements get a class when filtered
1 parent a22b12c commit a825d75

File tree

4 files changed

+30
-2
lines changed

4 files changed

+30
-2
lines changed

digital_land_frontend/templates/components/list-filter/list-filter.js

+14
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ ListFilter.prototype.ListFilter = function (e) {
4747
const listsToFilter = convertNodeListToArray(document.querySelectorAll('[data-filter="list"]'))
4848
const searchTerm = e.target.value
4949

50+
// set a class if a search/filter is in progress
51+
this.setActiveClasses(listsToFilter, searchTerm)
52+
5053
const boundMatchSearchTerm = this.matchSearchTerm.bind(this)
5154
itemsToFilter
5255
.filter(function ($item) {
@@ -82,6 +85,16 @@ ListFilter.prototype.matchSearchTerm = function (item, term) {
8285
return true
8386
}
8487

88+
ListFilter.prototype.setActiveClasses = function(lists, searchTerm) {
89+
lists.forEach(list => {
90+
if (searchTerm !== '') {
91+
list.classList.add(this.list_filtered_class);
92+
} else {
93+
list.classList.remove(this.list_filtered_class);
94+
}
95+
})
96+
}
97+
8598
ListFilter.prototype.updateListCounts = function (lists) {
8699
var totalMatches = 0
87100
const list_section_selector = this.list_section_selector
@@ -123,6 +136,7 @@ ListFilter.prototype.setupOptions = function (params) {
123136
params = params || {}
124137
this.list_section_selector = params.list_section_selector || '.dl-list-filter__count'
125138
this.count_wrapper_selector = params.count_wrapper_selector || '.dl-list-filter__count__wrapper'
139+
this.list_filtered_class = params.list_filtered_class || 'dl-list-filter__filtered-listed'
126140
}
127141

128142
export default ListFilter

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "digital-land-frontend-repo",
3-
"version": "0.2.3",
3+
"version": "0.2.4",
44
"description": "frontend components and assets for digital land",
55
"engines": {
66
"node": ">=16.0.0"

package/digital-land-frontend/javascripts/digital-land-frontend.js

+14
Original file line numberDiff line numberDiff line change
@@ -661,6 +661,9 @@
661661
const listsToFilter = convertNodeListToArray(document.querySelectorAll('[data-filter="list"]'));
662662
const searchTerm = e.target.value;
663663

664+
// set a class if a search/filter is in progress
665+
this.setActiveClasses(listsToFilter, searchTerm);
666+
664667
const boundMatchSearchTerm = this.matchSearchTerm.bind(this);
665668
itemsToFilter
666669
.filter(function ($item) {
@@ -696,6 +699,16 @@
696699
return true
697700
};
698701

702+
ListFilter.prototype.setActiveClasses = function(lists, searchTerm) {
703+
lists.forEach(list => {
704+
if (searchTerm !== '') {
705+
list.classList.add(this.list_filtered_class);
706+
} else {
707+
list.classList.remove(this.list_filtered_class);
708+
}
709+
});
710+
};
711+
699712
ListFilter.prototype.updateListCounts = function (lists) {
700713
var totalMatches = 0;
701714
const list_section_selector = this.list_section_selector;
@@ -737,6 +750,7 @@
737750
params = params || {};
738751
this.list_section_selector = params.list_section_selector || '.dl-list-filter__count';
739752
this.count_wrapper_selector = params.count_wrapper_selector || '.dl-list-filter__count__wrapper';
753+
this.list_filtered_class = params.list_filtered_class || '.dl-list-filter__filtered-listed';
740754
};
741755

742756
(function (global, factory) {

package/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "digital-land-frontend",
33
"description": "DL Frontend",
4-
"version": "0.3.1",
4+
"version": "0.3.2",
55
"engines": {
66
"node": ">= 4.2.0"
77
},

0 commit comments

Comments
 (0)