Permalink
Browse files

Basic functionality with flickr.

  • Loading branch information...
1 parent cd3e407 commit 2757ef32bd5d09503f8dfb36f7ce87aa0f4bdfa0 @scottgonzalez committed Mar 16, 2010
Showing with 57 additions and 0 deletions.
  1. +57 −0 src/js/srchr.js
View
@@ -0,0 +1,57 @@
+(function( $ ) {
+
+var util = {
+ parse: function( str, data ) {
+ return str.replace( /{([^}]+)}/g, function( match, name ) {
+ return name in data ? data[ name ] : "";
+ });
+ },
+
+ peek: function( obj, path ) {
+ path = path.split( "." );
+ while ( path.length ) {
+ obj = obj[ path.shift() ];
+ }
+ return obj;
+ }
+};
+
+var YQL = {
+ url: "http://query.yahooapis.com/v1/public/yql",
+ params: function( service, term ) {
+ return {
+ q: util.parse( service.query, { term: term } ),
+ format: "json"
+ };
+ }
+};
+
+var srchr = window.srchr = {
+ terms: {},
+ services: {},
+
+ addService: function( name, query, items, template ) {
+ srchr.services[ name ] = {
+ query: query,
+ handleResult: function( data ) {
+ $.each( util.peek( data, items), function( i, item ) {
+ var html = util.parse( template, item );
+ $( html ).appendTo( "body" );
+ });
+ }
+ };
+ },
+
+ search: function( service, term ) {
+ var service = srchr.services[ service ];
+ $.getJSON( YQL.url, YQL.params( service, term ), service.handleResult );
+ }
+};
+
+srchr.addService( "flickr",
+ "SELECT * FROM flickr.photos.search WHERE text = '{term}'",
+ "query.results.photo",
+ "<img src='http://farm{farm}.static.flickr.com/{server}/{id}_{secret}_t.jpg'>"
+);
+
+})( jQuery );

0 comments on commit 2757ef3

Please sign in to comment.