-
Notifications
You must be signed in to change notification settings - Fork 9
Improve facet limitation #41
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,22 +6,43 @@ document.addEventListener('DOMContentLoaded', function () { | |
| }); | ||
| } | ||
|
|
||
| for (const button of document.querySelectorAll('.search-facet .search-facet-expand-button')) { | ||
| button.addEventListener('click', function() { | ||
| this.closest('.search-facet').classList.toggle('search-facet-expanded'); | ||
| var buttonResetFacets = document.getElementById('reset-facets'); | ||
| if (buttonResetFacets) { | ||
| buttonResetFacets.addEventListener('click', function () { | ||
| resetFacets(); | ||
| }); | ||
| } | ||
|
|
||
| var buttonToggleHiddenFacets = document.querySelectorAll('.show-hidden-facets-btn'); | ||
| buttonToggleHiddenFacets.forEach(function (button) { | ||
| button.addEventListener('click', function () { | ||
| var facetName = button.getAttribute('data-facet-name'); | ||
| toggleHiddenFacets(facetName, button); | ||
| }); | ||
| }); | ||
|
|
||
| function toggleHiddenFacets(name, button) { | ||
| var hiddenFacets = document.querySelector('.search-facet[data-facet-name="' + name + '"] .hidden-facets'); | ||
|
|
||
| if (hiddenFacets.style.display === 'none' || hiddenFacets.style.display === '') { | ||
| hiddenFacets.style.display = 'block'; | ||
| button.classList.remove('o-icon-down'); | ||
| button.classList.add('o-icon-up'); | ||
| button.innerHTML = ' ' + button.getAttribute('data-collapse-label'); | ||
| } else { | ||
| hiddenFacets.style.display = 'none'; | ||
| button.classList.remove('o-icon-up'); | ||
| button.classList.add('o-icon-down'); | ||
| button.innerHTML = ' ' + button.getAttribute('data-expand-label'); | ||
| } | ||
| } | ||
|
|
||
| function submitFacets() { | ||
| var params = new URLSearchParams(window.location.search); | ||
|
|
||
| const facetCheckboxes = Array.from(document.querySelectorAll('.search-facet-item input[type="checkbox"]')); | ||
| const facetNames = new Set(facetCheckboxes.map(node => node.dataset.facetName)); | ||
| for (const [key, value] of params.entries()) { | ||
| for (const facetName of facetNames) { | ||
| if (key.startsWith(`limit[${facetName}]`)) { | ||
| params.delete(key); | ||
| } | ||
| for (const [key, value] of Array.from(params.entries())) { | ||
| if (key.startsWith('limit[')) { | ||
| params.delete(key); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. En théorie on peut utiliser les paramètres |
||
| } | ||
| } | ||
|
|
||
|
|
@@ -34,4 +55,21 @@ document.addEventListener('DOMContentLoaded', function () { | |
| }); | ||
| window.location.search = params.toString(); | ||
| } | ||
|
|
||
| function resetFacets() { | ||
| var allInputs = document.querySelectorAll('.search-facets input[type="checkbox"]:checked'); | ||
| allInputs.forEach(input => { | ||
| input.checked = false; | ||
| }); | ||
|
Comment on lines
+61
to
+63
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. À quoi ça sert de décocher puisqu'on redirige juste après ( |
||
|
|
||
| var params = new URLSearchParams(window.location.search); | ||
| var newParams = new URLSearchParams(); | ||
|
|
||
| for (let [key, value] of params.entries()) { | ||
| if (!key.startsWith('limit[')) { | ||
| newParams.append(key, value); | ||
| } | ||
| } | ||
|
Comment on lines
+68
to
+72
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Même remarque que pour submitFacets, on devrait conserver les paramètres limit qui ne correspondent pas à une facette visible |
||
| window.location.search = newParams.toString(); | ||
| } | ||
| }); | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,7 +40,8 @@ $facetedFiltering = isset($settings['faceted_filtering']) && $settings['faceted_ | |
| <h2> | ||
| <?php echo $this->translate('Filters'); ?> | ||
| <?php if ($facetedFiltering) : ?> | ||
| <button class="fas fa-sync" id="submit-facets" title="<?php echo $this->translate('Filter with selected facets');?>"></button> | ||
| <button class="fas fa-filter" id="submit-facets" title="<?php echo $this->translate('Filter with selected facets');?>"></button> | ||
| <button class="fas fa-times" id="reset-facets" title="<?php echo $this->translate('Reset all filters');?>"></button> | ||
|
Comment on lines
+43
to
+44
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Il manque |
||
| <?php endif; ?> | ||
| </h2> | ||
| <ul> | ||
|
|
@@ -69,8 +70,11 @@ $facetedFiltering = isset($settings['faceted_filtering']) && $settings['faceted_ | |
| </div> | ||
| <?php endif; ?> | ||
| <?php if (!empty($facetValues['hidden'])): ?> | ||
| <button class="search-facet-expand-button"> | ||
| <?php echo $this->escapeHtml($this->searchCurrentPage()->settings()['facet_limit_expand_label']); ?> | ||
| <button id="show-hidden-facets-<?php echo $this->escapeHtml($name); ?>" class="o-icon-down show-hidden-facets-btn" | ||
| data-facet-name="<?php echo $this->escapeHtml($name); ?>" | ||
| data-expand-label="<?php echo $this->escapeHtml($this->searchCurrentPage()->settings()['facet_limit_expand_label']); ?>" | ||
| data-collapse-label="<?php echo $this->escapeHtml($this->searchCurrentPage()->settings()['facet_limit_collapse_label']); ?>"> | ||
| <?php echo $this->escapeHtml($this->searchCurrentPage()->settings()['facet_limit_expand_label']); ?> | ||
| </button> | ||
|
Comment on lines
+75
to
78
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Tu peux utiliser |
||
| <?php endif; ?> | ||
| </li> | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
C'est pas vraiment "theme-friendly": modif de l'icône et de la propriété display + le fait de se baser sur la propriété display pour savoir s'il faut cacher ou montrer le bloc.
Ça annule ce que j'avais fait dans 9c31e68 (où le JS se contente d'ajouter/retirer une classe, tout le reste est fait en CSS)
Pour le bouton qui change d'icône et de libellé, c'est à mon avis plus simple (et plus theme-able) d'avoir 2 boutons, et de cacher l'un ou l'autre selon le besoin.
Ça évite aussi une faille XSS (Si data-*-label contient une balise
<script>par ex, c'est exécuté quand on clique sur le bouton)