Created
April 17, 2013 09:34
-
-
Save rgaidot/5403026 to your computer and use it in GitHub Desktop.
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
(($) -> | |
$.instagramPictures = (el, options) -> | |
base = this | |
base.$el = $(el) | |
base.el = el | |
base.photos = {} | |
base.$el.data "instagramPictures", base | |
base.init = -> | |
base.options = $.extend({}, $.instagramPictures.defaultOptions, options) | |
alert "The jQuery Instagram plugin need an access token" if typeof (base.options.accessToken) is "undefined" or base.options.accessToken is null | |
base.loadPictures() | |
base.loadPictures = (searchVal) -> | |
searchVal = base.options.search if typeof (searchVal) is "undefined" or searchVal is null | |
$.ajax | |
url: "https://api.instagram.com/v1/tags/" + searchVal + "/media/recent" | |
type: "GET" | |
dataType: "jsonp" | |
data: "access_token=" + base.options.accessToken + "&count=" + base.options.count | |
success: (response) -> | |
base.photos = response.data | |
base.displayPictures() | |
error: (error) -> | |
console.log error | |
base.displayPictures = -> | |
$.each base.photos, (index, value) -> | |
thumbsURL = value.images.thumbnail.url | |
base.$el.append "<img src=\"" + thumbsURL + "\">" | |
base.init() | |
$.instagramPictures.defaultOptions = | |
count: 20 | |
search: "lolcat" | |
$.fn.instagramPictures = (options) -> | |
@search = (searchVal) -> | |
searchVal = $.instagramPictures.defaultOptions.search if typeof (searchVal) is "undefined" or searchVal is null or searchVal is "" | |
@data("instagramPictures").loadPictures searchVal | |
@each -> | |
new $.instagramPictures(this, options) | |
$.fn.getInstagramPictures = -> | |
@data "instagramPictures" | |
) jQuery |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment