Created
March 14, 2010 10:09
-
-
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)
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
/* | |
* 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);; |
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
/* | |
* 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