Created
October 19, 2010 07:50
-
-
Save kgn/633799 to your computer and use it in GitHub Desktop.
This is the rss feed plugin developed for inscopeapps.com
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
| (function($){ | |
| $.fn.feed = function(options){ | |
| options = $.extend({ | |
| 'url': null, //required | |
| 'count': null, | |
| 'loadingImg': null | |
| }, options); | |
| var root = this; | |
| var loading = null; | |
| if(options.loadingImg){ | |
| loading = $('<img class="loading" src="'+options.loadingImg+'" />').appendTo(root); | |
| } | |
| $.ajax({ | |
| dataType: 'xml', | |
| url: options.url, | |
| success: function(data){ | |
| if(data){ | |
| root.each(function(){ | |
| $(root).fadeOut(function(){ | |
| $(loading).remove(); | |
| $(data).find('item').each(function(i){ | |
| if(i >= options.count){ | |
| return; | |
| } | |
| var title = $(this).children('title')[0]; | |
| var link = $(this).children('link')[0]; | |
| $(root).append('<li><a href="'+$(link).text()+'">'+$(title).text()+'</a></li>'); | |
| }); | |
| $(root).fadeIn(); | |
| }); | |
| }); | |
| } | |
| }, | |
| error: function(){ | |
| $(root).fadeOut(function(){ | |
| $(loading).remove(); | |
| $(root).append('<em class="error">Blog feed is currently unavailable.</em>'); | |
| $(root).fadeIn(); | |
| }); | |
| } | |
| }); | |
| return this; | |
| }; | |
| })(jQuery); | |
| /* | |
| If the rss feed comes from a different domain you will be blocked by the | |
| "same origin policy". If you want to use this plugin with rss feeds | |
| outside your domain you will need to pass them through a proxy script like this: | |
| <?php | |
| // PHP Proxy | |
| // Loads a XML from any location. Used with Flash/Flex apps to bypass security restrictions | |
| // Author: Paulo Fierro | |
| // January 29, 2006 | |
| // usage: proxy.php?url=http://mysite.com/myxml.xml | |
| $session = curl_init($_GET['url']); // Open the Curl session | |
| curl_setopt($session, CURLOPT_HEADER, false); // Don't return HTTP headers | |
| curl_setopt($session, CURLOPT_RETURNTRANSFER, true); // Do return the contents of the call | |
| $xml = curl_exec($session); // Make the call | |
| header("Content-Type: text/xml"); // Set the content type appropriately | |
| echo $xml; // Spit out the xml | |
| curl_close($session); // And close the session | |
| ?> | |
| */ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment