Surfin' JavaScript Wave

jQuery Picbox gallery using Picasa JSON feed

keemor~22 lipca 2010 /Javascript


Checkout new version at jQuery fullscreen gallery using Google Plus Photos 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:

At the right there is RSS link which looks like this:

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=""></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 
	//Array of photos
	photos: [],	
	//Loader image	
	loaderImg: $('#gallery-loader'),
	init: function() {
		if (!/android|iphone|ipod|series60|symbian|windows ce|blackberry/i.test(navigator.userAgent)) {
				//Prevent default click event
				//Show loader;
				//Add JSON feed from Picasa with parameter callback = Gal.prepare to BODY   																						
				$('BODY').append('<script src=";kind=photo&amp;hl=pl&amp;imgmax='+Gal.imgMax+'&amp;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 =$$content[0].url;
			//Other possible data  				
			//var width =$$content[0].width;
			//var height =$$content[0].height;								
			//var description =$$description.$t;
			//var link =[2].href;
			//Add photo to photos array				[imageurl,title]);				
		//Show gallery;
	show: function(start){
		//Start picbox gallery
		//Hide loader						
$(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.