22lip jQuery Picbox gallery using Picasa JSON feed
I’m running small website for my friend and there always be an issue with updating the gallery, because I had to manually upload photos and then change JavaScript code as well.
Fortunately he’s using Google Picasa Web Albums which we’ll use as a JSON feed and show on our site using JavaScript only – specially jQuery Picbox gallery.
Let’s consider example gallery at Picasa:
http://picasaweb.google.com/114870412886981821775/FIFAWORLDCUPGIRL2010
At the right there is RSS link which looks like this:
http://picasaweb.google.com/data/feed/base/user/114870412886981821775/albumid/5486865816083035937?alt=rss&kind=photo&hl=pl
Due to Picasa Web Albums query parameters reference we change alt param to json and add imgmax and callback in which we pass the name of the function to invoke after the feed is loaded.
In the head section jQuery and Picbox must be included:
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script> <script type="text/javascript" src="jquery.picbox.min.js"></script> <link href="picbox.css" media="screen" rel="Stylesheet" type="text/css" />
And all is needed in body section:
<a href="#" id="gallery"><h1>FIFA WORLD CUP GIRLS 2010</h1></a> <img id="gallery-loader" src="ajax-loader.gif" style="display: none;"/>
and then JS:
var Gal = {
//Max image width form Picasa
// 94, 110, 128, 200, 220, 288, 320, 400, 512, 576, 640, 720, 800, 912, 1024, 1152, 1280, 1440, 1600
imgMax:800,
//Array of photos
photos: [],
//Loader image
loaderImg: $('#gallery-loader'),
init: function() {
if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
$('#gallery').bind('click',function(e){
//Prevent default click event
e.preventDefault();
//Show loader
Gal.loaderImg.show();
//Add JSON feed from Picasa with parameter callback = Gal.prepare to BODY
$('BODY').append('<script src="http://picasaweb.google.com/data/feed/base/user/114870412886981821775/albumid/5486865816083035937?alt=json&kind=photo&hl=pl&imgmax='+Gal.imgMax+'&callback=Gal.prepare">'+'</sc'+'ript>');
});
}
},
//data array with photos from Picasa
prepare: function(data){
var i = data.feed.entry.length;
//Start with random photo
var start = Math.floor(Math.random()*i+1)
//Define vars at once
var item,title,imageurl;
//Iterate thru data
while (i--) {
item = data.feed.entry[i];
title = item.title.$t;
imageurl = item.media$group.media$content[0].url;
//Other possible data
//var width = item.media$group.media$content[0].width;
//var height = item.media$group.media$content[0].height;
//var description = item.media$group.media$description.$t;
//var link = item.link[2].href;
//Add photo to photos array
Gal.photos.push([imageurl,title]);
}
//Show gallery
Gal.show(start);
},
show: function(start){
//Start picbox gallery
$.picbox(Gal.photos,start,{'loop':true});
//Hide loader
Gal.loaderImg.hide();
}
}
$(document).ready(function(){ Gal.init(); });
And that’s it!
I think this solution has two major advantages: photos can be changed directly in Picasa by 3rd party admin and they are served via Google CDN.




Sierpień 23rd, 2010 at 23:27
Just another Wow! Earlier wow does appear so another WOW!
Sierpień 24th, 2010 at 1:44
Hi,
I see that loading image when Images are browsed is not showing up when either I run your script from my server or save it locally on my computer. Why is it so?
However, when I run gallery @ your site (in IE) the loading .. i.e. ajax throbber does show, on your domain only and not even locally or localhost @ my place.
Conditions are same (not showing loader img) for both Opera and IE6 (locally file:// as well as hosted localhost)
Pls clarify
Sierpień 24th, 2010 at 11:29
Look here:
http://keemor.com/demo/picasa/picbox.css
This css uses 3 other files:
http://keemor.com/demo/picasa/closebutton.png
http://keemor.com/demo/picasa/loading.gif
http://keemor.com/demo/picasa/navbtns.png
You have to download them as well
Sierpień 25th, 2010 at 4:52
Thank You! These files were different I saved them to the _files folder as saved and it works. I believe these were diofferent
Thanks a Bunch!
Sierpień 25th, 2010 at 5:19
Author @ Keemor.com
Here’s the Flickr version (simple no imagemax etc.)
(Flickr Limits feed to 20 items, you may use its api with key for more item display)
LINES TO EDIT IN MAIN HTML
===========================
> $(’BODY’).append would have: (Example JSON Flickr Feed)
http://api.flickr.com/services/feeds/groups_pool.gne?id=675729@N22&lang=en-us&format=json&jsoncallback=Gal.prepare
> Changes in function(data)
1. var i = data.items.length;
2. In while loop
item = data.items[i];
title = item.title;
imageurl = item.media.m;
All DONE…Easy 1. 2 . 3
SHERLYN
Sierpień 25th, 2010 at 9:54
Here is a similar solution which I found yesterday:
http://viatropos.com/blog/picasa-jquery-plugin/
and it works as a jQuery plugin