Skip to content
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

Fix AJAX facet handling issues. #4120

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions module/VuFind/src/VuFind/AjaxHandler/GetSideFacets.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
use VuFind\Search\SearchRunner;
use VuFind\Session\Settings as SessionSettings;

use function in_array;
use function is_callable;

/**
Expand Down Expand Up @@ -227,10 +228,10 @@ protected function formatFacets(
) {
$response = [];
$facetSet = $recommend->getFacetSet();
$checkboxFacets = array_column($recommend->getCheckboxFacetSet(), 'filter');
foreach ($facets as $facet) {
if (strpos($facet, ':')) {
$response[$facet]['checkboxCount']
= $this->getCheckboxFacetCount($facet, $results);
if (in_array($facet, $checkboxFacets)) {
$response[$facet]['checkboxCount'] = $this->getCheckboxFacetCount($facet, $results);
} else {
$context['facet'] = $facet;
$context['cluster'] = $facetSet[$facet] ?? [
Expand Down
18 changes: 13 additions & 5 deletions themes/bootstrap3/js/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ VuFind.register('sideFacets', function SideFacets() {
var facetList = [];
var $facets = $container.find('div.collapse.in[data-facet], div.collapse.show[data-facet], .checkbox-filters [data-facet]');
$facets.each(function addFacet() {
if (!$(this).data('loaded')) {
if (!$(this).data('initialized')) {
facetList.push($(this).data('facet'));
$(this).data('initialized', 'true');
}
});
if (facetList.length === 0) {
Expand Down Expand Up @@ -485,7 +486,7 @@ VuFind.register('sideFacets', function SideFacets() {
activateFacetBlocking($facetContainer);
}
}
if (isMultiFacetsSelectionEnabled()) {
if (isMultiFacetsSelectionEnabled() && $facetContainer.length > 0) {
VuFind.multiFacetsSelection.initFacetClickHandler($facetContainer.get()[0]);
}
$facetContainer.find('.facet-load-indicator').remove();
Expand All @@ -509,6 +510,13 @@ VuFind.register('sideFacets', function SideFacets() {
$('.side-facets-container-ajax').each(activateSingleAjaxFacetContainer);
}

/**
* Load AJAX side facets with a tiny delay so that all non-collapsed items are available after initialization
*/
function delayLoadAjaxSideFacets() {
setTimeout(loadAjaxSideFacets, 50);
}

function facetSessionStorage(e, data) {
var source = $('#result0 .hiddenSource').val();
var id = e.target.id;
Expand Down Expand Up @@ -551,13 +559,13 @@ VuFind.register('sideFacets', function SideFacets() {
if (VuFind.getBootstrapMajorVersion() === 3) {
$('.side-facets-container-ajax')
.find('div.collapse[data-facet]:not(.in)')
.on('shown.bs.collapse', loadAjaxSideFacets);
.on('shown.bs.collapse', delayLoadAjaxSideFacets);
} else {
document.querySelectorAll('.side-facets-container-ajax div[data-facet]').forEach((collapseEl) => {
collapseEl.addEventListener('shown.bs.collapse', loadAjaxSideFacets);
collapseEl.addEventListener('shown.bs.collapse', delayLoadAjaxSideFacets);
});
}
loadAjaxSideFacets();
delayLoadAjaxSideFacets();

// Keep filter dropdowns on screen
$(".search-filter-dropdown").on("shown.bs.dropdown", function checkFilterDropdownWidth(e) {
Expand Down
18 changes: 13 additions & 5 deletions themes/bootstrap5/js/facets.js
Original file line number Diff line number Diff line change
Expand Up @@ -430,8 +430,9 @@ VuFind.register('sideFacets', function SideFacets() {
var facetList = [];
var $facets = $container.find('div.collapse.in[data-facet], div.collapse.show[data-facet], .checkbox-filters [data-facet]');
$facets.each(function addFacet() {
if (!$(this).data('loaded')) {
if (!$(this).data('initialized')) {
facetList.push($(this).data('facet'));
$(this).data('initialized', 'true');
}
});
if (facetList.length === 0) {
Expand Down Expand Up @@ -485,7 +486,7 @@ VuFind.register('sideFacets', function SideFacets() {
activateFacetBlocking($facetContainer);
}
}
if (isMultiFacetsSelectionEnabled()) {
if (isMultiFacetsSelectionEnabled() && $facetContainer.length > 0) {
VuFind.multiFacetsSelection.initFacetClickHandler($facetContainer.get()[0]);
}
$facetContainer.find('.facet-load-indicator').remove();
Expand All @@ -509,6 +510,13 @@ VuFind.register('sideFacets', function SideFacets() {
$('.side-facets-container-ajax').each(activateSingleAjaxFacetContainer);
}

/**
* Load AJAX side facets with a tiny delay so that all non-collapsed items are available after initialization
*/
function delayLoadAjaxSideFacets() {
setTimeout(loadAjaxSideFacets, 50);
}

function facetSessionStorage(e, data) {
var source = $('#result0 .hiddenSource').val();
var id = e.target.id;
Expand Down Expand Up @@ -551,13 +559,13 @@ VuFind.register('sideFacets', function SideFacets() {
if (VuFind.getBootstrapMajorVersion() === 3) {
$('.side-facets-container-ajax')
.find('div.collapse[data-facet]:not(.in)')
.on('shown.bs.collapse', loadAjaxSideFacets);
.on('shown.bs.collapse', delayLoadAjaxSideFacets);
} else {
document.querySelectorAll('.side-facets-container-ajax div[data-facet]').forEach((collapseEl) => {
collapseEl.addEventListener('shown.bs.collapse', loadAjaxSideFacets);
collapseEl.addEventListener('shown.bs.collapse', delayLoadAjaxSideFacets);
});
}
loadAjaxSideFacets();
delayLoadAjaxSideFacets();

// Keep filter dropdowns on screen
$(".search-filter-dropdown").on("shown.bs.dropdown", function checkFilterDropdownWidth(e) {
Expand Down