Created
March 10, 2013 23:02
-
-
Save kristjanmik/5130899 to your computer and use it in GitHub Desktop.
Instagram code on nfvi.is
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
(function($){ | |
$.fn.instagram = function(options) { | |
var that = this, | |
apiEndpoint = "https://api.instagram.com/v1", | |
settings = { | |
hash: null | |
, userId: null | |
, locationId: null | |
, search: null | |
, accessToken: null | |
, clientId: null | |
, show: null | |
, onLoad: null | |
, onComplete: null | |
, maxId: null | |
, minId: null | |
, next_url: null | |
}; | |
options && $.extend(settings, options); | |
function createPhotoElement(photo) { | |
return $('<div>') | |
.addClass('instagram-placeholder') | |
.attr('id', photo.id) | |
.append( | |
$('<a>') | |
.attr('target', '_blank') | |
.attr('href', photo.link) | |
.append( | |
$('<img>') | |
.addClass('instagram-image') | |
.attr('src', photo.images.thumbnail.url) | |
) | |
); | |
} | |
function createEmptyElement() { | |
return $('<div>') | |
.addClass('instagram-placeholder') | |
.attr('id', 'empty') | |
.append($('<p>').html('No photos for this query')); | |
} | |
function composeRequestURL() { | |
var url = apiEndpoint, | |
params = {}; | |
if (settings.next_url != null) { | |
return settings.next_url; | |
} | |
if(settings.hash != null) { | |
url += "/tags/" + settings.hash + "/media/recent"; | |
} | |
else if(settings.search != null) { | |
url += "/media/search"; | |
params.lat = settings.search.lat; | |
params.lng = settings.search.lng; | |
settings.search.max_timestamp != null && (params.max_timestamp = settings.search.max_timestamp); | |
settings.search.min_timestamp != null && (params.min_timestamp = settings.search.min_timestamp); | |
settings.search.distance != null && (params.distance = settings.search.distance); | |
} | |
else if(settings.userId != null) { | |
url += "/users/" + settings.userId + "/media/recent"; | |
} | |
else if(settings.locationId != null) { | |
url += "/locations/" + settings.locationId + "/media/recent"; | |
} | |
else { | |
url += "/media/popular"; | |
} | |
settings.accessToken != null && (params.access_token = settings.accessToken); | |
settings.clientId != null && (params.client_id = settings.clientId); | |
settings.minId != null && (params.min_id = settings.minId); | |
settings.maxId != null && (params.max_id = settings.maxId); | |
url += "?" + $.param(params) | |
return url; | |
} | |
settings.onLoad != null && typeof settings.onLoad == 'function' && settings.onLoad(); | |
$.ajax({ | |
type: "GET", | |
dataType: "jsonp", | |
cache: false, | |
url: composeRequestURL(), | |
success: function(res) { | |
var length = typeof res.data != 'undefined' ? res.data.length : 0; | |
var limit = settings.show != null && settings.show < length ? settings.show : length; | |
if(limit > 0) { | |
for(var i = 0; i < limit; i++) { | |
that.append(createPhotoElement(res.data[i])); | |
} | |
} | |
else { | |
that.append(createEmptyElement()); | |
} | |
settings.onComplete != null && typeof settings.onComplete == 'function' && settings.onComplete(res.data, res); | |
} | |
}); | |
return this; | |
}; | |
})(jQuery); | |
$(".instagram-images").instagram({ | |
hash: 'your-instagram-tag-here', | |
clientId: 'b21bdd9f448846e2a7aafa5b1d8b31b0',//Ekki nota okkar client id takk | |
show: 2 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Ekki svolítið shaky að hafa clientId-ið í gisti?