-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
586aaac
commit d8b84b5
Showing
11 changed files
with
275 additions
and
129 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/open_inwoner/js/components/search/filter-dropdown-submit.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
export class FilterDropdownSubmit { | ||
static selector = '.filter-dropdown' | ||
|
||
constructor(node) { | ||
this.node = node | ||
this.submitButton = node.querySelector('.filter-dropdown__submit') | ||
this.checkboxes = node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]' | ||
) | ||
|
||
if (!this.submitButton || !this.checkboxes.length) return | ||
|
||
this.checkboxes.forEach((checkbox) => { | ||
checkbox.addEventListener('change', this.updateSubmitButton.bind(this)) | ||
}) | ||
} | ||
|
||
updateSubmitButton() { | ||
const selectedCount = this.node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]:checked' | ||
).length | ||
this.submitButton.textContent = `Apply Filters (${selectedCount})` | ||
} | ||
} | ||
|
||
/** | ||
* Initialize only dropdowns with submit buttons | ||
*/ | ||
document | ||
.querySelectorAll(FilterDropdownSubmit.selector) | ||
.forEach((dropdown) => new FilterDropdownSubmit(dropdown)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
export class FilterDropdown { | ||
static selector = '.filter-dropdown' | ||
|
||
constructor(node) { | ||
this.node = node | ||
this.button = node.querySelector('.filter-dropdown__button') | ||
this.menu = node.querySelector('.filter-dropdown__menu') | ||
this.checkboxes = node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]' | ||
) | ||
this.clearButton = node.querySelector('.filter-dropdown__clear') | ||
this.filterCount = node.querySelector('.filter-count') | ||
|
||
if (!this.button || !this.menu || !this.checkboxes.length) return | ||
|
||
this.button.addEventListener('click', this.toggleDropdown.bind(this)) | ||
document.addEventListener('click', this.closeDropdown.bind(this)) | ||
|
||
this.checkboxes.forEach((checkbox) => { | ||
checkbox.addEventListener('change', this.updateFilters.bind(this)) | ||
}) | ||
|
||
if (this.clearButton) { | ||
this.clearButton.addEventListener('click', this.clearFilters.bind(this)) | ||
} | ||
} | ||
|
||
toggleDropdown(event) { | ||
event.preventDefault() | ||
this.node.classList.toggle('open') | ||
} | ||
|
||
closeDropdown(event) { | ||
if (!this.node.contains(event.target)) { | ||
this.node.classList.remove('open') | ||
} | ||
} | ||
|
||
updateFilters() { | ||
const selectedCount = this.node.querySelectorAll( | ||
'.filter-dropdown__list input[type="checkbox"]:checked' | ||
).length | ||
if (this.filterCount) { | ||
this.filterCount.textContent = `(${selectedCount})` | ||
} | ||
} | ||
|
||
clearFilters() { | ||
this.checkboxes.forEach((checkbox) => (checkbox.checked = false)) | ||
this.updateFilters() | ||
} | ||
} | ||
|
||
/** | ||
* Initialize all dropdowns | ||
*/ | ||
document | ||
.querySelectorAll(FilterDropdown.selector) | ||
.forEach((dropdown) => new FilterDropdown(dropdown)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,7 @@ | ||
const searchForm = document.getElementById('search-form') | ||
const selectors = [ | ||
'.filter .checkbox__input', | ||
'.resetMultiSelectFilters', | ||
'.resetAllFilters', | ||
'.show-controls', | ||
] | ||
|
||
selectors.forEach((selector) => { | ||
document.querySelectorAll(selector).forEach((element) => { | ||
element.addEventListener('click', () => searchForm.submit()) | ||
document.querySelectorAll('.filter .checkbox__input').forEach((checkbox) => { | ||
checkbox.addEventListener('change', (event) => { | ||
searchForm.submit() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.