Last active
September 21, 2015 22:06
-
-
Save jensechu/90851c184aa5b0ba80f2 to your computer and use it in GitHub Desktop.
Instagram Feed
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
InstagramFeed = function() { | |
var self = this; | |
self.props = { | |
$feedContainer: $('#instagram-feed-container'), | |
IMAGE_TEMPLATE: $('#contest-image-template').html(), | |
ACCESS_TOKEN: '1711440167.ac32776.52e47348e60a4bdda0b90d79507a08ae', | |
finalFeed: '' | |
}; | |
self._setDependencies = function(options) { | |
$.extend(self.props, options); | |
self.props.url = 'https://api.instagram.com/v1/tags/' + self.props.hashtag + '/media/recent?access_token=' + self.props.ACCESS_TOKEN + '&count=' + self.props.count; | |
}; | |
self._gatherPhotos = function() { | |
$.ajax({ | |
url: self.props.url, | |
type: 'GET', | |
dataType: 'jsonp', | |
error: function(xhr, status, error) { | |
return; | |
}, | |
success: function(resp, status) { | |
self._gatherPhotoData(resp); | |
} | |
}); | |
}; | |
self._gatherPhotoData = function(photos) { | |
$.each(photos.data, function() { | |
var imageURL = this.images.standard_resolution.url; | |
var authorURL = this.link; | |
self._buildPhotoElement(imageURL, authorURL); | |
}); | |
self._addAllPhotoElements(); | |
}; | |
self._buildPhotoElement = function(imageURL, authorURL) { | |
var $photoContainer = $(self.props.IMAGE_TEMPLATE); | |
var $photo = $photoContainer.find('.instagram-photo'); | |
var $photoLink = $photoContainer.find('.instagram-author-link'); | |
$photo.attr('src', imageURL); | |
$photoLink.attr('href', authorURL); | |
self._addPhotoElement($photoContainer); | |
}; | |
self._addPhotoElement = function($photoContainer) { | |
self.props.finalFeed = self.props.finalFeed + $photoContainer[0].outerHTML; | |
}; | |
self._addAllPhotoElements = function($photoContainer) { | |
self.props.$feedContainer.html(self.props.finalFeed); | |
}; | |
self.init = function(options) { | |
self._setDependencies(options); | |
self._gatherPhotos(); | |
}; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment