// // rotch_blog_roll.js contains the functions to pull and display rss feeds. Requires pages to link to http://www.google.com/jsapi. // google.load("feeds", "1"); function stringFilter (input) { // This is the filtering function to remove invalid characters var returnString = input; var i = 0; var characterArray = [ "�", "", "ç", "\u00E7", "’", "\u0027", "‘", "\u0027", "”", "\u201D", "“", "\u201C", "&", "\u0026", "—", "\u2014", " ", " ", "ø", "\u00F8", """, "\u0022"]; //these are the strings to swap for (i; i < characterArray.length; i = i+2){ var regexToFind = new RegExp(characterArray[i], "gi");// regex constructor to find strings in feed text returnString = returnString.replace(regexToFind, characterArray[i+1]); }; return returnString; } function initialize() { // This loads the rss feed. URL is hardwired in this function var bsa_custom_feed = new google.feeds.Feed("http://urbanwaterfront.blogspot.com/feeds/posts/default?alt=rss"); // this is the feed to fetch bsa_custom_feed.setNumEntries(1); //sets the number of entries for this feed bsa_custom_feed.load(function(result) { var filteredTitle = ""; if (!result.error) { var container = document.getElementById("rotch_news_feed_hook"); // this is the hardwired div id hook to the html page for (var i = 0; i < result.feed.entries.length; i++) { var entry = result.feed.entries[i]; var attributes = ["title", "link", "contentSnippet"]; //these are the data pairs to fetch var div = document.createElement("div"); for (var j = 0; j < attributes.length; j++) { var div = document.createElement("div"); // creates new feed entry var attribute_class = document.createAttribute("class"); //creates class name for feed entry switch(j) // this decides what to do when we receive a piece a data { case 0: // feed entry title filteredTitle = stringFilter(entry.title); // call function to filter odd characters attribute_class.nodeValue = "rotch_custom_feed_title"; var div_link = document.createElement("a"); var attribute_div_link = document.createAttribute("href"); //creates href value for title attribute_div_link.nodeValue = entry[attributes[j+1]]; // sets href to the feed link div_link.setAttributeNode(attribute_div_link); // adds the new href to the tag div_link.appendChild(document.createTextNode(filteredTitle)); //add feed entry title text to the div div.appendChild(div_link); // add the constructed tag to the entry div container.appendChild(div); // add the constructed div tag to the container div div.setAttributeNode(attribute_class); // adds class name attribute to entry div break; case 1: // do nothing since we've reached the link data and we don't need to display that break; case 2: // feed entry snippet break; //since we only want the headline for now, I've commented out the remaining code //filteredSnippet = stringFilter(entry.contentSnippet); // call function to filter odd characters //attribute_class.nodeValue = "rotch_custom_feed_snippet"; //container.appendChild(div); //div.setAttributeNode(attribute_class); // adds class name attribute to entry div //if (filteredSnippet==="") { // this if statement will add some text if the description is empty... can remove after Rotch blog entry is taken away // filteredSnippet="View images from the 2009 Rotch Scholarship winner, Brandon Shigeta."; //} //div.appendChild(document.createTextNode(filteredSnippet)); //break; } } } } }); // end initialize function } google.setOnLoadCallback(initialize); // Init function to call rss feed functions