Skip to content

Instantly share code, notes, and snippets.

@boof
Created March 2, 2012 12:23
Show Gist options
  • Save boof/1958095 to your computer and use it in GitHub Desktop.
Save boof/1958095 to your computer and use it in GitHub Desktop.
Loads rss feeds.
(function(a,b){function e(b){var e=[],f;return b=a.extend({},d,b),a.each(b,function(a,b){if(b===!1)return;f=encodeURIComponent(a)+"="+encodeURIComponent(b),e.push(f)}),c.search=e.join("&"),c.href}function f(a){return'<script charset="'+document.charset+'"'+' language="JavaScript"'+' src="'+e(a)+'"'+' type="text/javascript"></script>'}var c=document.createElement("a");c.href="http://feed2js.org/feed2js.php";var d={num:3,au:"y",date:"y",targ:0,html:"a",utf:document.charset=="UTF-8"?"y":"n"};a.fn.feed2js=function(c,d,e){var g,h,i,j=this;return typeof d=="function"&&(e=d,d=undefined),e===b?j:(d=d||{},d.src=c,g=a("<IFRAME>").hide().appendTo("body").one("load",function(){e.call(j,h.body.innerHTML),g.detach()}),i=f(d),h=g.contents().get(0),h.open(),h.write(i),h.close(),this)}})(jQuery)
(function($, undef) {
var anchor = document.createElement('a');
anchor.href = 'http://feed2js.org/feed2js.php';
var defaultParameters = {
num: 3, // # of items
au: 'y', // author: y, false
date: 'y', // date: y, false
targ: 0, // target: 0, 1, String
html: 'a',
utf: document.charset == 'UTF-8' ? 'y' : 'n'
};
function compileParameters(parameters) {
var search = [], param;
parameters = $.extend({}, defaultParameters, parameters);
$.each(parameters, function(key, value) {
if (value === false) return;
param = encodeURIComponent(key) + '=' + encodeURIComponent(value);
search.push(param);
});
anchor.search = search.join('&');
return anchor.href;
}
function buildScript(parameters) {
return '<script charset="' + document.charset + '"' +
' language="JavaScript"' +
' src="' + compileParameters(parameters) + '"' +
' type="text/javascript"></script>';
}
$.fn.feed2js = function(src, parameters, callback) {
var iframe, feed, script;
var self = this;
if (typeof(parameters) == 'function') {
callback = parameters;
parameters = undefined;
}
if (callback === undef) return self;
parameters = parameters || {};
parameters.src = src;
iframe = $('<IFRAME>').hide().appendTo('body').
one('load', function() {
callback.call(self, feed.body.innerHTML);
iframe.detach();
});
script = buildScript(parameters);
feed = iframe.contents().get(0);
feed.open();
feed.write(script);
feed.close();
return this;
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment