diff --git a/clients/chrome/clip-it-good/background.html b/clients/chrome/clip-it-good/background.html index e337cf124..197715a0b 100644 --- a/clients/chrome/clip-it-good/background.html +++ b/clients/chrome/clip-it-good/background.html @@ -77,7 +77,7 @@ contexts: ['image'], onclick: function(data, tab) { return handleMenuClick( - albumDict.name, albumDict.id, data, tab) + albumType, albumDict.name, albumDict.id, data, tab) } }); }); @@ -85,7 +85,33 @@ }); } - function handleMenuClick(albumName, albumId, data, tab) { + // Upload actions + var ALBUM_TYPE_UPLOAD_FUNC = { + + 'picasa': function(albumId, albumName, dataSrcUrl, dataBlob, xhrDone) { + OAUTH.authorize(function() { + OAUTH.sendSignedRequest( + 'http://picasaweb.google.com/data/feed/api/' + + 'user/default/albumid/' + albumId, + xhrDone, + { + method: 'POST', + headers: { + 'Content-Type': 'image/png', + 'Slug': dataSrcUrl + }, + parameters: { + alt: 'json' + }, + body: dataBlob + } + ); + }); + } + + }; + + function handleMenuClick(albumType, albumName, albumId, data, tab) { chrome.pageAction.setTitle({ tabId: tab.id, title: 'Clip It Good: Uploading (' + data.srcUrl.substr(0, 100) + ')' @@ -113,24 +139,9 @@ } } // end complete - OAUTH.authorize(function() { - OAUTH.sendSignedRequest( - 'http://picasaweb.google.com/data/feed/api/' + - 'user/default/albumid/' + albumId, - complete, - { - method: 'POST', - headers: { - 'Content-Type': 'image/png', - 'Slug': data.srcUrl - }, - parameters: { - alt: 'json' - }, - body: builder.getBlob('image/png') - } - ); - }); + var uploadFunc = ALBUM_TYPE_UPLOAD_FUNC[albumType]; + uploadFunc(albumId, albumName, data.srcUrl, + builder.getBlob('image/png'), complete); } // end onload img.src = data.srcUrl;