Doesn't work with AJAX loaded content #19

Closed
nikolaydyankov opened this Issue Apr 30, 2012 · 2 comments

Comments

Projects
None yet
2 participants

When a content is loaded with AJAX the script doesn't activate. You can see it in action here (it's my company site, no advertising intended): http://nikolaydyankovdesign.com/

The small black & white images on the homepage have retina versions, I checked the filenames. In the inner pages where the content is static it works fine.

I understand it can't know when a content is loaded, but a hook for refreshing the script would work just fine.

Great job with this script, keep it up!

Contributor

caseyohara commented Apr 30, 2012

@nikolaydyankov Yes, it does not automatically detect when new content has loaded, but we do have a means for refreshing the script.

See issue #14 for details on that.

Basically, the callback for the function that is loading in more content, you can to feed it any the new images on the page that you want swapped in.

In your case, you can modify your $.post callback in your make_request() function to look something like this:

  $.post(
    MyAjax.ajaxurl,
    {
      action : 'load_projects',
      cat : cat
    },
    function(data) {
      productsWrap.append(data);
      $('img').each(function(){
        new RetinaImage(this);
      });
      loader.hide();
    }
  );

The important bit is this here:

$('img').each(function(){
  new RetinaImage(this);
});

Let us know how this works for you or if you have any ideas of how to make it easier to use.

Worked perfectly, thanks! Great job with this script.

@caseyohara caseyohara closed this May 3, 2012

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment