Score:0

Integrating jQuery Auto Height with Views Infinite Scroll

mw flag
H M

I have a views block with an infinite scroll (using Views Bootstrap and Views Infinite Scroll modules). The block displays cards and I want them to have the same height. jQuery Auto Height does that well. However, it only happens for the initial load. Auto Height has no way of knowing to fire on subsequent Ajax calls. What is the best way to integrate them so that Auto Height is called on each infinite scroll Ajax call?

Score:0
in flag

If you take a look at the source for the jQuery Auto height module, there appears to be an AutoHeight() method that you can call on a given jQuery object.

$(drupalSettings.auto_height.selectors).AutoHeight();

And in the source for Views Infinite Scroll, we can see that an event, scroll.views_infinite_scroll, is available to listen in on. The portion of Views Infinite Scroll's code that invokes this event is:

$window.on(scrollEvent, debounce(function () {
  if (isLoadNeeded()) {
    $pager.find('[rel=next]').click();
    $window.off(scrollEvent);
  }
}, 200));

Using the above as a template, I think you could invoke the AutoHeight() method every time a new view is added.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.