Building custom gadgets : Creating Google gadgets : Using gadget features
 
Using gadget features
Google gadgets use features to describe special API that enables the gadget to function. The code for these APIs are stored on the server displaying the Google gadget, in this case on Information Console. The gadget developer uses less code because the requested feature is loaded by Information Console. For example, instead of adding JavaScript code to parse data, the parse function can be loaded as a feature.
The Google gadget must contain a <require> element with the feature name, as shown in the following code:
<Require feature="pubsub" />
This code requests the pubsub gadget feature, which enables communication from an Actuate gadget to a Google gadget.
When the feature is available, the gadget loads the API associated with the feature from Information Console. If the requested feature is not available, an error message appears. Externally hosted Google gadgets can require special features not available in Information Console.
If a missing feature uses JavaScript, the feature can be included in a customized Google gadget by a software developer integrating the missing JavaScript code into the gadget code.
The following Google gadget features are supported along with the Google gadget Core JavaScript API:
*Flash
*Minimessage
*Pubsub
*Tabs
For more information about building Google gadgets with these features, see the Google Gadget API reference at the following URL:
http://code.google.com/apis/gadgets/docs/reference/
Using the Flash feature
Gadget developers embed Flash movies in Google gadgets using the Flash feature. The following code shows the Flash feature being used in a Google gadget:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="Flash demo" height="300">
<Require feature="flash" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<div id="flashcontainer"></div>
<script type="text/javascript">
var url = "http://www.mywebsite.com/swfs/main.swf";
gadgets.flash.embedFlash(url, "flashcontainer", {
swf_version: 6,
id: "flashid"
})
</script>
]]>
</Content>
</Module>
Optionally, gadget developers can use the object tag to embed the Adobe Flash content in HTML code. For more information about using Adobe Flash, see Displaying Adobe Flash content.
Using the minimessage feature
Gadget developers can display a temporary message to users using the minimessage feature. Figure 8‑1 shows the minimessage feature in a gadget.
Figure 8‑1 Using the minimessage feature
The following code shows the minimessage feature used in a Google gadget:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="minimessage demo">
<Require feature="minimessage" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<form>
<input type="button" value="Click" onClick="Changer()">
</form>
<script type="text/javascript">
var msg = new gadgets.MiniMessage(__MODULE_ID__);
function Changer(){
msg.createDismissibleMessage("test message");
}
</script>
]]>
</Content>
</Module>
Using the pubsub feature
The pubsub feature of a Google gadget is also called the publish and subscribe gadget framework. This framework enables gadgets to send and receive messages from one Google gadget to another. Gadget designers link Google gadgets to Actuate gadgets using the pubsub feature.
Google gadgets can also use the pubsub feature to communicate with other Google gadgets. For more information about linking gadgets, see Linking Google gadgets later in this section.
Using the tabs feature
Gadget developers can add a tabbed interface to their gadget using the tabs feature. Figure 8‑2 shows the tabs feature in a gadget.
Figure 8‑2 Using the tabs feature
The following code shows the tabs feature being used in a Google gadget:
<?xml version="1.0" encoding="UTF-8" ?>
<Module>
<ModulePrefs title="tabs demo">
<Require feature="tabs" />
</ModulePrefs>
<Content type="html">
<![CDATA[
<script type="text/javascript">
var tabs = new gadgets.TabSet(__MODULE_ID__, "Two");
function init() {
tabs.addTab("One", {
contentContainer: document.getElementById("id_1")});
tabs.addTab("Two", {
contentContainer: document.getElementById("id_2")});
tabs.addTab("Three", {
contentContainer: document.getElementById("id_3")});
}
gadgets.util.registerOnLoadHandler(init);
</script>
<div id="id_1" style="display:none">Content, tab One.</div>
<div id="id_2" style="display:none">Content, tab Two.</div>
<div id="id_3" style="display:none">Content, tab Three.</div>
]]>
</Content>
</Module>