|
|
Sign Up!
Mashup Showcase Mash Maker
Widget API
Examples
Mash Maker Blog Mash Maker Mailing List |
Patterns Library
The patterns library contains functions that make it easy to create a number of common widget types. If one's widget follows one of the patterns that the patterns library is designed for then using the patterns library is likely to make widget development much easier, since it avoids the need to write boilerplate code that would otherwise be common to many widgets. See the Simple Image example to see the patterns library in action. If you are interested in understanding how the patterns library is implemented in terms of the Widget API then you can have a look at the source for the patterns library: http://mashmaker.intel.com/v13/mashmaker_patterns.js.
To use the patterns library, make sure you include the following in the head section of your web page:
<script type="text/javascript" src="http://mashmaker.intel.com/v13/mashmaker_api.js"></script> <script type="text/javascript" src="http://mashmaker.intel.com/v13/mashmaker_settings.js"></script> <script type="text/javascript" src="http://mashmaker.intel.com/v13/mashmaker_patterns.js"></script> <link rel="stylesheet" href="http://mashmaker.intel.com/style/settingstyle.css"/>
A widget follows the itemsByProp pattern if it wants to be given a set of items with a particular set of properties. For example, all items with images, all items with phone numbers, or all items with addresses. The Simple Image widget is an instance of this pattern. The patterns library deals with providing the following functionality:
itemsByProp.settings(id,opts)Creates a settings panel automatically, given a description of the properties that we want. id is the id of a table that should have rows added to it for settings.
opts has the following fields:
A slot is something that the widget wants to know about an item. For example image, address, phone. The settings panel allows the user to match slots to actual properties of elements. E.g. should address be work address or home address. It is these concrete properties that will be passed to the main widget frame. See Simple Image for an example of this function in use. This function simplifies the implementaton of a widget that follows the itemsByProp pattern.
opts has the following fields:
If the widget does not yet have any settings (it was added to the page as-is, rather than as part of a mashup) then this function will try to guess the initial settings based on the data on the page.
This function is provided by the widget and is called whenever items matching the widget's criteria are added to or removed from the page.
The arguments are as follows:
Each item in the additems array contains an id filed that identifies it. This is the same id used for this item in the Widget Data Format for the data on the page. Each item also contains an associative array called slots. This matches each of the slot names passed to itemsByProp.widget to an array of text values that have been assigned to that slot for that item. In many cases there will be only one element in this array (e.g. in item usually has only one address). See Simple Image for an example of this function in use.
|