This document describes the classes and methods in the
gadgets.* namespace,
some of which are feature-specific.
For information on including features,
see the
Gadgets Specification.
Note: This API is not yet supported by the production instance of iGoogle, though it is available in the iGoogle sandbox. If you'd like to write a gadget for iGoogle, see the gadgets API Reference.
This document uses the following conventions for types:
Boolean object).String object).MiniMessage class, used to create messages that will appear to the user within the gadget. Typical use cases:
gadgets.MiniMessage(opt_moduleId, opt_container)
HTMLElement
createDismissibleMessage(message, opt_callback)
HTMLElement
createStaticMessage(message)
HTMLElement
createTimerMessage(message, seconds, opt_callback)
dismissMessage(message)
gadgets.MiniMessage(opt_moduleId, opt_container)
String opt_moduleId - Optional module ID
HTMLElement opt_container - Optional HTML container element where
mini-messages will appear
HTMLElement createDismissibleMessage(message, opt_callback)
String, Object message - The message as an HTML string or DOM element
Function opt_callback - Optional callback function to be called when
the message is dismissed
HTMLElement HTML element of the created message
HTMLElement createStaticMessage(message)
String, Object message - The message as an HTML string or DOM element
HTMLElement HTML element of the created message
HTMLElement createTimerMessage(message, seconds, opt_callback)
String, Object message - The message as an HTML string or DOM element
number seconds - Number of seconds to wait before dismissing
the message
Function opt_callback - Optional callback function to be called when
the message is dismissed
HTMLElement HTML element of the created message
dismissMessage(message)
HTMLElement message - HTML element of the message to remove
Provides access to user preferences, module dimensions, and messages. Clients can access their preferences by constructing an instance of gadgets.Prefs and passing in their module ID. Example:
var prefs = new gadgets.Prefs();
var name = prefs.getString("name");
var lang = prefs.getLang();
gadgets.Prefs(opt_moduleId)
Array.<String>
getArray(key)
Boolean
getBool(key)
String
getCountry()
Number
getFloat(key)
Number
getInt(key)
String
getLang()
String, Number
getModuleId()
String
getMsg(key)
String
getString(key)
set(key, val)
setArray(key, val)
gadgets.Prefs(opt_moduleId)
String, Number opt_moduleId - An optional parameter specifying the
module ID to create prefs for; if not provided, the default module ID
is used
Array.<String> getArray(key)
String key - The preference to fetch
Array.<String> The preference; if not set, an empty array
Boolean getBool(key)
String key - The preference to fetch
Boolean The preference; if not set, false
String getCountry()
String The country for this module instance
Number getFloat(key)
String key - The preference to fetch
Number The preference; if not set, 0
Number getInt(key)
String key - The preference to fetch
Number The preference; if not set, 0
String getLang()
String The language for this module instance
String, Number getModuleId()
String, Number The module ID for this module instance
String getMsg(key)
String key - The message to fetch
String The message
String getString(key)
String key - The preference to fetch
String The preference; if not set, an empty string
set(key, val)
Note: If the gadget needs to store an Array it should use setArray instead of this call.
String key - The pref to store
Object val - The values to store
setArray(key, val)
String key - The pref to store
Array val - The values to store
Tab class for gadgets. You create tabs using the TabSet addTab() method. To get Tab objects, use the TabSet getSelectedTab() or getTabs() methods.
See also: TabSet
Function
getCallback()
HTMLElement
getContentContainer()
Number
getIndex()
String
getName()
HTMLElement
getNameContainer()
Function getCallback()
Function The callback function of the tab
HTMLElement getContentContainer()
HTMLElement The HTML element of the content container
Number getIndex()
Number The tab's index
String getName()
String The label of the tab
HTMLElement getNameContainer()
HTMLElement The HTML element of the tab's label
A class gadgets can use to make tabs.
gadgets.TabSet(opt_moduleId, opt_defaultTab, opt_container)
String
addTab(tabName, opt_params)
alignTabs(align, opt_offset)
displayTabs(display)
HTMLElement
getHeaderContainer()
gadgets.Tab
getSelectedTab()
Array.<gadgets.Tab>
getTabs()
removeTab(tabIndex)
setSelectedTab(tabIndex)
swapTabs(tabIndex1, tabIndex2)
gadgets.TabSet(opt_moduleId, opt_defaultTab, opt_container)
String opt_moduleId - Optional suffix for the ID of tab container
String opt_defaultTab - Optional tab name that specifies the name of
of the tab that is selected after initialization;
if this parameter is omitted, the first tab is selected by
default
HTMLElement opt_container - The HTML element to contain the tabs; if
omitted, a new div element is created and inserted at the
very top
String addTab(tabName, opt_params)
String tabName - Label of the tab to create
Object opt_params - Optional parameter object
String DOM id of the tab container
alignTabs(align, opt_offset)
String align - 'left', 'center', or 'right'
Number opt_offset - Optional parameter to set the number of pixels
to offset tabs from the left or right edge; the default
value is 3px
displayTabs(display)
Boolean display - True to show tabs; false to hide tabs
HTMLElement getHeaderContainer()
HTMLElement The tab headers container element
gadgets.Tab getSelectedTab()
gadgets.Tab The currently selected tab object
Array.<gadgets.Tab> getTabs()
Array.<gadgets.Tab> Array of all existing tab objects
removeTab(tabIndex)
Number tabIndex - Index of the tab to remove
setSelectedTab(tabIndex)
Number tabIndex - Index of the tab to select
swapTabs(tabIndex1, tabIndex2)
Number tabIndex1 - Index of the first tab to swap
Number tabIndex2 - Index of the secnod tab to swap
Embeds Flash content in gadgets.
<static>
Boolean
embedCachedFlash()
<static>
Boolean
embedFlash(swfUrl, swfContainer, swfVersion, opt_params)
<static>
Number
getMajorVersion()
<static> Boolean embedCachedFlash()
Boolean Whether the function call completes successfully
<static> Boolean embedFlash(swfUrl, swfContainer, swfVersion, opt_params)
String swfUrl - SWF URL
String, Object swfContainer - The ID or object reference of an
existing HTML container element
Number swfVersion - Minimum Flash Player version required
Object opt_params - An optional object that may contain any valid HTML
parameter; all attributes will be passed through to the Flash movie on
creation
Boolean Whether the function call completes successfully
<static> Number getMajorVersion()
Number The major version of Flash Player
or 0 if Flash is not supported
Provides remote content retrieval functions.
<static>
String
encodeValues(fields)
<static>
String
getProxyUrl(url, opt_params)
<static>
makeRequest(url, callback, opt_params)
<static> String encodeValues(fields)
Object fields - The post fields you wish to encode
String The processed post data; this includes a trailing
ampersand (&)
<static> String getProxyUrl(url, opt_params)
String url - The URL to get the proxy URL for
Map<String, String> opt_params - Additional optional
parameters
to pass to the request
String The proxied version of the URL
<static> makeRequest(url, callback, opt_params)
var params = {};
params[gadgets.io.RequestParameters.CONTENT_TYPE] = gadgets.io.ContentType.TEXT;
gadgets.io.makeRequest(url, callback, params);
If opt_params[gadgets.io.RequestParameters.AUTHORIZATION] is set to
gadgets.io.AuthorizationType.SIGNED,
the container needs to vouch
for the user's identity to
the destination server.
The container does this by doing the following:
Removing any request parameters with names that begin with oauth, xoauth,
or opensocial (case insensitive).
Adding the following parameters to the request query string:
getId() value on the viewer person object.getId() value on the owner person object.opensocial_app_url and
opensocial_instance_id
uniquely identify an instance of an
application in a container. Signing the resulting request according to section 9 of the OAuth specification.
If a container uses public keys to sign requests, the container may choose to use either self-signed certificates or certificates signed by a well-known certificate authority. If a container does not distribute its OAuth signing key over HTTPS, it should use a certificate signed by a well-known certificate authority.
The commonName attribute of the certificate should match the
hostname of the container server, and should also match the value of
the oauth_consumer_key parameter specified in the request.
The container should make its public key available for download
at a well-known location. The location
https://container-hostname/opensocial/certificates/xoauth_public_keyvalue
is recommended.
Recipients of signed requests must verify that the signature on the request is correct, and that the timestamp on the request is within a reasonable time window. A time window of 5 minutes before and after the current time is recommended.
Recipients of signed requests may use the oauth_consumer_key and
xoauth_public_key parameters to automatically detect when a container
deploys new certificates. If the container deploys certificates at a
well-known location, the recipient may automatically download the new
certificate. Recipients that automatically download new certificates
should cache the resulting certificates.
If a container's certificate is not downloaded from
https://container-hostname, the recipient should verify that the
certificate is signed by a well-known certificate authority before
trusting the certificate.
If opt_params[gadgets.io.RequestParameters.AUTHORIZATION] is set
to gadgets.io.AuthorizationType.OAUTH,
the container needs to use OAuth to gain access to
the resource specified in the request.
This may require that the gadget obtain the user's content by
directing the user to the service provider to gain access.
The following additional parameters may be specified in opt_params:
If OAuth is used, the container should execute the OAuth protocol on
behalf of the gadget. If the gadget has not registered a consumer key
for use with this service provider, the container may choose to use a
default RSA signing key corresponding to a well-known certificate to sign
requests. If the container uses a default consumer key, it will include
an additional OAuth parameter xoauth_app_url that identifies the gadget
making the request.
The makeRequest() callback parameter
is passed a javascript object with
several OAuth-specific fields in addition to the normal values returned
by makeRequest():
String url - The URL where the content is located
Function callback - The function to call with the data from the
URL once it is fetched
Map.<gadgets.io.RequestParameters, Object> opt_params - Additional
request parameters or
proxy
request parameters
Used by RequestParameters.
<static> object
NONE
<static> object
OAUTH
<static> object
SIGNED
<static> object NONE
<static> object OAUTH
<static> object SIGNED
Used by RequestParameters.
<static> object
DOM
<static> object
FEED
<static> object
JSON
<static> object
TEXT
<static> object DOM
<static> object FEED
<static> object JSON
<static> object TEXT
Defines values for RequestParameters.METHOD.
<static> object
DELETE
<static> object
GET
<static> object
HEAD
<static> object
POST
<static> object
PUT
<static> object DELETE
<static> object GET
<static> object HEAD
<static> object POST
<static> object PUT
Used by
gadgets.io.getProxyUrl() method.
<static> object
REFRESH_INTERVAL
<static> object REFRESH_INTERVAL
Used by the
gadgets.io.makeRequest() method.
<static> object
AUTHORIZATION
AuthorizationType.NONE.
<static> object
CONTENT_TYPE
ContentType.TEXT.
<static> object
GET_SUMMARIES
<static> object
HEADERS
<static> object
METHOD
MethodType.GET.
<static> object
NUM_ENTRIES
<static> object
POST_DATA
<static> object AUTHORIZATION
AuthorizationType.NONE.
Specified as an
AuthorizationType.
<static> object CONTENT_TYPE
ContentType.TEXT.
Specified as a
ContentType.
<static> object GET_SUMMARIES
Boolean.
<static> object HEADERS
Map.<String,String>.
<static> object METHOD
MethodType.GET.
Valid values are specified by
MethodType.
<static> object NUM_ENTRIES
Number.
<static> object POST_DATA
String.
Provides operations for translating objects to and from JSON.
<static>
Object
parse(text)
<static>
String
stringify(v)
<static> Object parse(text)
String text - The string to transform into an object —
usually the result of a previous stringify call
Object The object parsed from the passed in text; false if
an error occurred
<static> String stringify(v)
Object v - The object to convert
String The JSON equivalent
Provides operations for publishing and subscribing to message channels.
<static>
publish(channelName, message)
<static>
subscribe(channelName, callback)
<static>
unsubscribe(channelName)
<static> publish(channelName, message)
String channelName - The name of the channel
String message - The message to publish
<static> subscribe(channelName, callback)
String channelName - The name of the channel
Function callback - A function that will be called with the channel
messages
<static> unsubscribe(channelName)
String channelName - The name of the channel
Provides operations for making remote procedure calls for gadget-to-container, container-to-gadget, and gadget-to-gadget communication.
<static>
call(targetId, serviceName, callback, var_args)
<static>
register(serviceName, handler)
<static>
registerDefault(handler)
<static>
unregister(serviceName)
<static>
unregisterDefault()
<static> call(targetId, serviceName, callback, var_args)
String targetId - ID of the RPC service provider;
empty if calling the parent container
String serviceName - Service name to call
Function, null callback - Callback function (if any) to process
the return value of the RPC request
* var_args - Parameters for the RPC request
<static> register(serviceName, handler)
String serviceName - Service name to register
Function handler - Service handler
<static> registerDefault(handler)
Function handler - Service handler
<static> unregister(serviceName)
String serviceName - Service name to unregister
<static> unregisterDefault()
Provides operations for getting display information about the currently shown skin.
<static>
String
getProperty(propertyKey)
<static> String getProperty(propertyKey)
String propertyKey - The key to get data for;
keys are defined in
gadgets.skins.Property
String The data
All of the display values that can be fetched and used in the gadgets UI. These are the supported keys for the gadgets.skins.getProperty() method.
<static> object
ANCHOR_COLOR
<static> object
BG_COLOR
<static> object
BG_IMAGE
<static> object
FONT_COLOR
<static> object ANCHOR_COLOR
<static> object BG_COLOR
<static> object BG_IMAGE
<static> object FONT_COLOR
Provides general-purpose utility functions.
<static>
String
escapeString(str)
<static>
Object
getFeatureParameters(feature)
<static>
Boolean
hasFeature(feature)
<static>
registerOnLoadHandler(callback)
<static>
String
unescapeString(str)
<static> String escapeString(str)
String str - The string to escape
String The escaped string
<static> Object getFeatureParameters(feature)
<Param> subelement of the
<Requires> or
<Optional> element.
String feature - The feature to get parameters for
Object The parameters for the given feature, or null
<static> Boolean hasFeature(feature)
String feature - The feature to test for
Boolean True if the feature is supported
<static> registerOnLoadHandler(callback)
Function callback - The handler to run
<static> String unescapeString(str)
String str - The string to unescape.
String The unescaped string
Provides operations for dealing with views.
See also:
gadgets.views.View
<static>
String
bind(urlTemplate, environment)
<static>
gadgets.views.View
getCurrentView()
<static>
Map.<String, String>
getParams()
<static>
Map<gadgets.views.ViewType, String, gadgets.views.View>
getSupportedViews()
<static>
requestNavigateTo(view, opt_params, opt_ownerId)
<static> String bind(urlTemplate, environment)
See also:
View.getUrlTemplate()
urlTemplate - A url template for a container view
environment - A set of named variables
(for example, [OWNER | PATH | PARAMS | NAME]) of type string.
String A URL string