0

I am using pjax and masonry in my tumblr theme. I just figured out how to get masonry to work after clicking a pjax'd link, but now the problem is that the like button is not working anymore. Here is my code so far:

html:

<article class="entry" id="{PostID}">

</article>

jquery:

$(document).ajaxComplete(function(){
   $('#content').imagesLoaded(function(){
      $('#content').masonry('reloadItems').masonry();
   });

   var $newPosts   = $(data).find('.entry');
   var $newPostIDs = $newPosts.map(function () {
     return this.id;
   }).get();

   Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);
});
mikedidthis
  • 4,899
  • 3
  • 28
  • 43
Ely
  • 21
  • 9
  • 3
    `$(data).find('.entry');` what is `data` here? – Alex May 08 '15 at 09:30
  • I changed `div` to `article` just like what it says here [link](http://stackoverflow.com/questions/18245238/tumblr-like-button-not-working-after-infinite-scroll-ajax-recall), but it is still not working. – Ely May 08 '15 at 10:26
  • Are you getting errors in the console? Can you post a link to the tumblr? – lharby May 08 '15 at 10:33
  • `.ajaxComplete()` is a jQuery method, not a `pjax` method. `data` is an object that should contain a collection of new elements added to the page. – mikedidthis May 08 '15 at 11:56
  • My tumblr - [link](http://asphyxiatcd.tumblr.com) - Not sure if I'm getting errors in the console though? I'm not really that good in javascript. – Ely May 08 '15 at 12:14

1 Answers1

1

I believe you need to use pjax:success. This should give you the data object.

$(document).on('pjax:success', function( event, data, status, xhr, options ) {

 $('#content').imagesLoaded(function(){
    $('#content').masonry('reloadItems').masonry();
 });

 var $newPosts   = $(data).find('.entry');
 var $newPostIDs = $newPosts.map(function () {
   return this.id;
 }).get();

 Tumblr.LikeButton.get_status_by_post_ids($newPostIDs);

});

Source: https://github.com/defunkt/jquery-pjax#events

mikedidthis
  • 4,899
  • 3
  • 28
  • 43
  • 1
    It worked! Thank you! I actually used `pjax:success` before to see if masonry would work, but it didn't. I guess I was missing `event, data, status, xhr, options` in the function. Thanks again! – Ely May 08 '15 at 12:39