Created
January 9, 2010 04:01
-
-
Save elijahmanor/272702 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
(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); |
This file contains hidden or 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
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