/** * The GoogleFeeds JavaScript library is used for processing and displaying * multiple RSS feeds using the Google AJAX Feed API. * Copyright (C) 2008 Ramiro Gómez * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * * @author Ramiro Gómez www.ramiro.org * @see www.la-liga.eu for a usage example * */ // load Google AJAX Feed API google.load("feeds", "1"); // create an empty GoogleFeeds object var GoogleFeeds = {}; /** * Set the element id of the feed container * * @param {String} id Container element id */ GoogleFeeds.setContainerId = function(id) { GoogleFeeds.container_id = id; } /** * Set the feed URLs * * @param {Array} feeds An array of feed URLs */ GoogleFeeds.setFeeds = function(feeds) { GoogleFeeds.feeds = feeds; } /** * Set the target container and process feeds */ GoogleFeeds.processFeeds = function() { GoogleFeeds.container = document.getElementById(GoogleFeeds.container_id); for (url in GoogleFeeds.feeds) { GoogleFeeds.displayFeed(GoogleFeeds.feeds[url]); } } /** * Display feed in the container element * * @param {String} url a feed URL */ GoogleFeeds.displayFeed = function(url) { var feed = new google.feeds.Feed(url); feed.setNumEntries(10); feed.load(function(result) { if (!result.error) { var div = document.createElement("div"); div.className = 'block-feed'; var heading = document.createElement("h2"); var feed_title = result.feed.title; heading.appendChild(document.createTextNode(feed_title)); div.appendChild(heading); var ul = document.createElement("ul"); for (var i = 0; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; var link = '' + entry.title + ''; var li = document.createElement("li"); li.innerHTML = link; ul.appendChild(li); } div.appendChild(ul); var div_info = document.createElement("div"); div_info.className = 'block-feed-info'; var div_info_link = '' + 'RSS'; div_info.innerHTML = div_info_link; div.appendChild(div_info); GoogleFeeds.container.appendChild(div); } }); } /** * escape HTML */ String.prototype.escapeHTML = function () { return ( this.replace(/&/g,'&').replace(/>/g,'>'). replace(/