jQuery each loop is not working -
i put code based off reading other stackoverflow questions , tested in fiddle , works jsfiddle
tried implement in clearfix function in project (at bottom) , cant work. tried putting in numerous places didnt change anything. placed console logs along code see gets , never fires function. want insert clearfix div every 3 divs have class col-md-3.
i'm sure lack of knowledge have wrong. starting learn , piece code together. here code -
(function () { 'use strict'; window.insta = { apiurl: 'https://api.instagram.com/v1/users/self/feed?access_token=[token goes here]&callback=?', grams: {}, init: function () { $.ajax({ type: 'get', url: insta.apiurl, datatype: 'json', success: insta.success }); }, rendergrams: function (grams) { $.each(grams, function(index, gram) { insta.grams[gram.id] = gram; var gramhtml = '<div class="col-md-3"><p><img class="img-circle" style="margin-right: 5px" width="60" src="' + gram.user.profile_picture + '">' + gram.user.username + '</p><a href="#mymodal" data-toggle="modal" data-media-id="' + gram.id +'">'; if (gram.type === 'image') { gramhtml = gramhtml + '<img class="img-thumbnail" src="' + gram.images.low_resolution.url + '"/>'; } if (gram.type === 'video') { gramhtml = gramhtml + '<video class="img-thumbnail" src="' + gram.videos.low_resolution.url + '"/>'; } gramhtml = gramhtml + '</a></div>'; $('.results').append(gramhtml); }); }, setupclickevent: function () { $('a').click(function(){ var mediaid = $(this).data('mediaid'), gram = insta.grams[mediaid], largeimage = gram.images.standard_resolution.url, username = gram.user.username, tags = gram.tags, comments = ''; $('.modal-title').html(username); $('.modal-body').html('<div class="col-md-6"><img class="img-responsive" src="' + largeimage + '"><div class="tagwrap">' + tags + '</div></div>'); $.each(gram.comments.data, function(index, comment){ comments += '<p>' + comment.text + '</p>'; }); $('.modal-body').append('<div class="comment-container">' + comments + '</div>'); }); }, success: function (responsedata) { if (responsedata.meta.code === 200) { insta.rendergrams(responsedata.data); insta.setupclickevent(); } else { $('.results').html('<h1>an error occured</h1><p>' + responsedata.meta.error_message + '</p>'); } }, clearfix: function () { $('.col-md-3').each(function(i,val){ i++; if(i%3===0){ $(this).append('<div class="clearfix"></div>'); } }); }, }; // fires fires off // follow here insta.init(); }());
Comments
Post a Comment