Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
The show fewer links did not work for my facets. I debugged the code and the tiny change that needs to be made to make them work right is to change in the block of code for "Show More/Show Fewer" functionality that starts on line 40 of facetapi.js
// Adds "Show more" / "Show fewer" links as appropriate.
$('ul#' + settings.id).filter(function() {
return $(this).find('li').length > settings.limit;
}).each(function() {
$('<a href="#" class="facetapi-limit-link"></a>').text(Drupal.t(settings.showMoreText)).click(function() {
if ($(this).siblings('ul').find('li:hidden').length > 0) {
$(this).siblings().find('li:gt(' + limit + ')').slideDown();
$(this).addClass('open').text(Drupal.t(settings.showFewerText));
}
else {
$(this).siblings().find('li:gt(' + limit + ')').slideUp();
$(this).removeClass('open').text(Drupal.t(settings.showMoreText));
}
return false;
}).insertAfter($(this));
});
}
}
Change (line 45):
if ($(this).siblings().find('li:hidden').length > 0) {
To:
if ($(this).siblings('ul').find('li:hidden').length > 0) {
Note the addition of the sibling filter of 'ul'
I can generate a patch for this if others need it, I could not find it as a reported issue though.
Comment | File | Size | Author |
---|---|---|---|
#16 | facetapi-2327997-16-show-fewer-links.patch | 1021 bytes | joseph.olstad |
|
Comments
Comment #1
Leksat CreditAttribution: Leksat commentedDrCord's solution works good for me.
Comment #2
zterry95 CreditAttribution: zterry95 commentedconfirm it works. Thanks.
Comment #3
milesw CreditAttribution: milesw commentedHere's a patch.
Also cleans up some variables to avoid redundant jQuery selection (perhaps a bit faster) and to make more readable.
Comment #4
zterry95 CreditAttribution: zterry95 commentedComment #5
heddn+1 on #3. Works for me on a search api site.
Comment #6
robertstaddon CreditAttribution: robertstaddon commentedI was having the same problem and the #3 patch solved it! Thanks!
The cause of the issue appears to be the .siblings() selector grabbing four additional hidden links from the "Contextual Links" area that is automatically inserted into blocks for administrators. Thus, it only breaks for administrators who are logged into the site.
Comment #7
nareshbw CreditAttribution: nareshbw commentedPatch # 3 is working fine for me .
Comment #8
monstrfolk CreditAttribution: monstrfolk commentedPatch #3 works for me.
Comment #9
fox_01 CreditAttribution: fox_01 commentedPatch #3 works for me.
Comment #10
ozinPatch #3 works for me as well. Good job!!!
Comment #11
Helice CreditAttribution: Helice commentedPatch #3 works for me.
Comment #12
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commentedHello
Unfortunately, I cannot reproduce this issue. For me "show more/show fewer" works well.
Also cannot reproduce it for administrator.
Comment #13
doostinharrell CreditAttribution: doostinharrell commentedI was also experiencing this issue running a Bootstrap 3.8 sub-theme. Creating a new block template (block--facetapi.tpl.php) based off of the core block template (/modules/block/block.tpl.php) resolved my issues. I'm guessing this is related to markup. I propose we create and include a new block template for facets to further minimize this impacting any other users.
@eugene.ilyin, I'm happy to take the lead on that unless you have any better ideas?
Comment #14
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commented@doostinharrell what do you mean? Lead the investigation of this issue? Why not? I'm appreciate for any help.
Comment #15
alexrayu CreditAttribution: alexrayu commentedSubscribing. Please consider using the 'open' class as a switch. Please consider the patch attached.
Update: Yes, using Bootstrap. The condition finds li:hidden siblings always and always returns TRUE. It seems that using a search for siblings is a logical duplicity. We need to have a pure switch, like 1 or 0, has class or not. Looking for more hidden elements would only make sense if you would want to expand the controls some more and show another set of them. Otherwise, it has edge cases like for us with bootstrap.
Comment #16
joseph.olstadRTBC+1 , just had to reroll patch 15 (against latest dev)
Here's the reroll. Works great.
Comment #17
joseph.olstadAlso, FYI, tested using bootstrap (drupal.org/project/bootstrap) latest release, and (facetapi 7.x-1.5+22-dev)
patch applies to head of facetapi 7.x-1.x branch
Comment #18
ultimike+1 for this patch.
I found that this issue only occurs for non-anonymous users.
-mike
Comment #19
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commentedI'll back from vacation in September and then I can check it. Don't hesitate to ping me directly. Let's finish with it.
Comment #21
eugene.ilyin CreditAttribution: eugene.ilyin as a volunteer and at DrupalJedi commented