A UWA widget file uses standard XHTML code, except for the preferences section, which uses a specific set of elements. Apart from preferences, the XHTML code is entirely based on Web-standards: XHTML/XML, JavaScript/Ajax, CSS.
html element, this way: xmlns:widget=“http://www.netvibes.com/ns/”.script and style tags. The only allowed external files are the emulation ones.
Apart from the Netvibes widget namespace, the header features the usual code from any well-formed XHTML 1.0 Strict files.
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:widget="http://www.netvibes.com/ns/" >
<head>
<title>Title of the widget</title>
title tag is used to set the actual title of the widget. Its content should therefore be meaningful.
UWA defines a set of new meta labels, used to either describe the widget or to give indication to the platform. They are mostly optional, but very useful.
They are coded just like regular meta tags:
<meta name="author" content="Jane Doe" />
| Name | Role | Content example |
|---|---|---|
| author | Name of the widget author. Required by iGoogle | Jane Doe |
| E-mail adress of the widget author. Required by iGoogle | jane@example.org | |
| website | URL of the author's site/page | http://example.org |
| description | A description of the widget. Required by iGoogle | Access your account directly from Netvibes |
| version | The widget's version number | 0.1 alpha |
| keywords | Words to categorize the widget | local, food, map |
| screenshot | Full-size screen-capture of your widget in action. Aim for 280px width. Required by iGoogle | http://example.org/widget-full.png |
| thumbnail | Smaller version of the thumbnail, or the service's logo. Aim for 120px with by 60px height | http://example.org/widget-logo.png |
| autoRefresh | Set the time between two refreshing of the widget (in minutes) | 20 |
| Name | Role | Content example |
|---|---|---|
| apiVersion | Version number of the UWA API | 1.2 |
| debugMode | If true (and if the platform supports it), traces log messages in the platform's JavaScript console (i.e. Firebug) | false |
There are already meta labels for screenshot and thumbnail, but these are only part of the equation.
UWA supports favicon, just like any other XHTML file:
<link rel="icon" type="image/x-icon" href="http://example.org/widget/favicon.png" />
This icon serves as a quick differentiator within Netvibes: it is display on the top-left side of the widget, next to its title.
The target file should be a classical favicon file:
Some platforms ask for bigger icons. UWA sets this in the same way as the favicon:
<link rel="rich-icon" type="image/png" href="http://example.org/widget/richicon.png"/>
This icons serves as a quick differentiator within the following platforms: Apple Dashboard, Windows Vista, Yahoo! Widget. Since it is much more noticeable on these platforms, you should make sure to provide one - which can be a screen capture, a logo, anything that helps differentiate your widget.
Moreover, it you don't provide one, the default UWA icon could lose your widget among all the other UWA widgets that don't define one either. See this blog post for an example.
In order to test your UWA locally, you should add these two lines to your HTML header. They will emulate the UWA environment while not in Netvibes - what we call “Standalone mode”.
Once you are done testing, you can leave them in the code: they are ignored by Netvibes or any supported platform.
<link rel="stylesheet" type="text/css" href="http://www.netvibes.com/themes/uwa/style.css" /> <script type="text/javascript" src="http://www.netvibes.com/js/UWA/load.js.php?env=Standalone"></script>
UWA is based on Web-standards, so widgets can make use of any HTML element and attribute (like table or style, as well as CSS.
But for real styling, widget can rely on CSS. CSS rules are to be defined in the widget file's style tag. Here is an example:
<style type="text/css"> .flickr a, .flickr a:link, .flickr a:hover, .flickr a:active, .flickr a:visited { text-decoration: none; border: none; } </style>
style tag.
It is recommended to only target the widget's element, not general page elements:
h2, span, div…body tag, and target that (as shown in the above sample code. You can use the addClassName() method to dynamically add that class: widget.body.addClassName('flickr');
UWA supports scripting using regular JavaScript code. Widget developers can rely on UWA's JavaScript framework for extended functionalities.
Scripts are to be put within a single script tag, inside the file's head section.
script tag.
It is not recommended to use the document and window objects, as well as their methods, properties and events, for portability reasons. Most of these have been duplicated and expanded in the new widget object.
UWA widgets can have user-defined preferences of several types. These preferences are stored on the local platform, and retrieved every time the widget is loaded.
Preferences are based on the UWA-specific widget:preference element, and each preference uses a preferences tag.
There must be only one widget:preferences element per widget in the head portion of the file. There can be as many preference tags as needed, provided they are all within widget:preferences.
<widget:preferences> <preference name="url" type="text" label="URL" defaultValue="http://feeds.feedburner.com/NetvibesDevBlog" /> <preference name="limit" type="range" label="Number of items to display" defaultValue="10" step="1" min="1" max="25" /> <preference name="search" type="hidden" defaultValue="" /> </widget:preferences>
This preferences block gives the following Edit form:
preference tags can use the following types (to be set in the “type” attribute of each tag):
| Type | Description | Default value |
|---|---|---|
| text | Renders an HTML input field. This is the default type | undefined |
| boolean | Renders an HTML checkbox (true for checked, false for unchecked) | false |
| hidden | Renders nothing, used to initalize a value | (empty) |
| range | Generates a list of integers inside an HTML listbox (select/option). Inspired by HTML5's range list | (empty range) |
| list | Renders an HTML listbox (select/option) | (empty list) |
| password | An HTML password field. The password is then saved on our servers, and never sent back to the client | undefined |
list preference type doesn't display properly in standalone mode - you need to test the widget in Netvibes in order to see it properly displayed.
hidden preference is a handy way to locally store data without letting the user modify it.
preference tags may contain these attributes:
| Attribute | Description |
|---|---|
| label | Indicates the HTML label describing the preference. Since it is displayed to the user, the value should be short and descriptive |
| defaultValue | Lets the user set a default value for the preference |
| min | Defines the minimal integer possible (range type only) |
| max | Defines the maximal integer possible (range type only) |
| step | Defines the incremental step between two values (range type only) |
Using a preference of type list requires more than three specific attributes, as it does for the range type. The list type requires options, which are to be set like common select/option tags in HTML:
<widget:preferences> <preference name="category" type="list" label="Category" defaultValue="1st" onchange="refresh"> <option value="all" label="all" /> <option value="1st" label="First category" /> <option value="2nd" label="Second category" /> <option value="3rd" label="Third category" /> </preference> </widget:preferences>
Preferences can be retrieved using JavaScript. The UWA JavaScript framework provides a handful of methods for that:
widget.getValue(name), widget.getInt(name), widget.getBool(name) ;widget.setValue(name, value) (doesn't work with the range and list types).In order to work properly in iGoogle:
´, etc) in a preference label: since the file is UTF-8 encoded, you can directly use any special character you need.&, <, >, ' and ” should be respectively rewritten as &, <, >, ", '. This is specially true for preference values that features a URL with a & followed by parameters: use & instead. If the URL already features a &, then encode it to &amp;.
There is no best way to handle the body section of the XHTML file: developers are free to have their widget start with an empty body, or a fully created one.
Most of the time, developers can rely on this kind of body content:
(...) </head> <body> <p>Loading...</p> </body> </html>
…and update the whole XHTML content using JavaScript and DOM methods from the UWA framework, such as widget.addBody() or widget.body.setHTML.
But another way could be to build a static XHTML skeleton in the body section, and fill the content in using JS/DOM methods.
(...) </head> <body> <h3>Title goes here</h3> <p>The content goes here</p> </body> </html>
In either case, it is recommended to update the content using JS/DOM methods rather than server-side scripting, for portability reasons.