Skip to content

Instantly share code, notes, and snippets.

@rgaidot
Created April 17, 2013 09:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rgaidot/5403026 to your computer and use it in GitHub Desktop.
Save rgaidot/5403026 to your computer and use it in GitHub Desktop.
(($) ->
$.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