Web Gadget SDK Web Gadget SDK
[Back to Web Gadget API Reference]
Module Class
An instance of the Module object is created for each Gadget. The Module object that can be used to access various UI elements and settings that are specific to the Gadget. You can obtain a reference your Gadget's module object from the constructor of your Gadget:

        
Microsoft.Live.SampleGadget = function( p_elSource, p_args, p_namespace )
{               
    Microsoft.Live.SampleGadget.initializeBase(this, arguments);      
    var m_module = p_args.module;
    ...
}        
        

deletePreference Method
Removes a setting object that was previously set by the setPreference method. In general, it is a good idea to remove any settings that your Gadget had set but will no longer need to minimzethe amount of data transferred from the server.
Syntax
module.deletePreference(strKey);
Parameters
Parameter Description
strKey The key name of the preference to delete.
Return Value
None
Example
The following example shows how a preference is deleted.
module.setPreference("Age", 14);
...
module.deletePreference("Age");
getEl Method
Returns the DOM element object that contains the Gadget.
Syntax
module.getEl();
Parameters
None
Return Value
The DOM element object that contains the Gadget.
getFooterEl Method
Inline Gadgets only. Returns the DOM element object that contains the footer of the Gadget.
Syntax
module.getFooterEl();
Parameters
None
Return Value
The DOM element object that contains the footer of the Gadget.
getId Method
Returns the ID of the "div" element that contains the Gadget.
Syntax
module.getId();
Parameters
None
Return Value
String representing the ID of the "div" DOM element object that contains the Gadget.
getLanguage Method
Returns a string that represents the current language used.
Syntax
module.getLanguage();
Parameters
None
Return Value
String representing the current language used. This is typically the two character language code such as "en" for English, or "ja" for Japanese. Live.com currently supports the following languages:
Returns the URL associated with the Gadget title. The URL associated with the Gadget title is most commoly set by using the "link" element in the Gadget manifest:

<?xml version="1.0"?>
<rss version="2.0" xmlns:binding="http://www.live.com">
    <channel>
        
        <title>Hello World</title>
        <link>http://www.microsoft.com</link>
        ...    
    </channel>
</rss>      
        
Inline Gadgets can also use setTitleLink to change the Gadget title URL.
Syntax
module.getLink();
Parameters
None
Return Value
String representing the URL associated with the title of the Gadget. The web browser will navigate to this URL when the user clicks on the title of the Gadget.
getLocale Method
Returns a string that represents the current locale used.
Syntax
module.getLocale();
Parameters
None
Return Value
String representing the current locale used. This is typically the two character language code such as "us" for United States, or "jp" for Japan. Live.com currently supports the following locales:
getMarket Method
Returns a string that represents the current market used. The market string is the concatentation of the language and the locale string, with a "-" character in between.
Syntax
module.getMarket();
Parameters
None
Return Value
String representing the current market used. Live.com currently supports the following markets:
getMode Method
Returns the mode of the gadget � author or viewer.
Syntax
module.getMode();
Parameters
None
Return Value
A Web.Enum representing the mode of the gadget. Enum contains the values: ie: p_args.module.getMode() == Web.Gadget.Mode.author
Note: getMode() always returns Web.Gadget.Mode.author when hosted on a live.com page. When a gadget is hosted on a space, getMode() may return either author or viewer
getPreference Method
Returns a setting object previously stored via the setPreference method. Settings are scoped to per user and per Gadget instance.
Syntax
module.getPreference(strKey);
Parameters
Parameter Description
strKey The key name of the preference to get.
Return Value
The setting object that was previously set using strKey. If such a setting object does not exist, this method will return null.
getTitle Method
Returns the title of the Gadget. The title of the Gadget is most commoly set in the Gadget manifest. Inline Gadgets can also use setTitleText to change the Gadget title.
Syntax
module.getTitle();
Parameters
None
Return Value
String representing the title of the Gadget.
resize Method
Resizes the Gadget based on the current context so that the contents fit within the Gadget body. Note that this is usually not needed when the Gadget is run with Internet Explorer. However, for cross-browser compatibility, you should always call this method whenever the contents of your Gadget changes in a way that may require a resize.
Syntax
module.resize();
Parameters
None
Return Value
None
resolveUrl Method
Resolves a relative URL with the location of the manifest URL as the base location. Returns a string containing the resolved absolute URL.
Syntax
module.resolveUrl(strRelUrl);
Parameters
Parameter Description
strRelUrl Relative URL to be resolved.
Return Value
Absolute URL resolved according to the relative URL passed in with the location of the manifest URL as the base.
Example
The following example shows how you would build an image tag in JavaScript that points to an image file that resides in the parent directory of your Gadget manifest file.
var strUrl = module.resolveUrl("../books.gif");
var elImg = document.createElement("img");
elImg.setAttribute("src", strUrl);
...
setFooterText Method
Inline Gadgets only. Sets the text used in the footer of the Gadget.
Syntax
module.setFooterText(strFooter);
Parameters
Parameter Description
strFooter Text of the Footer to set.
Return Value
None
setPreference Method
Sets a setting object that can be later retrieved using the getPreference method.
Syntax
module.setPreference(strKey, objSetting);
Parameters
Parameter Description
strKey The key name of the preference to set.
objSetting The setting object to be stored. Note that the setting does not need to be an object, but also be of any primitive data type or string.
Return Value
None
setTitleIcon Method
Inline Gadgets only. Sets the icon used in the title of the Gadget. This method accepts a variable number of ojbects, each containing two properties: state and iconUrl. For now, state can be one of {expanded, collapsed, all} which sets the icon in the title bar for the Gadget in the expanded, collapsed and all states, respectively. Note that iconUrl should point to a valid .gif file.
Syntax
module.setTitleIcon(obj1, obj2, ...);
Parameters
Parameter Description
objN An object that contains two properties: state and iconUrl. The state can be one of {expanded, collapsed, all}. The iconUrl should be an absolute URL that points to a valid GIF file. If you want to use a relative URL for iconUrl, you should use resolveUrl to convert the relative URL into an absolute URL before passing it into this method.
Return Value
None
Example
The following example shows how to use this method to change the title icon of the Gadget in all of its states.
m_module.setTitleIcon( {state:"all", "http://SampleDomain/img/icon.gif" } );
...
Inline Gadgets only. Sets the URL associated with the title of the Gadget.
Syntax
module.setTitleLink(strUrl);
Parameters
Parameter Description
strUrl The absolute URL to set for the Gadget title.
Return Value
None
setTitleText Method
Inline Gadgets only. Sets the title text of the Gadget.
Syntax
module.setTitleText(strTitle);
Parameters
Parameter Description
strTitle The title text to set.
Return Value
None