potomak / jquery-instagram

Instagram jQuery plugin
http://potomak.github.io/jquery-instagram/
MIT License
554 stars 143 forks source link

Images appending twice #58

Closed saryan7 closed 9 years ago

saryan7 commented 9 years ago

Hi, This is probably just a dumb mistake I'm making but I'm having a problem with the

$('.instagram').on('didLoadInstagram', function(event, response)

running twice so my images get appended twice. I know its running twice because I checked it with a print statement. Here is the full function in my code:

$('button').click(function(){
    jQuery(function($) {
      $("#pictures").html("");
      $('.instagram').on('willLoadInstagram', function(event, options) {
        console.log(options);
      });
      $('.instagram').on('didLoadInstagram', function(event, response) {
        console.log(response)
        console.log("go")
        for (i = 0; i < response.data.length; i++) {
            var DOM_img = document.createElement("img");
            var link = document.createElement('a'); 
            DOM_img.setAttribute('src', response.data[i].images.thumbnail.url);
            link.setAttribute('href', response.data[i].link);
            link.appendChild(DOM_img)
            pictures.appendChild(link);
        }

      });
      $('.instagram').instagram({
        search: {
        lat: lat,
        lng: lng,
        distance: document.getElementById('Distance').value
      },
        count : 33,
        clientId: 'removed'
      });
    });
});

Thanks for any help on this

potomak commented 9 years ago

There's nothing special going on with in the instagram function, it just triggers a didLoadIntagram event on XHR request success callback, see https://github.com/potomak/jquery-instagram/blob/d23926bf780314525d22b89d857685248618be30/src/instagram.js#L63.

Try to put this question on StackOverflow (or similar) to get help about how to use the library.

Suggestion: I think you can get rid of jQuery(function($) {.