Including the OpenSocial Feature JavaScript Libraries

There is a series of JavaScript-based features available in the gadgets JavaScript specification to help you build out your application. The functionality these features offer ranges from embedding Flash movies to creating simple tabs.

These JavaScript features include those that are built for server communication (e.g., content-rewrite) as well as for client communication (e.g., dynamic-height). This means that your gadget can use these features to communicate directly with the hosting server and to create client-based functionality.

As shown in the following example, you can include a specific feature by adding a Require element in the gadget XML spec file. Once initialized, the feature may be rendered via spec-defined JavaScript initialization calls that you include in a Content section:

<ModulePrefs>
    <Require feature="tabs" />
</ModulePrefs>

A number of JavaScript features are currently available through the gadgets spec; these are listed in Table 4-1.

Table 4-1. JavaScript features

Attribute

Description

dynamic-height

Gives a gadget the ability to resize itself automatically. This is useful if you’re inserting or replacing content via AJAX requests and the height of your gadget changes.

flash

Embeds a .swf Flash movie in your gadget.

minimessage

Displays within your gadget a small message window, which can be dismissed by the user.

setprefs

Allows you to programmatically save key/value pair state information for a user.

settitle

Allows you to set the gadget’s title programmatically. You can use this to personalize the state of the gadget for each user.

tabs

Allows you to create a tabbed interface in your applications.

Let’s explore some of these features in more depth and see how they can help personalize the gadget experience.

Get Programming Social Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.