This is the reference for the "legacy" gadgets API, based on the _IG_... namespace. It includes reference
information for the gadget spec XML, and for the JavaScript core
and feature-specific libraries.
Going forward, the gadgets API is being "renamespaced" into the gadgets.* JavaScript namespace, to provide a cleaner API to program
against and support. Currently the new namespace is only supported in containers that also support the OpenSocial API. If you are developing gadgets for an OpenSocial container, see the gadgets.* Developers Guide. You can see the gadgets.* reference here. If you are interested in gaining a deeper understanding, you are also welcome to read the gadgets specification. Keep in mind that the new gadgets.* API is NOT yet supported everywhere. Go here for a list of containers that support the gadgets.* API.
The following sections describe the structure and contents of the XML file used to specify a gadget.
The <ModulePrefs> section
in the XML file specifies characteristics of the gadget,
such as title, author, preferred sizing, and so on. For
example:
<Module>
<ModulePrefs title="Developer Forum" title_url="http://groups.google.com/group/Google-Gadgets-API"
height="200" author="Jane Smith" author_email="xxx@google.com"/>
<Content ...>
... content ...
</Content>
</Module>
The users of your gadget cannot change these attributes.
The following table lists the <ModulePrefs> attributes:
| Attribute | Description |
|---|---|
title |
Optional string that provides the title of the
gadget. This title is displayed in the gadget
title bar on iGoogle.
If this string contains user
preference substitution variables and you
are planning to submit your gadget to the
content directory, you should also provide
a directory_title for
directory display. |
directory_title |
Optional string that provides the title that
should be displayed for your gadget in the
content directory. Should contain only
the literal text to be displayed, not user
preference substitution variables. This is
because the content directory displays a static
view of your gadget, and therefore can't perform
the necessary substitution to produce a reasonable
title. For example, if your gadget's title is "Friends for
__UP_name__", the directory
is not able to perform the substitution to provide
a reasonable value for " __UP_name__".
So you might set your directory_title to
be simply "Friends". |
title_url |
Optional string that provides a URL that the gadget title links to. For example, you could link the title to a webpage related to the gadget. |
description |
Optional string that describes the gadget. |
author |
Optional string that lists the author of the gadget. |
author_email |
Optional string that provides the gadget author's
email address. You can use any email system,
but you should not use a personal email address
because of spam. One approach is to use an email
address of the form helensmith.feedback+coolgadget@gmail.com in your gadget spec.
Gmail drops everything after the plus sign (+), so this email address is interpreted as helensmith.feedback@gmail.com. You can create a Gmail account here. |
author_affiliation |
Optional string such as "Google" that indicates the author's affiliation. This attribute is required for gadgets that are included in the content directory. |
author_location |
The author's geographical location, such as "Mountain View , CA, USA ". |
screenshot |
Optional string that gives the URL of a gadget screenshot. This must be an image on a public web site that is not blocked by robots.txt. PNG is the preferred format, though GIF and JPG are also acceptable. Gadget screenshots should be 280 pixels wide. The height of the screenshot should be the "natural" height of the gadget when it's in use. For more discussion of screenshot guidelines, see Publishing to the Content Directory. |
thumbnail |
Optional string that gives the URL of a gadget thumbnail. This must be an image on a public web site that is not blocked by robots.txt. PNG is the preferred format, though GIF and JPG are also acceptable. Gadget thumbnails should be 120x60 pixels. For more discussion of thumbnail guidelines, see Publishing to the Content Directory. |
height |
Optional positive integer that specifies the height of the area in which the gadget runs. The default height is 200. |
width |
Optional positive integer that specifies the width of the area in which the gadget runs. This setting only applies to syndicated gadgets. The default width is 320. |
scaling |
Optional boolean that specifies whether the aspect ratio (height-to-width ratio) of the gadget is maintained when the browser is resized. Gadgets that can automatically scale vertically should set this to true, but gadgets which have a fixed height should set this to false. The default is true. |
scrolling |
Optional boolean that provides vertical and/or horizontal scrollbars if the content exceeds the space provided. If false, then the content is clipped to the height and width provided (not that width is not configurable). The default is false. |
singleton |
Optional boolean that specifies whether users
can add a gadget multiple times from a directory.
The default is true, meaning that by default,
gadgets can only be added once. Directories
can handle this attribute however they choose.
For example, the content
directory handles singleton="true" by
graying out and displaying the text "Added" for
gadgets that have already been added. Note
that changes to this attribute may not be
picked up by directories right away.
This attribute doesn't prevent users from adding gadgets multiple times through the developer gadget or Add by URL. Consequently, you still need to write your gadget to support multiple instances. |
author_photo |
For the authors page, a URL to a photo (70x100 PNG format preferred, but JPG/GIF are also supported). |
author_aboutme |
For the authors page, a statement about yourself (try to keep to ~500 characters). |
author_link |
For the authors page, a link to your website, blog, etc. |
author_quote |
For the authors page, a quote you'd like to include (try to keep to ~300 characters). |
To use certain gadget API features, such as dynamic height
or storing state, you need to load the appropriate JavaScript
library using the <Require> tag
(inside
<ModulePrefs>). The <Require> tag
has one required attribute, feature,
whose value specifies the feature library.
For example:
<ModulePrefs title="Set Userprefs Demo"> <Require feature="dynamic-height"/> <Require feature="setprefs" /> </ModulePrefs>
For more discussion of the feature libraries, see Feature-Specific JavaScript Libraries.
You can use <Locale> tags
under <ModulePrefs> to
specify the locales supported by your gadget. You can
also use it to specify message bundles, as described
in Internationalization.
For example, this snippet specifies two different locales:
<ModulePrefs ...> <Locale lang="en" country="us" /> <Locale lang="ja" country="jp" /> </ModulePrefs>
The "lang" (language) and "country" attributes
are both optional, but you must have at least one of
them for each <Locale>.
If you omit either attribute, the value is equivalent
to "*" and "ALL". If you specify
a country and no language, it is assumed that your gadget
supports all languages associated with the country. Likewise,
if you specify a language and no country, it is assumed
that your gadget supports all countries associated with
the language.
You can find the acceptable values you for "lang" and "country" here.
There are a few exceptions to the usual language rules:
lang="zh-cn" (typically
for country="cn").lang="zh-tw" (typically
for country="tw" or "hk", Taiwan
or Hong Kong, respectively). The following table lists the <Locale> attributes:
| Attribute | Description |
|---|---|
lang |
Optional string indicating the language associated with the locale. |
country |
Optional string indicating the country associated with the locale. |
messages |
Optional string that is a URL that points to a message bundle. Message bundles are XML files that contain the translated strings for a given locale. For more information, see Internationalization. |
language_direction |
Optional string that sets the direction of the
gadget. Its value can either be "rtl" (right-to-left)
or "ltr" (left-to-right). The default
is "ltr". This
attribute lets you create gadgets that support
both left-to-right and right-to-left languages.
For more discussion of this topic, see Creating
Bi-directional Gadgets. You can use
the following substitution variables in conjunction
with language_direction:
|
If you don't specify a <Locale>,
the default is assumed to be US + English only.
Not all gadgets can run in all environments. A gadget
may require a particular browser or software. You can
use the <MayRequire> tag
to provide information about special requirements of
your gadget. For example:
<ModulePrefs ...>
<MayRequire type="plugin" value="quicktime"/>
<MayRequire type="browser" value="firefox" min_version="1.06"/>
<MayRequire type="platform"
value="windows"> This gadget uses a Windows API.
</MayRequire>
</ModulePrefs>
The following table lists the <MayRequire> attributes:
| Attribute | Description |
|---|---|
type |
Required string indicating the type of requirement.
The supported types are "platform", "browser",
and "plugin". |
value |
Required string that provides a value for the
type. For example, type="plugin" value="flash". |
min_version |
Optional string indicating the minimal version number for the required item. |
cdata |
Optional string that provides additional information about the requirement. |
Some gadgets need to give users a way of supplying user-specific
information. For example, a weather gadget might require
users to provide their postal codes. The user preferences
(<UserPref>) section
in the XML file describes the user input fields that
are turned into user interface controls when the gadget
runs.
The following table lists the <UserPref> attributes:
| Attribute | Description |
|---|---|
name |
Required "symbolic" name of the user
preference; displayed to the user during editing
if no display_name is defined.
Must contain only letters, number and underscores,
i.e. the regular expression ^[a-zA-Z0-9_]+$.
Must be unique. |
display_name |
Optional string to display alongside the user preferences in the edit window. Must be unique. |
urlparam |
Optional string to pass as the parameter name
for content type="url". |
datatype |
Optional string that indicates the data type
of this attribute. Can be string, bool, enum, hidden (a
string that is not visible or user editable), or list (dynamic
array generated from user input). The default is string. |
required |
Optional boolean argument (true or false)
indicating whether this user preference is required.
The default is false. |
default_value |
Optional string that indicates a user preference's default value. |
User preferences can be accessed from your gadget using the user preferences JavaScript API, for example:
<script type="text/javascript">
var prefs = new _IG_Prefs();
var someStringPref = prefs.getString("StringPrefName");
var someIntPref = prefs.getInt("IntPrefName");
var someBoolPref = prefs.getBool("BoolPrefName");
</script>
One of the values you can specify for the <UserPref> datatype attribute
is enum. The enum data
type is presented in the user interface as a menu of
choices. You specify the contents of the menu using <EnumValue>.
For example, this <UserPref> lets
users set the level of difficulty for a game. Each value
that will appear in the menu (Easy, Medium, and Hard)
is defined using an <EnumValue> tag.
<UserPref name="difficulty"
display_name="Difficulty"
datatype="enum"
default_value="4">
<EnumValue value="3" display_value="Easy"/>
<EnumValue value="4" display_value="Medium"/>
<EnumValue value="5" display_value="Hard"/>
</UserPref>
The following table lists the <EnumValue> attributes:
| Attribute | Description |
|---|---|
value |
Required string that provides a unique value.
This value is displayed in the menu in the user
preferences edit box unless a display_value is
provided. |
display_value |
Optional string that is displayed in the menu
in the user preferences edit box. If you do not
specify a display_value,
the value is
displayed in the user interface. |
The <Content> section
defines the type of content, and either holds the content
itself or has a reference to external content. The <Content> section
is where the gadget attributes and user preferences are
combined with programming logic and formatting information
to become a running gadget. For more discussion on content
types, see Choosing
a Content Type.
The following table lists the <Content> attributes:
| Attribute | Description |
|---|---|
type |
Optional string that gives the type of the content.
The possible values are html
and url.
The default is html. |
href |
String that provides a destination URL. Required
for type="url", and not allowed for
other content types. |
cdata |
Optional string. For HTML, contains the raw HTML to render in the iframe. |
This section describes the JavaScript functions supported by the gadgets API. For a discussion of the requirements of using the JavaScript libraries, see Using the JavaScript Libraries with Different Content Types.
There are two different types of JavaScript libraries in the gadgets API:
The core JavaScript library includes general functions that aren't related to a specific feature.
This table lists the userprefs constructor, and the functions you can call on a userprefs object once you have instantiated it:
| Name | Description |
|---|---|
_IG_Prefs() |
The user preferences constructor. For example:var prefs
= new _IG_Prefs(); |
getString(userpref) |
Retrieves the specified userpref as
a String value. For a userpref that has a list data
type, retrieves the contents of the array as a single
string of pipe-delimited values. |
getInt(userpref) |
Retrieves the specified userpref as
an Integer value. |
getBool(userpref) |
Retrieves the specified userpref as
a Boolean value. |
getArray(userpref) |
For a userpref that
has a list data
type, retrieves the contents as an array. |
set(userpref, value) |
Sets the value for
the specified userpref. To use this function
you must include the setprefs library
in your gadget, as described in Setprefs
Library. For more discussion of this function
and an example, see Saving
State. |
setArray(userpref, [value...]) |
For a userpref that
has a list data
type, adds elements to the array. To use this
function you must include the setprefs library
in your gadget, as described in Setprefs
Library. For more discussion of this function,
see Using
the list Data Type . Example:prefs.setArray("mylist", ["Apples","Oranges"]); |
dump() |
For debugging, uses document.writeln() to display
all of the available preferences. |
This table lists the general purpose JavaScript methods that aren't specifically related to userprefs:
| Name | Description |
|---|---|
_IG_FetchContent(url,
func, {refreshInterval:num}) |
Fetches the content at url.
When it's ready, calls func.
Note that _IG_FetchContent() is
asynchronous, meaning that it returns immediately
and then calls the inner function later,
when the fetch finishes. This means that
you must put any dependent code inside the
callback function, or inside functions called
by the callback function. The optional refreshInterval parameter
lets you override the default caching behavior
by refreshing the cache every num seconds. For more discussion of this function, see Working with Text. |
_IG_FetchXmlContent(url,
func, {refreshInterval:num}) |
Fetches the XML content at url. When it's
ready, calls func.
The optional refreshInterval parameter
lets you override the default caching behavior
by refreshing the cache every num seconds. Like _IG_FetchContent(), is asynchronous.For more discussion of this function, see Working with XML. |
_IG_FetchFeedAsJSON(url,
func, num_entries, get_summaries) |
Fetches the RSS / Atom feed content at url and
returns it as a JSON object.
When it's ready, calls func.
Fetches the number of feed entries specified
by num_entries (default
is 3, possible range is 1-100), and optionally
fetches entry summaries depending on the
value of get_summaries (default
is false).
Like _IG_FetchContent(), is asynchronous.
For more discussion of this function, see Working with Feeds. |
_IG_RegisterOnloadHandler(func) |
Event handler that gets called on load. Takes a single argument, which is a function that is called after the gadget loads. The passed function takes no arguments. |
_gel(id) |
A wrapper around the JavaScript document.getElementById() function. |
_gelstn(tagname) |
A wrapper around the JavaScript document.getElementsByTagName() function. |
_esc(str) |
A wrapper around the JavaScript escape() and
encodeURIComponent() functions. |
_unesc(str) |
A wrapper around the JavaScript unescape() and
decodeURIComponent() functions. |
_trim(str) |
Trims whitespace from the beginning and end of
str. |
_uc(str) |
Returns an uppercase version of str. |
_min(val1, val2) |
Returns the lesser value of val1 and val2, or
val2 if they are equal. |
_max(val1, val2) |
Returns the greater value of val1 and val2,
or val2 if they
are equal. |
_hesc(str) |
Returns the HTML string str with
the following characters escaped: <>'" |
_args() |
Returns the URL parameter key-value pairs
from document.location as an associative
array. So, for example, "&foo=bar&up_cats=meow" would
be returned as {"foo":"bar", "up_cats":"meow"}.
Here is an example of how you might use it
to fetch the language or country:
var
lang = _args()["lang"]; |
_toggle(element) |
Toggles between showing and hiding an HTML element. |
_IG_GetImage(url,
{refreshInterval:num}) |
Returns the cached version of the image specified
by url. This can improve performance
in gadgets that have static images. For example: var img = _IG_GetImage(my_image_url);The optional refreshInterval parameter
lets you override the default caching behavior
by refreshing the cache every num seconds. The functions _IG_GetImageUrl() and
_IG_GetCachedUrl() also give you
access to cached content. For more discussion
of this topic, see Improving Gadget
Performance. |
_IG_GetCachedUrl(url, {refreshInterval:num}) |
Returns the proxy URL for the cached version
of the file specified by url.
Using cached content can improve gadget performance.
The optional refreshInterval parameter
lets you override the default caching behavior by refreshing the
cache every num seconds. |
The gadgets API includes the following feature libraries:
To use a particular feature library, you include it in your
gadget spec using the <Require> tag
(inside
<ModulePrefs>). For example:
<ModulePrefs title="My Tabbed Gadget"> <Require feature="tabs"/> </ModulePrefs>
The feature libraries are described in more detail below.
For a detailed discussion of using the setprefs library
and examples, see Saving
State.
To use the setprefs library, gadgets must include the
following line under <ModulePrefs>:
<Require feature="setprefs"/>
The setprefs library includes the following function:
set(userpref, value)
This function is called on a (typically hidden) userprefs object.
The userpref parameter specifies
the name of the user preference, and the value parameter
specifies the value that is being assigned to the user
preference. For example:
var prefs = new _IG_Prefs();
prefs.set("score", 5000);
For a detailed discussion of using the dynamic-height library and examples, see Managing
Gadget Height.
To use the dynamic-height library, gadgets must include
the following line under <ModulePrefs>:
<Require feature="dynamic-height" />
The dynamic-height library includes one function, which tells the
gadget to resize itself:
_IG_AdjustIFrameHeight()
For a detailed discussion of using the settitle library
and examples, see Setting a Gadget's
Title.
To use the settitle library,
gadgets must include the following line under <ModulePrefs>:
<Require feature="settitle" />
The settitle library includes
the following constructors:
| Function | Description |
|---|---|
_IG_SetTitle(title) |
Changes a gadget's title to title. |
For a detailed discussion of using the tabs library and
examples, see Tabs.
To use the tabs library, gadgets must include the following
line under <ModulePrefs>:
<Require feature="tabs" />
This table
lists the tabs constructor,
and the functions you can call on a tabs object once
you have instantiated it. A tabs object is the parent
container that holds an array of individual tab
objects.
| Function | Description |
|---|---|
_IG_Tabs(module_id,
opt_selected_tab, opt_container) |
The constructor that instantiates a new instance
of the tabs object,
which represents a set of tabs. The first parameter
is the __MODULE_ID__ of
the gadget. The optional parameter opt_selected_tab is
the name of the tab that is selected by default
the first time the gadget loads. If this parameter
is omitted, the first tab is selected by default.
The optional parameter opt_container specifies
an HTML element
to contain the tabs. If omitted, a
new HTML element is created and inserted at the
very top. This parameter lets you control where
the tabs appear in your gadget. |
addTab(tabName, opt_params) |
Adds a new tab based on the name-value pairs
specified in opt_params. You can
specify the following parameters:
For example: tabs.addTab("Tab", { |
addTab(tabName,
opt_domId, opt_callback) |
Adds a tab to the tabs object
and returns the DOM ID of the tab's associated <div>.
If the <div> doesn't
exist, the tabs library
creates one. The tabName parameter
gives the display name of the tab. The optional
parameter opt_domId provides
the DOM ID of the <div> holding
content for this tab. The optional opt_callback parameter
specifies a callback function that is fired each
time this tab is selected. |
addDynamicTab(tabName,
callback) |
Adds to the tabs object
a tab whose dynamic content is provided by a callback function.
Creates an empty <div> and
returns its DOM ID. The <div>'s
content must be dynamically generated from within
the callback function.
The tabName parameter
specifies the display name of the tab. The callback parameter
specifies the callback function
that is called each time this tab is selected. |
getSelectedTab() |
Returns a tab object for the currently selected tab. |
setSelectedTab(tabIndex) |
Selects the tab specified by tabIndex and
fires the tab's callback function if it exists.
If the tab is already selected, then the callback
is ignored. Tabs are indexed starting from 0.
Index is dependent on position If you change
a tab's position relative to other tabs, its
index changes accordingly. |
moveTab(tabIndex1,
tabIndex2) |
Swaps the positions of the tabs at tabIndex1 and tabIndex2.
The selected tab does not change and no callback
functions are called. |
removeTab(tabIndex) |
Removes the tab at tabIndex and
all of its associated content. |
getTabs() |
Returns an array of tab objects that includes all existing tabs. |
alignTabs(align, opt_offset) |
Sets how tabs are aligned in the HTML table that
contains them. Tabs are center-aligned by default.
The parameter align is a string
whose value must be one of the following (case-sensitive): left,
center, right The parameter opt_offset is a number, and it
only applies when the tab is left or right aligned.
It represents the number of pixels to offset
tabs from the left or right edge. The default
is 3px. |
displayTabs(display) |
Shows or hides tabs and all associated content. The display parameter is a boolean: true to
show tabs and false to hide tabs. |
getHeaderContainer() |
Returns the tab headers HTML container element. |
This table lists the functions you can call on a individual tab object.
| Function | Description |
|---|---|
getName() |
Returns the display name of the tab as a string (may contain HTML). |
getNameContainer() |
Returns the HTML element that contains the tab's name/label within the tab's header. |
getContentContainer() |
Returns the HTML element container where tab content is rendered. |
getCallback() |
Returns the JavaScript callback function that is executed every time the tab is selected. |
getIndex() |
Returns the tab's index |
For a detailed discussion of using the drag library and
examples, see Drag.
To use the drag library, gadgets must include the following
line under <ModulePrefs>:
<Require feature="drag" />
The drag library includes the following callback functions:
| Callback Function | Description |
|---|---|
onDragStart = function(newSource) {} |
Called when dragging starts. |
onDragTargetHit = function(newTarget, lastTarget)
{} |
Called when dragging is under way and a target has been hit. |
onDragTargetLost = function(lastTarget) {} |
Called when dragging is under way and the user is no longer on a target. |
onDragEnd = function(source, target) {} |
Called when dragging has ended (the user has let go of the mouse button). |
onDragClick = function(source) {} |
Called when the user never moved the mouse, but had a mouse down and mouse up on a source. |
This table lists the drag constructor, and the functions
you can call on a drag object once you have instantiated
it. Sources and targets are HTML elements that have associated
DOM ID's. Sources and targets also have drag ID's. If
no drag ID is specified, the drag library uses the DOM
ID as the drag ID.
| Function | Description |
|---|---|
_IG_Drag() |
The drag constructor. Instantiates a drag object
to which you can add sources and targets. |
addSource(DOM_id) |
Adds a source to the drag object, where DOM_id is the unique identifier for the HTML
element being added as a source. If you
don't specify a drag ID, the drag library
uses the HTML element's DOM ID as the drag
ID. For example:drag_obj.addSource("dom_id1"); |
addSource(drag_id, HTML_element) |
Adds HTML_element as a source to the drag object. Assigns the source a drag_id. For
example:
drag_obj.addSource("first",
_gel("dom_id1")); |
addSource(drag_id, HTML_element, surrogate) |
Adds HTML_element as a source to the drag object. Assigns the source a drag_id. This
function also includes a surrogate parameter
that specifies the HTML markup you want to
use for the surrogate. The surrogate is a
blank object that impersonates the source
when the user is in mid-drag. By default,
the surrogate is a clone of the source.
For example:drag_obj.addSource("first", _gel("dom_id1"), "<b>This
is my surrogate</b>"); |
removeSource(drag_id) |
Removes the source specified by drag_id. |
removeAllSources() |
Removes all sources from the drag object. |
addTarget(DOM_id) |
Adds a target to the drag object, where DOM_id is the unique identifier for the HTML
element being added as a target. If you
don't specify a drag ID, the drag library
uses the HTML element's DOM ID as the drag
ID. |
addTarget(drag_id, HTML_element) |
Adds HTML_element as a target to the drag object.
Assigns the target a drag_id. |
addTarget(drag_id, HTML_element, priority) |
Adds HTML_element as a target to the drag object.
Assigns the target a drag_id. The priority parameter
is a numeric value that specifies the priority
if there are overlapping targets. Targets with
higher priorities get selected in case of conflict.
By default, a target's priority is 0. If two
targets are "hittable," the one with
the numerically higher priority is hit. For example,
a target with a priority of 4 would take precedence
over a target with a priority of 2. |
removeTarget(drag_id) |
Removes the target specified by drag_id. |
removeAllTargets() |
Removes all targets from the drag object. |
The drag library includes the properties listed below.
You access these properties through a drag object. For
example:
if (drag_obj.isDragging == true) {
// do something
}
This table lists read-only properties:
| Read-Only Property | Description |
|---|---|
isDragging |
True if the user is dragging. |
hasDragged |
True if is isDragging is true and the user has
moved the mouse since the last mouseDown. |
surrogate |
Points to the current surrogate. |
surrogateInitialX, surrogateInitialY |
Where the surrogate started out at the start of the drag. |
curSource |
Points to the current source. Is null if the user is not dragging. |
curTargetId |
Contains the ID of the current target. Is null if the user is not dragging. |
This table lists read-write properties. Changing these properties affects how dragging works. Do not change them during dragging:
| Read-Write Property | Description |
|---|---|
leftMargin, rightMargin, topMargin, bottomMargin |
Each target has a margin around it. You can change how sensitive the targets are by changing this value. By default the margin is 2 pixels. |
surrogateOffsetX, surrogateOffsetY |
You can change these values to have the surrogate be a few pixels offset when the drag starts. The default value is 1 pixel. It's not 0 because a value of 1 ensures that the user gets feedback when dragging starts. |
For a detailed discussion of using the grid library
and examples, see Grid.
To use the grid library,
gadgets must include the following line under <ModulePrefs>:
<Require feature="grid" />
The functions in the grid library
are summarized below.
As part of using the grid library, you must implement the following backend functions:
| Function | Description |
|---|---|
_IGG_getNormalView(index) |
Returns the default HTML content of the cell at index to
be displayed when the user is not dragging. |
_IGG_isDragSource(index) |
Returns a boolean value to indicate whether the element at
index is a drag source. |
_IGG_isDragTarget(index, sourceIndex) |
Returns a boolean value to indicate whether the element at
index is a drag target when sourceIndex is
a drag source. |
By default, the grid library calls
getNormalView() whenever it wants to display the contents
of a cell. However, you may want the contents of a cell to react and
be displayed differently based on how the user is dragging. For those
cases, you can implement the following optional functions for your
backend object.
| Function | Description |
|---|---|
_IGG_getSurrogateView(index) |
Returns the HTML content of the surrogate view (visible under
the mouse cursor) when the content at index is
being dragged. |
_IGG_getSourceView(source, target) |
Returns the HTML contents of the cell that is the source when
the user is dragging. If the mouse cursor is over a target,
then target contains the index of the target;
otherwise, it contains -1. |
_IGG_getTargetView(target, source) |
Returns the HTML content of the cell when it is the target and the user is dragging. The source is the index of the
source. |
_IGG_getPossibleTargetView(potential_target, source) |
Returns the HTML content of the cell when it is a potential_target (but not the target) and the user is dragging. The source is
the index of the source. |
_IGG_getDragView(index, source) |
Returns the HTML content of the cell at index when
it is neither a potential target nor the source, and the user
is dragging. The source is
the index of the source. |
The grid library provides the following functions to let your gadget respond to mouse clicking and dragging:
| Function | Description |
|---|---|
_IGG_handleClick(source) |
Called when the user has clicked the source (that is, when
the user has performed a mouseDown and mouseUp without dragging
the mouse). |
_IGG_handleDragStart(source) |
Called when the user has done a mouseDown on the source and
has started the drag process. |
_IGG_handleDrag(source, target) |
Called when the user has finished dragging. If the
user ended on a valid target, then target contains
the target's index. Otherwise, it has the value -1. Note that if _IGG_handleClick() is called, _IGG_handleDrag() is called
too. So, depending on the application, it may make more sense to just use
_IGG_handleDrag(). |
Backend callback functions are automatically created in your backend object. The grid library calls them as necessary, but you can also call them yourself, such as when your data is changing through a processes other than user dragging. The grid library includes the following backend callbacks:
| Function | Description |
|---|---|
_IGG_refreshCell(index) |
Refreshes the display of the cell at index. |
_IGG_refreshAll() |
Refreshes the display of all cells. Note that this can be a time-consuming operation, particularly if you have a large, complex grid. |
The grid library includes the grid object fields and functions listed below. You access these through a grid object. For example:
document.getElementById("summary").innerHTML = "In the grid " + mygrid.name +
" the HTML content of the source is " + mygrid.getCellValue(mygrid.source);
The fields and functions you can access through a grid object are as follows:
| Function | Description |
|---|---|
initDragging() |
Makes the grid sensitive to dragging. |
dataObject |
The backend object. |
name |
The prefix string prepended to all DOM ids made by the grid. |
height, width |
The grid's height and width parameters. |
maxIndex |
The largest index value of any cell. This is usually height*width-1,
but it can be a higher number if you create extra cells using
getCell(). |
source |
The index of the current source. The value is -1 if the user is not dragging. |
target |
The index of the current target. The value is -1 if the user is not dragging or is not over a target. |
getCellName(index) |
Returns the DOM ID of the SPAN element containing the contents
of the cell at index. |
getCellTDID(index) |
Returns the DOM ID of the TD element containing the SPAN element
that contains the contents of the cell at index. |
getCellValue(index) |
Returns the HTML content of the cell at index. |
getTable() |
Returns the DOM table that contains the cell. |
getCell(index) |
Returns the cell AT index. If index < 0,
returns null. If index > maxIndex, a new cell is created
with that index. This allows you to have cells that are not
in the table. |
makeNewTable() |
Completely rebuilds the DOM HTML table. Note that you may have to reattach the new table to your DOM tree, and that this may slow down your page as the old table probably needs to be garbage-collected. |
table |
Direct access to the DOM HTML table. You'll probably want to use getTable() instead of changing this. |
cells |
A direct access to the array containing DOM cells. You'll
probably want to use getCell() instead of changing this. |
dragHandler |
The _IG_Drag object (see drag
Library) for managing
this grid's dragging. |
setXMapper, setYMapper |
Changes the mappers in the internal _IG_Drag object. |
isRightButton |
Returns true if the user used the right button on the last
drag. |
refreshCell(index) |
Refreshes the cell at index. This is equivalent to using the
_IGG_refreshCell() callback. |
refreshAll() |
Refreshes all cells. This is equivalent to using the
_IGG_refreshAll() callback. |
refreshDragSources() |
Forces a recalculation of all cells to see which ones are sources and registers them with the underlying Drag object. |
refreshDragTargets(sourceIndex) |
Refreshes all cells that are targets of source at sourceIndex.
Note that this doesn't register the targets with the underlying
Drag object. |
refreshDragNonTargets(sourceIndex) |
Refreshes all cells that are not targets of the
source at sourceIndex. |
addDragSource(index) |
Adds a cell to be a valid source (even if isDragSource had
returned false). |
removeDragSource(index) |
Removes a cell as a valid source (even if isDragSource had
returned true). |
removeDragSource(index) |
Removes a cell as a valid source (even if isDragSource had
returned true). |
calculateDragTargets(sourceIndex) |
Registers all targets of the source at sourceIndex with the
underlying Drag object. |
If you override the dragHandler in the Grid object,
sometimes the user will drag something that the Grid
can't handle. In that case, it will attempt to call these
functions in your backend object if they exist. See drag
Library for details on how they work.
_IGG_handleOnDragStart(object) _IGG_handleOnDragTargetHit(object) _IGG_handleOnDragTargetLost() _IGG_handleOnDragEnd(object, object) _IGG_handleOnDragClick(object) For a detailed discussion of using the MiniMessage library and examples, see MiniMessages.
To use the MiniMessage library, gadgets must include the
following line under <ModulePrefs>:
<Require feature="minimessage" />
This table lists the MiniMessage constructor, and the functions you can call on a MiniMessage object once you have instantiated it:
| Function | Description |
|---|---|
_IG_MiniMessage(moduleId,
opt_container) |
The MiniMessage constructor.
Instantiates a new MiniMessage object. Takes
the
__MODULE_ID__ of
the gadget as a parameter. The constructor
optionally takes an opt_container parameter,
which specifies an HTML element
(typically a <div>)
where messages are appended. If opt_container is
omitted, a default message container is auto-generated
and placed at the top of the gadget. For example: var
mini = new _IG_MiniMessage(__MODULE_ID__, _gel("messageContainer")); |
createDismissibleMessage(msg,
opt_callback) |
Creates a dismissible message.
The parameter
msg is an HTML
string or element. The message is displayed with
a clickable [x] link that allows the user to
dismiss the message. When the message is dismissed,
it is removed from the DOM, and the optional
callback function opt_callback is
called. If the callback returns
false, dismissal is cancelled.
For example: mini.createDismissibleMessage("Loading message"); |
createTimerMessage(msg,
seconds, opt_callback) |
Creates a timed message that
displays for the specified number of seconds.
The parameter
msg is an HTML
string or element. When the timer expires, the
message initiates the dismissal procedure where
the optional callback function opt_callback executes.
If the callback returns false, dismissal is cancelled.
For example: mini.createTimerMessage("Your account has
been updated.", 5); |
createStaticMessage(msg) |
Creates a static message that
displays until it is programmatically dismissed
by dismissMessage(msg). The
parameter
msg is an HTML
string or element.For example: var loadMsg
= mini.createStaticMessage("Loading
content..."); |
dismissMessage(msg) |
Dismisses the specified message
msg. This function
is the only way to dismiss a static message. For example: var loadMsg
= mini.createStaticMessage("Loading
content..."); |
For a detailed discussion of using the analytics library
and examples, see Using
Analytics.
To use the analytics library, gadgets must include the
following line under <ModulePrefs>:
<Require feature="analytics" />
The analytics library includes the following function:
| Function | Description |
|---|---|
_IG_Analytics(id, path) |
Records a single page view to a single Google
Analytics account. Supports multiple calls
within a single gadget. The id parameter
is a Google Analytics account ID. The path parameter
is the virtual page view path that is recorded
back to Google Analytics for each call. Set
this to a unique name so you can identify
the page view hits for different gadgets
within your analytics reports.For example: _IG_Analytics("UA_000000-0", "/weathergadget");
|
For a detailed discussion of using the flash library
and examples, see Flash.
To use the flash library,
gadgets must include the following line under <ModulePrefs>:
<Require feature="flash" />
The flash library includes the following functions:
| Function | Description |
|---|---|
_IG_EmbedFlash(swf_url, swf_container, opt_params) |
Embeds the .swf file specified by swf_url, and
displays it in the gadget at the location specified by swf_container.
The parameter opt_params is an object that optionally includes
the following:
_IG_EmbedFlash() returns true if
successful, or false if not.
Note: If you experience performance problems or if the caret does not display (sometimes an issue in Firefox 2.0), try explicitly setting wmode to "window" as follows: _IG_EmbedFlash("example.swf", "wrapper",
{wmode: "window"}); |
_IG_GetFlashMajorVersion() |
Returns the Flash Player's major version or zero if Flash Player is not detected. |
The locked-domain library isolates your gadgets from other gadgets running on the same page. You can only use this feature with type="html" gadgets.
To use the locked-domain library, gadgets must include the following line under <ModulePrefs>:
<Require feature="locked-domain"/>
We suggest that you add this feature requirement to your gadget if your gadget stores sensitive private user data. This feature is only supported on iGoogle. Other gadget containers may not support this feature and will reject your gadget.
When the gadget URL is requested from iGoogle, parameters
are appended to the request, which is a GET method. This
only applies when your content type is set to "url"--see URL for
more information. These parameters can be read by a gadget
using JavaScript, or by a server-side web application.
For an example, see URL.
The parameters that are passed are listed in the following table:
| Name | Description |
|---|---|
up_<name> |
A user preference and its value. For each of
the user preferences, the name-value pair are
passed as parameters using the following format: &up_<name>=<value> For example, suppose you had a zip code parameter called zp, and a user assigned it a value of
94306. It would be passed in the URL as follows: &up_zp=94306 |
lang |
The user's language preference (set in the browser). |
country |
The user's home country (defined in the user's Google account). |