Skip to content

Instantly share code, notes, and snippets.

@bscofield
Created September 7, 2008 12:58
Show Gist options
  • Save bscofield/9252 to your computer and use it in GitHub Desktop.
Save bscofield/9252 to your computer and use it in GitHub Desktop.
makeSearchCommand({
name: "Flickr-CC",
url: "http://www.flickr.com/search/?q={QUERY}&w=all&l=cc&ss=0&ct=0",
icon: "http://www.flickr.com/favicon.ico",
description: "Searches <a href=\"http://www.flickr.com\">Flickr</a> for Creative Commons-licensed pictures matching your words.",
preview : function(previewBlock, inputObject){
var inputText = inputObject.text;
if(inputText.length < 1) {
previewBlock.innerHTML = "Searches for photos on Flickr.";
return;
}
previewBlock.innerHTML = "Searching for photos on Flickr...";
var apiUrl = "http://api.flickr.com/services/rest/";
var apiParams = {
api_key: "4ca9aaaf5c2d83260eba9ab68ac1b1ac",
format: "json",
nojsoncallback: 1,
method: "flickr.photos.search",
media: "photos",
license: [1,2,3,4,5,6,7],
text: inputText,
per_page: 8,
sort: "relevance"
};
jQuery.ajax({
type: "GET",
url: apiUrl,
data: apiParams,
datatype: "string",
error: function() {
previewBlock.innerHTML = "<i>Error searching Flickr.</i>";
},
success: function(responseData) {
responseData = Utils.decodeJson(responseData);
if(responseData.stat != "ok") {
previewBlock.innerHTML = "<i>Error searching Flickr.</i>";
return;
}
var previewData = {
numcols: 4,
nummatches: responseData.photos.total,
photos: responseData.photos.photo
};
previewBlock.innerHTML = CmdUtils.renderTemplate({file:"flickr.html"}, previewData);
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment