Skip to content

Instantly share code, notes, and snippets.

@elijahmanor
Created January 9, 2010 04:01
Show Gist options
  • Save elijahmanor/272702 to your computer and use it in GitHub Desktop.
Save elijahmanor/272702 to your computer and use it in GitHub Desktop.
(function($){
$.PicasaWebViewer = {
jQuery : $,
defaultOptions : {
albumClass: "albumClass",
photoClass: "photoClass",
urlFormat: "http://picasaweb.google.com/data/feed/api/user/{0}?alt=json-in-script",
userName: "elijah.manor"
},
options : null,
overrideOptions : function(options) {
$.PicasaWebViewer.options = $.extend({},$.PicasaWebViewer.defaultOptions, options);
},
getAlbums : function() {
console.group('getAlbums');
var albums = null;
var updatedUrl = $.PicasaWebViewer.options.urlFormat.replace("{0}", $.PicasaWebViewer.options.userName);
$.PicasaWebViewer.jQuery.ajax({ url: updatedUrl,
success: function(data) {
albums = data.feed.entry;
},
dataType: 'jsonp'
});
console.groupEnd('getAlbums');
return albums;
},
displayAlbum : function(album) {
console.log('displayAlbum');
},
clickAlbum : function() {
console.log('clickAlbum');
},
displayAlbums : function(albums) {
console.log('displayAlbums');
},
getAndDisplayPhotos : function(url) {
console.log('getAndDisplayPhotos');
},
getPhotos : function(url) {
console.log('getPhotos');
},
displayPhotos : function(photos) {
console.log('displayPhotos');
}
}
$.fn.picasaWebViewer = function(options){
return this.each(function(){
$.PicasaWebViewer.overrideOptions(options);
var albums = $.PicasaWebViewer.getAlbums();
if (albums) {
$.each(albums, function() {
$.PicasaWebViewer.displayAlbum(this);
});
}
});
};
})(jQuery);
var targetId = "#qunit-target";
module("Picasa Web Viewer", {
setup: function() {
$(targetId).picasaWebViewer({userName: "elijah.manor"});
},
teardown: function() {
}
});
test("Default Options", function() {
same($.PicasaWebViewer.defaultOptions.albumClass, 'albumClass');
same($.PicasaWebViewer.defaultOptions.photoClass, 'photoClass');
same($.PicasaWebViewer.defaultOptions.urlFormat, 'http://picasaweb.google.com/data/feed/api/user/{0}?alt=json-in-script');
same($.PicasaWebViewer.defaultOptions.userName, 'elijah.manor');
});
test("Override Deafult Options", function() {
$.PicasaWebViewer.overrideOptions({userName : 'andrea.manor'});
same($.PicasaWebViewer.options.userName, 'andrea.manor');
});
test("Get Albums", function() {
var mockJquery = new Mock();
mockJquery
.expects(1)
.method('ajax')
.withArguments({
url: String,
success: Function,
dataType: "jsonp"
})
.callFunctionWith({ feed : { entry : "data response" }});
$.PicasaWebViewer.jQuery = mockJquery;
var albums = $.PicasaWebViewer.getAlbums();
ok(albums, "albums != null");
same(albums, "data response");
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment