Click here to Skip to main content
6,822,123 members and growing! (19,354 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, HTML, Dev, Design
Revision:3 (See All)
Posted:1 Jul 2008
Views:15,033
Bookmarked:14 times
printPrint   add Share
      Discuss Discuss   Broken Article?Report  
4 votes for this article.
Popularity: 2.14 Rating: 3.56 out of 5
1 vote, 25.0%
1

2

3
2 votes, 50.0%
4
1 vote, 25.0%
5

Introduction

This is a short article about iGoogle gadgets. The Gadgets API is easy to use, but documentation is really fuzzy.

Background

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

There are several steps to creating your first gadget:

  1. Sign up for the Sandbox. Note: the behavior of the application in Sandbox is different from that in the IGoogle home page (looks like they use different JS libraries).
  2. Add developer tools. These tools will protect your gadget from caching.
  3. Use the 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 displays 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

The gadget has two presentation parts:

  • a form to configure the gadget;
  • a 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=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 the code above, we are setting up all the required settings for a future gadget and including two modules at the end: "setprefs" and "dynamic-height". The first module allows us to programmatically save the user settings, the second one allows to adjust the height of the IFrame (if content height was changed).

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

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

_IG_TriggerEvent("domload");

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

.................
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 the RSS feed:

_IG_FetchFeedAsJSON(buildURL(), parseResponse);

function parseResponse(obj) 
{  
    var html = ""; 
      if(obj && obj.Entry)
    {
        var n = obj.Entry.length;
        for(var i=0; i<n; i++)
        {
            html+= buildEntryHTML(obj.Entry[i]);
        }
    }
    rssRender(html); 
}

The framework will automatically refresh feed every 60 minutes or so.

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

_IG_AdjustIFrameHeight();

This call will adjust the size of the 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


Member

Location: United States United States

Other popular Ajax and Atlas articles:

Article Top
You must Sign In to use this message board.
FAQ FAQ 
 
Noise Tolerance  Layout  Per page   
 Msgs 1 to 3 of 3 (Total in Forum: 3) (Refresh)FirstPrevNext
GeneraliGoogle gadgets on Microsoft 2003 SharePoint server. PinmemberhappyUser8:22 16 Jan '09  
GeneralRe: iGoogle gadgets on Microsoft 2003 SharePoint server. PinmemberMaxim Kazitov11:49 19 Jan '09  
GeneralNice. PinmemberRajib Ahmed19:51 1 Jul '08  

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads.

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