5,695,118 members and growing! (14,173 online)
Email Password   helpLost your password?
Web Development » Ajax and Atlas » Samples     Intermediate License: The Code Project Open License (CPOL)

Simple IGoogle Gadget

By Maxim Kazitov

Simple IGoogle Gadget to display Expedia RSS
Javascript, XML, CSS, HTMLGoogle, Dev, Design

Posted: 1 Jul 2008
Updated: 1 Jul 2008
Views: 6,173
Bookmarked: 7 times
Announcements
Loading...



Search    
Advanced Search
Sitemap
3 votes for this Article.
Popularity: 1.67 Rating: 3.50 out of 5
1 vote, 33.3%
1
0 votes, 0.0%
2
0 votes, 0.0%
3
1 vote, 33.3%
4
1 vote, 33.3%
5
Note: This is an unedited contribution. If this article is inappropriate, needs attention or copies someone else's work without reference then please Report This Article

Introduction

It's a short article about iGoogle gadgets. Gadgets API is easy but documentation is really fuzzy.

Background

Gadgets are mini applications that use the IGoogle framework and can live inside other site. In short it's a your page inside iFrame.

There are several steps to create your first gadget:

1. Sign up for the Sandbox. Note: behavior of application in Sandbox is different from the one on IGoogle home page (looks like they use different JS libraries).

2. Add developer tools. These tools will protect your gadget from caching.

3. Use Online editor or any other editor to create your gadget.

4. Publish your gadget.

Using the code

The full gadget code is available here.

I decided to create a gadget which display the Hot deals from Expedia.com. After a few minutes in Google, I found the DataSource for my gadget - Expedia RSS Feed.

IGoogle Gadget for Expedia Deals

Gadget has 2 presentation parts:

- form to configure gadget;

- list of entries from the feed;

<ModulePrefs 
   title="Travel Deals on Expedia" 
   description="Hot Travel Deals from Expedia.com. Cheap flights and hotels, cruises and top deals." 
   title_url="http://www.expedia.com/daily/outposts/rss/expedia_rss.asp"
   author="Maxim Kazitov"
   author_email= href="mailto:mvkazit@tut.by">mvkazit@tut.by
   screenshot="http://www.yogageneration.com/~mvkazit/expedia/iexpedia/screen.jpg" 
   thumbnail="http://www.yogageneration.com/~mvkazit/expedia/iexpedia/thumbnail.gif"
   directory_title="IG Expedia Hot Deals" 
   height="250"
   width="250">

   <icon>http://www.yogageneration.com/~mvkazit/expedia/iexpedia/icon.gif</icon>
   <Require feature="setprefs"/>
   <Require feature="dynamic-height"/>
</ModulePrefs>

In code above we are setting up all required settings for a future gadget and including 2 modules at the end : "setprefs" and "dynamic-height". First module allows us to programatically save the user settings, the second one allows to adjust the height of IFrame (if content height was changed).

_IG_RegisterOnloadHandler(pgLoad);
function pgLoad()
{
//...................
}

pgLoad function will be called and a page will finish the loading process. Actually IG framework will add following line at the end of the body.

_IG_TriggerEvent("domload");

Note: looks like "registerOnLoadHandler()" is working only inside the Sandbox.

"hidden" default_value="false" name="hasCfg" /> 
.................
var m_UsrPref   = new _IG_Prefs(__MODULE_ID__);
m_UsrPref.getBool("hasCfg"))
m_UsrPref.set("hasCfg", true); 

It's easy to read/write settings, but you MUST declare these settings first.

Now we want to read RSS feed

_IG_FetchFeedAsJSON(buildURL(), parseResponse);

function parseResponse(obj) 
{  
  if(obj && obj.Entry)
  {

     for(var i=0; i

Framework will automatically refresh feed every 60 min or so.

Note: looks like "gadgets.io.makeRequest()" are working only inside the Sandbox. In general gadgets.io* functions are working only in dev environment and only _IG_* is really working.

_IG_AdjustIFrameHeight();

This call will adjust the size of IFrame to fit the content height (again don't try to use adjustHeight). Now we can publish our gadget and share it with friends.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Maxim Kazitov



Location: United States United States

Other popular Ajax and Atlas articles:

Article Top
Sign Up to vote for this article
You must Sign In to use this message board.
FAQ FAQ Noise ToleranceSearch Search Messages 
 Layout  Per page   
 Msgs 1 to 1 of 1 (Total in Forum: 1) (Refresh)FirstPrevNext
GeneralNice.memberRajib Ahmed19:51 1 Jul '08  

General General    News News    Question Question    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

PermaLink | Privacy | Terms of Use
Last Updated: 1 Jul 2008
Editor:
Copyright 2008 by Maxim Kazitov
Everything else Copyright © CodeProject, 1999-2008
Web10 | Advertise on the Code Project