Created
March 15, 2015 19:45
-
-
Save jamc92/7e8689b0451368194141 to your computer and use it in GitHub Desktop.
jSON - Using jSON with Flickr
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
// Calling our function with a parameter as ID | |
function loadFlickr(flickrId) { | |
//Display a loading icon in our display element | |
$('#feed').html('<span><img src="/blog/images/lightbox-ico-loading.gif" alt=""></span>'); | |
// Request the JSON and process it | |
$.ajax({ | |
type:'GET', | |
url:"http://api.flickr.com/services/feeds/photos_public.gne", | |
data:"id"+flickrId+"&lang=en-us&format=json&jsoncallback=?", | |
success: function(feed) { | |
//Create an empty array to store images | |
var thumbs = []; | |
//Loop through the items | |
for (var i=0, l=feed.items.length; i < l && i < 16; i){ | |
// Manipulate the image to get thumb and medium sizes | |
var img = feed.items[i].media.m.replace( | |
/^(.*?)_m.jpg$/, | |
'<a href="/blog/$1.jpg"><img src="/blog/$1_s.jpg" alt=""></a>' | |
); | |
//Add the new element to the array | |
thumbs.push(img); | |
} | |
// Display the thumbnails on the page | |
$('#feed').html(thumbs.join('')); | |
// A function to add a lightbox effect | |
addLB(); | |
}, | |
dataType:'jsonp' | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment