<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs title="Twitter Feed Gadget" height="280" scrolling="true" />
<UserPref name="num_entries" display_name="Number of Entries:" default_value="10" />
<UserPref name="get_summaries" display_name="Show Summaries?" datatype="bool" default_value="true" />
<Content type="html"><![CDATA[

<style>
#content_div { font-size: 80%; margin: 5px; padding: 5px; background-color: #FFFFBF; }
#content_div a, #content_div a:visited { color: #0000FF; }
#content_div a:hover { color: #FF0000; }
#content_div ul.feed { list-style-type: none; margin: 0 5px; padding-left: 0px; }
#content_div ul.feed > li { margin: 5px auto; }
</style>

<div id="content_div"></div>

<script type="text/javascript">
// Register a handler function to be executed when this gadget has loaded
_IG_RegisterOnloadHandler(init);

function init() {
// Get user preferences
var prefs = new _IG_Prefs();
var options = {
"num_entries": prefs.getInt("num_entries"),
"get_summaries": prefs.getBool("get_summaries")
};

// Download the RSS/Atom feed and pass the response to the handler function
getFeed("http://search.twitter.com/search.atom?q=research3", handleTwitterFeed, options);
}

function getFeed(url, handler, options) {
// Use the _IG_FetchFeedAsJSON function to download the RSS/Atom feed specified by 'url'
// Pass the associative array of 'options' to the 'handler' using an anonymous function
_IG_FetchFeedAsJSON(url, function(feed) {
handler(feed, options);
// The last two parameters of the _IG_FetchFeedAsJSON function are optional:
// num_entries - number of entries to download
// get_summaries - whether or not to return summaries (which includes feed description)
}, options["num_entries"], options["get_summaries"]);
}

function handleTwitterFeed(feed, options) {
// If 'feed' is undefined, display an error message
if (feed == null) {
_gel("content_div").innerHTML = "<i>Feed contains no data</i>";
return;
}

// Create a string to hold HTML content
var html = "";

// Render feed metadata
html += "<div><b><a target='_blank' href='" + feed.Link + "'>" + feed.Title + "</a></b></div>";

// If the 'get_summaries' flag is set to true, render the feed description
if (options["get_summaries"]) {
html += "<div>" + feed.Description + "</div>";
}

// Test if the feed has at least one entry
if (feed.Entry) {
html += "<ul class='feed'>";

// Iterate over each feed entry
for (var i = 0; i < feed.Entry.length; i++) {
html += "<li>";

// Render entry metadata
html += "<a target='_blank' href='" + feed.Entry[i].Link + "'>" + feed.Entry[i].Title + "</a>";
html += "<br/>" + new Date(feed.Entry[i].Date * 1000).toUTCString();

// If the 'get_summaries' flag is set to true, render the entry summary
if (options["get_summaries"]) {
html += "<br/><i>" + feed.Entry[i].Summary + "</i>";
}

html += "</li>";
}

html += "</ul>";
}

// Update the HTML content of the 'content_div' element
_gel("content_div").innerHTML = html;
}

</script>

]]></Content>
</Module>

