Skip to content

Instantly share code, notes, and snippets.

@rowanmanning
Created March 14, 2010 10:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rowanmanning/331901 to your computer and use it in GitHub Desktop.
Save rowanmanning/331901 to your computer and use it in GitHub Desktop.
A simple plugin which wraps the Google Ajax Feeds API (without having to load google ajaxlib)
/*
* jQuery getFeed Plugin 1.0
*
* Tested in jQuery 1.4.2
*
* Copyright 2010, Rowan Manning (http://www.rowanmanning.co.uk/)
* Dual licensed under the MIT or GPL Version 2 licenses
*/
(function($){
//============================================================
// jquery function
$.getFeed = function(feed, callback, options){
// default options
var options = $.extend({}, $.getFeed.defaults, options), data = {
q: feed,
num: options.count,
v: options.apiVersion
};
if (options.key){
data.key = options.apiKey;
}
if (options.language){
data.hl = options.language;
}
// get feed
$.ajax({
url: 'http://ajax.googleapis.com/ajax/services/feed/load',
dataType: 'jsonp',
data: data,
success: callback,
error: options.error
});
}
//============================================================
// public variables and functions
// jquery function option defaults
$.getFeed.defaults = {
count: 5,
apiKey: null,
apiVersion: '1.0'
};
//============================================================
})(jQuery);;
/*
* jQuery getFeed Plugin 1.0
*
* Tested in jQuery 1.4.2
*
* Copyright 2010, Rowan Manning (http://www.rowanmanning.co.uk/)
* Dual licensed under the MIT or GPL Version 2 licenses
*/
(function(b){b.getFeed=function(c,d,a){a=b.extend({},b.getFeed.defaults,a);c={q:c,num:a.count,v:a.apiVersion};if(a.key)c.key=a.apiKey;if(a.language)c.hl=a.language;b.ajax({url:"http://ajax.googleapis.com/ajax/services/feed/load",dataType:"jsonp",data:c,success:d,error:a.error})};b.getFeed.defaults={count:5,apiKey:null,apiVersion:"1.0"}})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment