Table of Content
View photo
Now comes the reveal part. It is almost the same as the News module, just now news entry becomes photo.
The #photo-view
page.
The CSS for some photos styles.
And add the data-photo-id
to each photo link in the photos list.
1$(element).append("<a href='#photo-view' data-photo-id='" + i + "'><div class='photo' style='background-image:url( " + image.picture + ")'></div></a>");
When displaying the photo, we get the photo ID and use it to find the photo object. Then finally display the image in an img
tag.
1// Photo view 2$('#photos').delegate('a[href="#photo-view"]', 'click', function(event){ 3 var photoId = $(this).data('photoId'); 4 5 var contentElement = $('#photo'); 6 var photoData = fbPhotos.photos.data[photoId]; 7 if (photoData === undefined) 8 { 9 contentElement.html('Error loading photo.'); 10 } 11 else { 12 var text = "<img src='" + photoData.images[2].source + "' alt='photo' class='big-photo'>"; 13 14 contentElement.html(text); 15 } 16}); // End Photo view
What’s next? We’re going to take a look at “Setup mongolab”.