Personal tools
You are here: Home About Committees Outreach gadget gadget.xml

gadget.xml

gadget.xml — Extensible Markup Language (XML), 14Kb

File contents

<?xml version="1.0" encoding="UTF-8"?>
<Module>
<ModulePrefs author_email="iowagic+feedback@gmail.com" author="Iowa Geographic Information Council" description="Information and news updates about and from the Iowa Geographic Information Council (IGIC)" title="IGIC" height="278" category="politics" category2="electiontool">
<Require feature="flash"/>
<Require feature="setprefs"/>
</ModulePrefs>
<UserPref name="lastTab" default_value="0" datatype="hidden"/>
<Content type="html">
<![CDATA[ 
<script type="text/javascript">

var gCampaignPrefs = {"headerImg": "http://www.iowagic.org/about/committee/outreach/logo.png", "campaignName": "The mission of the Iowa Geographic Information Council (IGIC) is to foster an efficient GIS environment through cooperation and coordination with public and private entities that access, collect, provide, and share data, metadata, applications and educational opportunities.", "defaultTab": "GNews", "includeYTPlaylist": false, "YTPlaylist": "http://", "includeRSSFeed": false, "RSSFeed": "http://www.iowagic.net/atom.xml", "includeGNewsFeed": true, "GNewsFeed": "http://pipes.yahoo.com/pipes/pipe.run?_id=vox3rDrm3BGbC24tnkartA&_render=rss", "includeGetInvolvedTab": true, "ctaMailingList": "http://www.iowagic.org/about/committee/membership_nominations/igic-membership", "ctaDonation": "http://", "gadgetBaseUrl": "http://www.iowagic.org/about/committee/outreach/"} 

var kUserPrefs = false;

var kTabs = {'RSS':0, 'YT':1, 'GNews':2, 'CallAction':3};
var gadgetTabs = [];
var kCurrTab = -1;

var kRssNmbItems = 10;
var rssOutCache = "";
var gnewsOutCache = "";

var ytAllVideos = [];
var ytCurrVideo = -1;

var kImg = {ArrowLeft:"/gadget-img/left-arrow.png", ArrowRight:"/gadget-img/right-arrow.png", TabReadBlog:"/gadget-img/tab-read-blog.jpg", TabWatch:"/gadget-img/tab-watch.jpg", TabNews:"/gadget-img/tab-news.jpg", TabGetInvolved:"/gadget-img/tab-get-involved.jpg"};

var kDefaultBaseUrl = "http://www.google.com/webmasters/gadgets/promo";

function gadgetInit()
{
	var url = getCampaignPref('gadgetBaseUrl').replace(/\/$/, '');
	if(!getCampaignPref('gadgetBaseUrl') || getCampaignPref('gadgetBaseUrl') == "")
		url = kDefaultBaseUrl;

	for(var i in kImg)
		kImg[i] = _IG_GetImageUrl(url + kImg[i]);

	placeHeaderFooter();
	buildTabTable();


	var prefs = new _IG_Prefs();
	var lastTab = parseInt(prefs.getString("lastTab"));
	if(lastTab < 0 || lastTab >= gadgetTabs.length)
		lastTab = 0;

	setTimeout("activateTab("+ lastTab +")", 100);
}

function showGNewsTab()
{
	if(!getCampaignPref('includeGNewsFeed') || !getCampaignPref('GNewsFeed'))
		return;

	showLoadingIndicator();

	if(typeof gnewsOutCache != "undefined" && gnewsOutCache != "")
	{
		_gel('contentDiv').innerHTML = gnewsOutCache;
	}
	else
	{
		var url = '';

		if(getCampaignPref('GNewsFeed').match(/^https?:\/\//))
			url = getCampaignPref('GNewsFeed');
		else
			url = "http://news.google.com/news?hl=en&ned=us&ie=UTF-8&scoring=n&output=atom&q="+ encodeURIComponent(getCampaignPref('GNewsFeed'));

		_IG_FetchFeedAsJSON(url, function(response)
		{
			var out = "";

			if((out = rssContentHandler(response)) === false)
				return;

			gnewsOutCache = out;
			_gel('contentDiv').innerHTML = out;				
		}, kRssNmbItems, true);
	}
}


function showRSSTab()
{
	if(!getCampaignPref('includeRSSFeed') || !getCampaignPref('RSSFeed'))
		return;

	showLoadingIndicator();

	if(typeof rssOutCache != "undefined" && rssOutCache != "")
        {
                _gel('contentDiv').innerHTML = rssOutCache;
        }
        else
        {
		_IG_FetchFeedAsJSON(getCampaignPref('RSSFeed'), function (response)
		{
			var out = "";
			if((out = rssContentHandler(response)) === false)
				return;

			rssOutCache = out;
			_gel('contentDiv').innerHTML = out;
		}, kRssNmbItems, true);
	}
}

function rssContentHandler(response)
{
	var out = "";

	try
	{
		if(response == null || typeof response != "object" || typeof response.Entry == "undefined" || response.Entry.length == "undefined" || response.Entry.length == 0)
			return false;

		var newsItems = response.Entry;

		var out = "";

		for(var i = 0; i < newsItems.length; i++)
		{
			var link = newsItems[i].Link;
			var title = newsItems[i].Title;

			var description = newsItems[i].Summary.replace(/<[^>]+>/g, ' ').replace(/[ ]+/g, ' ');
			if(description.length > 200)
                                description = description.split(' ').slice(0,32).join(' ') + '...';

			out += "<div style='margin-top:5px; margin-bottom:5px;margin-left:2px;margin-right:2px;'>";
			out += "<a target=_blank class=rssLink href='"+ link  +"'>"+ title +"</a>";
			out += "<div class=rssDescription>" + description + "</div></div>";			
		}
	}
	catch(E) { }

	return out;
}

function prevVideo() { loadVideo((ytCurrVideo - 1 < 0)? ytAllVideos.length - 1 : ytCurrVideo - 1);  }
function nextVideo() { loadVideo((ytCurrVideo + 1 == ytAllVideos.length)? 0 : ytCurrVideo + 1) }

function loadVideo(videoIdx)
{
	if(typeof ytAllVideos == "undefined" || typeof ytAllVideos.length == "undefined" || ytAllVideos.length == 0)
		return;

	if(typeof videoIdx == "undefined" || videoIdx < 0 || videoIdx >= ytAllVideos.length)
        	videoIdx = 0;

	if(!_gel('watchDiv'))
		return;

	ytCurrVideo = videoIdx;

	var vWidth = 260;
	var vHeight = 150;

	_IG_EmbedFlash('http://www.youtube.com/v/' + ytAllVideos[videoIdx], 'watchDiv',
      	{
      	        swf_version: 6,
     	        id: "flashmovie",
       	        width: vWidth,
                height: vHeight,
                flashvars: 'autoplay=true'
        });

	var out = "<center><table border=0 cellspacing=0 cellpadding=0 width=90><tr>";
	out += "<td valign=middle width=16>";
	out += "<a href='javascript:void(0)' onclick='prevVideo()'><img border=0 id='arrowLeftImg' src='" + kImg.ArrowLeft + "'></a>";
	out += "</td><td valign=middle width=55 align=center><span style='font-size:10px;'>";
	out += (1 + videoIdx) + " OF " + ytAllVideos.length;
	out += "</td><td valign=middle width=16>";
	out += "<a href='javascript:void(0)' onclick='nextVideo()'><img border=0 id='arrowRightImg' src='" + kImg.ArrowRight + "'></a>";
	out += "</td></tr></table></center>";

	_gel('videoArrowsDiv').innerHTML = out;

	fixPNG(_gel('arrowLeftImg'));
	fixPNG(_gel('arrowRightImg'));
}

function showYTTab()
{
        if(!getCampaignPref('includeYTPlaylist') || !getCampaignPref('YTPlaylist'))
                return;

	showLoadingIndicator();

	if(typeof ytAllVideos == "undefined" || typeof ytAllVideos.length == "undefined" || ytAllVideos.length == 0)
	{
		loadYTPlaylist();
	}
	else
	{
		if(typeof ytCurrVideo == "undefined" || ytCurrVideo < 0 || ytCurrVideo >= ytAllVideos.length)
			ytCurrVideo = 0;

		var out = '<div id="watchDiv"></div><div id="videoArrowsDiv"></div>';

		_gel('contentDiv').innerHTML = out;

		setTimeout(function(){ loadVideo(ytCurrVideo); }, 100);
	}
}

function loadYTPlaylist()
{
	var playlistIdMatchRe = /p=([^\&]+)/
	var playlistIdMatch = playlistIdMatchRe.exec(getCampaignPref('YTPlaylist'));

	if(typeof playlistIdMatch == "undefined" || !playlistIdMatch || playlistIdMatch.length <= 1)
		return;
	var playlistId = playlistIdMatch[1];

	_IG_FetchXmlContent("http://www.youtube.com/api2_rest?method=youtube%2Evideos%2Elist%5Fby%5Fplaylist&id=" + playlistId, function (response)
	{
		try {

		if(response == null || typeof response != "object" || response.firstChild == null)
			return;
	
		var videoIds = response.getElementsByTagName("id");

		for(var i = 0; i < videoIds.length; i++)
			ytAllVideos.push(videoIds[i].firstChild.nodeValue);

		showYTTab();

		} catch(E) { }
	});
}

function showCallActionTab()
{
	var out = "<div style='margin-top:20px'>";

	if(getCampaignPref('ctaMailingList'))
		out += "<div style='margin-top:40px;width:100%;'><center><a class=mailingListLink target=_blank href='"+ getCampaignPref('ctaMailingList')  +"'>Join our mailing list</a></center></div>";

	if(getCampaignPref('ctaDonation'))
	{
		out += "<div style='margin-top:40px;width:100%;'><center><span class=donationLink>Make a donation</a></center>";
		out += "<center><div class=donationCopy style='width:90%;margin-top:10px;'>Click <a target=_blank href='"+ getCampaignPref('ctaDonation') +"'>here</a> to make a donation in support of ";
		
		if(getCampaignPref('campaignName'))
			out += "the <b>"+ getCampaignPref('campaignName') +"</b>";
		else
			out += "this";

		out += " campaign</div></center>";
		out += "</div>";
	}
	
	out += "</div>";

	_gel('contentDiv').innerHTML = out;
}

function activateTab(tabIdx)
{
	if(typeof gadgetTabs == "undefined" || typeof gadgetTabs.length == "undefined" || gadgetTabs.length < tabIdx)
		return;

	if(kCurrTab == tabIdx)
		return;
	kCurrTab = tabIdx;

	var prefs = new _IG_Prefs();
	prefs.set("lastTab", String(tabIdx));

	for(var i = 0; i < gadgetTabs.length; i++)
	{
		if(i == tabIdx)
			_gel('tab'+ i +'Cell').style.borderBottom = '0px';
		else
			_gel('tab'+ i +'Cell').style.borderBottom = '1px solid #ccc';			
	}

	switch(gadgetTabs[tabIdx])
	{
		case kTabs.RSS:
			showRSSTab();
		break;

		case kTabs.YT:
			showYTTab();
		break;

		case kTabs.GNews:
			showGNewsTab();
		break;

		case kTabs.CallAction:
			showCallActionTab();
		break;
	}
}

function showLoadingIndicator()
{
	_gel('contentDiv').innerHTML = "<div style='margin:0px;padding:0px;margin-top:80px;width:100%;font-size:16px;font-family:verdana;color:#777'><center>Loading...</center></div>";
}

function makeTableCell(img, width, idx)
{
	var out = "";

	out += "<td width="+width+" id='tab"+ idx +"Cell'>";
	out += "<a href='javascript:void(0)' onclick='activateTab("+ idx +")'>";
	out += "<img border=0 src='"+ img +"'>";
	out += "</a></td>";

	return out;
}

function buildTabTable()
{
	var currCellCount = 0;

	var out = "<table border=0 width='100%' cellspacing=0 cellpadding=0>";
	out += "<tr><td style='border-bottom:1px solid #ccc' width='20'>&nbsp;</td>";

	var tabDefs = [{
		campaignPref:'includeYTPlaylist',
		tabImg:kImg.TabWatch,
		tabImgWidth:65,
		tabType:kTabs.YT
	},{
		campaignPref:'includeRSSFeed',
		tabImg:kImg.TabReadBlog,
		tabImgWidth:66,
		tabType:kTabs.RSS
	},{
		campaignPref:'includeGNewsFeed',
		tabImg:kImg.TabNews,
		tabImgWidth:68,
		tabType:kTabs.GNews
	},{
		campaignPref:'includeGetInvolvedTab',
		tabImg:kImg.TabGetInvolved,
		tabImgWidth:76,
		tabType:kTabs.CallAction
	}];

	if(getCampaignPref('defaultTab') != '')
	{
		for(var i = 0; i < tabDefs.length; i++)
		{
			if(tabDefs[i].tabType == kTabs[getCampaignPref('defaultTab')])
			{
				var el = tabDefs.splice(i, 1);
				if(typeof el.length != "undefined")
					el = el[0];

				tabDefs.unshift(el);
				break;
			}
		}
	}

	for(var i = 0; i < tabDefs.length; i++)
	{
		var currTab = tabDefs[i];

		if(getCampaignPref(currTab.campaignPref) == true)
		{
			out += makeTableCell(currTab.tabImg, currTab.tabImgWidth, currCellCount++);

			gadgetTabs.push(currTab.tabType);
		}
	}


	if(gadgetTabs.length == 0)
		out += "<td width=100><div style='width:100px;border:1px solid #ccc;border-bottom:none;padding:3px;font-size:13px'>Tabs</div></td>";

	out += "<td style='border-bottom:1px solid #ccc'>&nbsp;</td>";
	out += "</tr></table>";

	_gel('tabsTableDiv').innerHTML = out;
}

function placeHeaderFooter()
{
	if(getCampaignPref('headerImg') && getCampaignPref('headerImg') != "http://")
	{
		_gel('headerImgDiv').innerHTML = "<img id='headerImg' src='"+ _IG_GetImageUrl(getCampaignPref('headerImg')) +"'>";
		fixPNG(_gel('headerImg'));
	}
	else
		_gel('headerImgDiv').innerHTML = "<div style='background:#e8e8e8;padding:10px;font-size:13px;width:300px;'>Header image</div>";

	_gel('tabsTableDiv').style.top = "63px";
	_gel('contentDiv').style.top = "83px";
	_gel('contentDiv').style.height = "192px";


	if(getCampaignPref('campaignName'))
		_gel('campaignNameDiv').innerHTML = "<center>"+ getCampaignPref('campaignName') +"</center>";
	else
		_gel('campaignNameDiv').innerHTML = "<div style='font-weight:normal;text-align:center;font-size:11px;color:black;width:300px; padding:10px;background:#e8e8e8;'>Footer Text</div>";

	_gel('contentDiv').style.height = parseInt(_gel('contentDiv').style.height) - 13 + "px";
}

function getCampaignPref(key)
{
	if(kUserPrefs)
	{
		var prefs = new _IG_Prefs();

		return prefs.getString(key);
	}
	else
	{
		if(typeof gCampaignPrefs != "undefined" && typeof gCampaignPrefs[key] != "undefined" && gCampaignPrefs[key] != "")
			return gCampaignPrefs[key];

		return false;
	}
}

function fixPNG(img)
{
if (!(/MSIE (5\.5|6).+Win/.test(navigator.userAgent)))
        return;

var arVersion = navigator.appVersion.split("MSIE")
var version = parseFloat(arVersion[1])

if ((version >= 5.5) && (document.body.filters))
{
      var imgName = img.src.toUpperCase()
      if (imgName.substring(imgName.length-3, imgName.length) == "PNG")
      {
         var imgID = (img.id) ? "id='" + img.id + "' " : ""
         var imgClass = (img.className) ? "class='" + img.className + "' " : ""
         var imgTitle = (img.title) ? "title='" + img.title + "' " : "title='" + img.alt + "' "
         var imgStyle = "display:inline-block;" + img.style.cssText
         if (img.align == "left") imgStyle = "float:left;" + imgStyle
         if (img.align == "right") imgStyle = "float:right;" + imgStyle
         if (img.parentElement.href) imgStyle = "cursor:hand;" + imgStyle
         var strNewHTML = "<span " + imgID + imgClass + imgTitle
         + " style=\"" + "width:" + img.width + "px; height:" + img.height + "px;" + imgStyle + ";"
         + "filter:progid:DXImageTransform.Microsoft.AlphaImageLoader"
         + "(src=\'" + img.src + "\');\"></span>"
         img.outerHTML = strNewHTML
      }
}
}

_IG_RegisterOnloadHandler(gadgetInit);

</script>
<style type="text/css">
* { font-family: times }

.rssLink { font-size: 12px; font-weight:bold; color: blue; text-decoration: underline; }
.rssDescription { font-size:11px; color:black; margin-top:2px; }

#campaignNameDiv { font-size: 10px; color: #888; font-weight:bold; }

#watchDiv {
	margin-top: 3px;
	text-align: center;
}

#videoArrowsDiv {
	margin-top: 2px;
	background: #d9d9d9;
	height: 16px;
}

.mailingListLink { font-family:times; font-size:18px; color: blue }
.donationLink { font-family:times; font-size:18px; color: red }

.donationCopy { font-size:13px; color:#777 }

</style>

<div style='height:278px;'>

<div style='position:absolute;height:100px' id='headerImgDiv'></div>
<div style='position:absolute;height:100px' id='tabsTableDiv'></div>
<div style='position:absolute;width:100%;overflow:hidden;overflow-y:auto;' id='contentDiv'></div>
<div style='position:absolute;bottom:1px;width:100%;' id='campaignNameDiv'></div>

</div>

     ]]>
  </Content> 
</Module>
Document Actions