Update soft-limit.js

This commit is contained in:
Kyle Huynh 2023-02-28 10:25:53 -05:00 committed by GitHub
parent 812ca8a37d
commit f1a680e5ad
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,8 @@
//# sourceURL=modules/contrib/islandora/modules/advanced_search/js/facets/soft-limit.js
/**
* @file
* Overrides the soft-limit.js behavior from the 'facets' module.
* As when having many facets the original version causes the page to slow down and snap to hidden when rendering.
* Provides the soft limit functionality.
*/
(function ($) {
'use strict';
@ -42,28 +41,33 @@
});
}
// Hide facets over the limit.
facetsList.each(function () {
$(this).children('li:gt(' + zero_based_limit + ')').once('applysoftlimit').hide();
});
// Add "Show more" / "Show less" links.
facetsList.filter(function () {
return $(this).next('ul').length == 1; // Has expanding list.
return ($(this).find('li').length > limit && $(this).parent().find('a.facets-soft-limit-link').length < 1);
}).each(function () {
var facet = $(this);
var expand = facet.next('ul');
var link = expand.next('a');
var showLessLabel = settings.facets.softLimitSettings[facet_id].showLessLabel;
var showMoreLabel = settings.facets.softLimitSettings[facet_id].showMoreLabel;
link.text(showMoreLabel)
.once()
$('<a href="#" class="facets-soft-limit-link"></a>')
.text(showMoreLabel).attr("aria-expanded", "false")
.on('click', function () {
if (!expand.is(":visible")) {
expand.slideDown();
$(this).addClass('open').text(showLessLabel);
if (facet.find('li:hidden').length > 0) {
facet.find('li:gt(' + zero_based_limit + ')').slideDown();
facet.find('li:lt(' + (zero_based_limit + 2) + ') input').focus();
$(this).addClass('open').text(showLessLabel).attr("aria-expanded", "true");
}
else {
expand.slideUp();
$(this).removeClass('open').text(showMoreLabel);
facet.find('li:gt(' + zero_based_limit + ')').slideUp();
$(this).removeClass('open').text(showMoreLabel).attr("aria-expanded", "false");
}
return false;
})
}).insertAfter($(this));
});
};