0

I understand that this question has been asked and answered many times, but I still can't get my theme (using Masonry + Infinite Scroll) working due to my lack of JavaScript knowledge.... Like button isn't clickable for those posts loaded using Infinite Scroll. I feel that 20789608 (updated answer on March 5, 2014) is quite close to what I need, but still can't get mine working (don't know how to incorporate/apply correctly). Here is my codes (relevant part only).

JS

<script type="text/javascript">
jQuery(function($){
// with masonry & jQuery
// init masonry
var $grid = $('.grid').masonry({
// masonry options
    itemSelector: '.grid-item',
    columnWidth: 400,
    gutter: 20,
    fitWidth: true,
});

// get masonry instance
var msnry = $grid.data('masonry');

// layout masonry after each image loads
$grid.imagesLoaded().progress( function() {
    $grid.masonry('layout');
});

{block:IfInfiniteScroll}
// init infinite scroll
$grid.infiniteScroll({
// infinite scroll options
    path: '.pagination_next',
    append: '.for_infinite_scroll',
    outlayer: msnry,
    status: '.page-load-status',
});
{/block:IfInfiniteScroll}
});
</script>

HTML

<div id="content" class="grid">
{block:Posts}
    <article class="{PostType}{block:PermalinkPage} {block:Date}not-{/block:Date}page{/block:PermalinkPage} {TagsAsClasses} for_infinite_scroll">
{block:Text}
    <div class="post grid-item">
        {block:Title}
        <h1><a href="{Permalink}">{Title}</a></h1>
        {/block:Title}
        <div>
        {Body}
        </div>
    </div><!-- .post grid-item -->
{/block:Text}

Will be much much appreciated if you could help me resolve this. Thanks in advance!

1 Answers1

0

Looks like I've found a solution. Replacing codes between {block:IfInfiniteScroll} and {/block:IfInfiniteScroll} with the following seems working.

{block:IfInfiniteScroll}
// init infinite scroll
$grid.infiniteScroll({
// infinite scroll options
    path: '.pagination_next',
    append: '.for_infinite_scroll',
    outlayer: msnry,
    status: '.page-load-status',
});
// making like buttons work using infinite scroll
$grid.on('append.infiniteScroll',function(e,r,p,items){
    var $newElems = $(items);
    var $newElemsIDs = $newElems.map(function(){
        return this.id;
        }).get();
        Tumblr.LikeButton.get_status_by_post_ids($newElemsIDs);
});
{/block:IfInfiniteScroll}
  • Update: For the above code to work, id="{PostID}" needs to be added to each post. So, doing like
    (depending on how your theme is written).
    –  Jan 27 '19 at 13:52