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.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Leksat’s picture

DrCord's solution works good for me.

zterry95’s picture

confirm it works. Thanks.

milesw’s picture

Status: Active » Needs review
FileSize
2.51 KB

Here's a patch.

Also cleans up some variables to avoid redundant jQuery selection (perhaps a bit faster) and to make more readable.

zterry95’s picture

Status: Needs review » Reviewed & tested by the community
heddn’s picture

+1 on #3. Works for me on a search api site.

robertstaddon’s picture

I 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.

nareshbw’s picture

Patch # 3 is working fine for me .

monstrfolk’s picture

Patch #3 works for me.

fox_01’s picture

Patch #3 works for me.

ozin’s picture

Patch #3 works for me as well. Good job!!!

Helice’s picture

Patch #3 works for me.

eugene.ilyin’s picture

Status: Reviewed & tested by the community » Postponed (maintainer needs more info)

Hello

Unfortunately, I cannot reproduce this issue. For me "show more/show fewer" works well.

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.

Also cannot reproduce it for administrator.

doostinharrell’s picture

I 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?

eugene.ilyin’s picture

@eugene.ilyin, I'm happy to take the lead on that unless you have any better ideas?

@doostinharrell what do you mean? Lead the investigation of this issue? Why not? I'm appreciate for any help.

alexrayu’s picture

Subscribing. 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.

joseph.olstad’s picture

Status: Postponed (maintainer needs more info) » Needs review
FileSize
1021 bytes

RTBC+1 , just had to reroll patch 15 (against latest dev)

Here's the reroll. Works great.

joseph.olstad’s picture

Also, 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

ultimike’s picture

+1 for this patch.

I found that this issue only occurs for non-anonymous users.

-mike

eugene.ilyin’s picture

I'll back from vacation in September and then I can check it. Don't hesitate to ping me directly. Let's finish with it.

  • eugene.ilyin committed c7c1d91 on 7.x-1.x authored by alexrayu
    Issue #2327997 by joseph.olstad, milesw, alexrayu, eugene.ilyin: Show...
eugene.ilyin’s picture

Status: Needs review » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.