Search code examples
javascriptjqueryruby-on-railsinfinite-scrollkaminari

jQuery infinitescroll, kaminari, and Rails 4. Infinitescroll triggering on another page. Not after refresh


Running into a weird behaviour using Paul Irish's infinitescroll plugin with kaminari and rails 4. I've followed the example given on kaminari's wiki, and have the following code:

$(document).ready ->
    $("#activities .activityBox").infinitescroll
        navSelector: "ul.pagination"
        nextSelector: "ul.pagination a[rel=next]"
        itemSelector: "#activities div.activityBox"

The infinitescroll plugin works perfectly on pages#home where the div#activities element is located. What's not working as intended however is that the plugin is still firing AFTER I navigate away from pages#home.

For instance, I would be browsing on pages#home. I'd click a link to Tags#index. When I scroll to the bottom of Tags#index, infinitescroll would fetch and render the next batch of activities. The behaviour stops after refreshing the page with the browser.

How do I get infinitescroll to fire only when div#activities is present?


Solution

  • After hours of experimentation, I've decided to abandon the jquery.infinitescroll plugin.

    Ryan Bates' implementation here works fine, doesn't require an external plugin, and is compatible with turbolinks.